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;
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();
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() {
im = Mockito.mock(IntegrityMonitor.class);
try {
Mockito.doNothing().when(im).startTransaction();
- } catch (StandbyStatusException | AdministrativeStateException e) {
+ } catch (IntegrityMonitorException e) {
fail();
}
Mockito.doNothing().when(im).endTransaction();
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