public static boolean isConsoleTextPresent(String text) throws Exception { String currentDate = DateUtil.getCurrentDate("yyyy-MM-dd", LocaleUtil.getDefault()); String fileName = PropsValues.LIFERAY_HOME + "/logs/liferay." + currentDate + ".log"; String content = FileUtil.read(fileName); Pattern pattern = Pattern.compile(text); Matcher matcher = pattern.matcher(content); return matcher.find(); }
public static void assertLiferayErrors() throws Exception { String currentDate = DateUtil.getCurrentDate("yyyy-MM-dd", LocaleUtil.getDefault()); String fileName = PropsValues.LIFERAY_HOME + "/logs/liferay." + currentDate + ".xml"; if (!FileUtil.exists(fileName)) { return; } String content = FileUtil.read(fileName); if (content.equals("")) { return; } content = "<log4j>" + content + "</log4j>"; content = content.replaceAll("log4j:", ""); SAXReader saxReader = new SAXReader(); File file = new File(fileName); Document document = saxReader.read(file); Element rootElement = document.getRootElement(); List<Element> eventElements = rootElement.elements("event"); for (Element eventElement : eventElements) { String level = eventElement.attributeValue("level"); if (level.equals("ERROR")) { String fileContent = FileUtil.read(fileName); fileContent = fileContent.replaceFirst("level=\"ERROR\"", "level=\"ERROR_FOUND\""); FileUtil.write(fileName, fileContent); Element messageElement = eventElement.element("message"); String messageText = messageElement.getText(); if (isIgnorableErrorLine(messageText)) { continue; } Element throwableElement = eventElement.element("throwable"); Exception exception; if (throwableElement != null) { exception = new Exception(messageText + throwableElement.getText()); addToLiferayExceptions(exception); throw exception; } exception = new Exception(messageText); addToLiferayExceptions(exception); throw exception; } } }