X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=LogParser%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fxacml%2Fparser%2FParseLogTest.java;h=91de4644076ead91167a53c08b376e378f8fd4be;hb=f39febaa77ab395b8e755c19ef85cc984b8da072;hp=c12797f281ef9eef549dff7d96f8fb35f7a7e28f;hpb=81d5df62133aa7bdb9c64b3d227a2838a0a2b83c;p=policy%2Fengine.git diff --git a/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java index c12797f28..91de46440 100644 --- a/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java +++ b/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java @@ -37,20 +37,28 @@ import java.util.regex.Pattern; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mockito; import org.onap.policy.common.im.AdministrativeStateException; import org.onap.policy.common.im.IntegrityMonitor; +import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.im.StandbyStatusException; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.xacml.parser.LogEntryObject.LOGTYPE; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; - +@PrepareForTest({ParseLogTest.class, IntegrityMonitor.class}) +@RunWith(PowerMockRunner.class) public class ParseLogTest { private static Logger logger = FlexLogger.getLogger(ParseLogTest.class); private Properties config = new Properties(); private String configFile; + private String configFileDebug; + private String configFileError; private String testFile1; private String testFile2; private IntegrityMonitor im; @@ -69,12 +77,22 @@ public class ParseLogTest { Mockito.doNothing().when(im).endTransaction(); ClassLoader classLoader = getClass().getClassLoader(); configFile = classLoader.getResource("test_config.properties").getFile(); + configFileDebug = classLoader.getResource("test_config_debug.properties").getFile(); + configFileError = classLoader.getResource("test_config_error.properties").getFile(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(configFile); + Matcher matcherDebug = pattern.matcher(configFileDebug); + Matcher matcherError = pattern.matcher(configFileError); if (matcher.find()) { configFile = configFile.substring(1); } + if (matcherDebug.find()) { + configFileDebug = configFileDebug.substring(1); + } + if (matcherError.find()) { + configFileError = configFileError.substring(1); + } testFile1 = classLoader.getResource("LineTest.txt").getFile(); testFile2 = classLoader.getResource("LineTest2.txt").getFile(); @@ -122,8 +140,8 @@ public class ParseLogTest { config = new Properties(); config.put("RESOURCE_NAME", "logparser_pap01"); - config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); - config.put("JDBC_URL", "jdbc:mysql://localhost:3306/"); + config.put("JDBC_DRIVER" ,"org.mariadb.jdbc.Driver"); + config.put("JDBC_URL", "jdbc:mariadb://localhost:3306/"); config.put("JDBC_USER", "root"); config.put("JDBC_PASSWORD", "password"); config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); @@ -140,6 +158,56 @@ public class ParseLogTest { logger.debug("testGetPropertiesValue: exit"); } + @Test + public void testGetPropertiesValue_1() { + + logger.debug("testGetPropertiesValue: enter"); + + config = new Properties(); + config.put("RESOURCE_NAME", "logparser_pap01"); + config.put("JDBC_DRIVER", "org.mariadb.jdbc.Driver"); + config.put("JDBC_URL", "jdbc:mariadb://localhost:3306/"); + config.put("JDBC_USER", "root"); + config.put("JDBC_PASSWORD", "password"); + config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); + config.put("SERVER", "password"); + config.put("JDBC_PASSWORD", "https://localhost:9091/pap/"); + config.put("LOGTYPE", "PAP"); + config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\debug\\pap-rest.log"); + config.put("PARSERLOGPATH", "IntegrityMonitor.log"); + + final Properties returnConfig = ParseLog.getPropertiesValue(configFileDebug); + logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig); + assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); + + logger.debug("testGetPropertiesValue_1: exit"); + } + + @Test + public void testGetPropertiesValue_2() { + + logger.debug("testGetPropertiesValue: enter"); + + config = new Properties(); + config.put("RESOURCE_NAME", "logparser_pap01"); + config.put("JDBC_DRIVER", "org.mariadb.jdbc.Driver"); + config.put("JDBC_URL", "jdbc:mariadb://localhost:3306/"); + config.put("JDBC_USER", "root"); + config.put("JDBC_PASSWORD", "password"); + config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); + config.put("SERVER", "password"); + config.put("JDBC_PASSWORD", "https://localhost:9091/pap/"); + config.put("LOGTYPE", "PAP"); + config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\error\\pap-rest.log"); + config.put("PARSERLOGPATH", "IntegrityMonitor.log"); + + final Properties returnConfig = ParseLog.getPropertiesValue(configFileError); + logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig); + assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); + + logger.debug("testGetPropertiesValue_2: exit"); + } + @Test public void testGetPropertiesFail() { @@ -488,7 +556,7 @@ public class ParseLogTest { im = Mockito.mock(IntegrityMonitor.class); try { Mockito.doNothing().when(im).startTransaction(); - } catch (StandbyStatusException | AdministrativeStateException e) { + } catch (IntegrityMonitorException e) { fail(); } Mockito.doNothing().when(im).endTransaction(); @@ -496,4 +564,39 @@ public class ParseLogTest { logger.debug("testProcess: exit"); } + + @Test + public void testMain() { + try { + ParseLog.main(new String[] {}); + } catch (final Exception e) { + logger.debug("exception occured while executing the test: exit"); + } + } + + @Test + public void testMainDebug() { + try { + final Properties returnConfig = ParseLog.getPropertiesValue(configFileDebug); + PowerMockito.mockStatic(IntegrityMonitor.class); + Mockito.when(IntegrityMonitor.getInstance("test", returnConfig)).thenReturn(im); + ParseLog.main(new String[] {}); + Thread.sleep(30000); + } catch (final Exception e) { + logger.debug("exception occured while executing the test: exit"); + } + } + + @Test + public void testMainError() { + try { + final Properties returnConfig = ParseLog.getPropertiesValue(configFileError); + PowerMockito.mockStatic(IntegrityMonitor.class); + Mockito.when(IntegrityMonitor.getInstance("test", returnConfig)).thenReturn(im); + ParseLog.main(new String[] {}); + Thread.sleep(30000); + } catch (final Exception e) { + logger.debug("exception occured while executing the test: exit"); + } + } } \ No newline at end of file