diff options
author | 2017-06-09 15:11:06 -0400 | |
---|---|---|
committer | 2017-06-12 16:59:35 -0400 | |
commit | 685ed1545ed28b777a3ba6e7d315b78f355154cb (patch) | |
tree | 1e37d639242c5f1e9cbf5623821f8498542b81dc /LogParser/src/test/java/org/openecomp | |
parent | fc5c07705edc4dcb7083b39116a43844bb6a1490 (diff) |
[Policy-20] getConfig & Policy resolved blockers
Change-Id: If08e4c90d419e8d6e1426d817a12dde5b7cafba3
Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'LogParser/src/test/java/org/openecomp')
-rw-r--r-- | LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java | 233 |
1 files changed, 186 insertions, 47 deletions
diff --git a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java index 621f39742..2bd70f2be 100644 --- a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java +++ b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java @@ -21,6 +21,7 @@ package org.openecomp.xacml.parser; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.BufferedReader; @@ -38,15 +39,19 @@ import org.mockito.Mockito; import org.openecomp.policy.common.im.AdministrativeStateException; import org.openecomp.policy.common.im.IntegrityMonitor; import org.openecomp.policy.common.im.StandbyStatusException; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; public class ParseLogTest { - + + private static Logger logger = FlexLogger.getLogger(ParseLogTest.class); private Properties config = new Properties(); - private String configFile = "test_config.properties"; + private String configFile; + private String testFile1; + private String testFile2; private IntegrityMonitor im; - @Before public void setUp() throws Exception { @@ -59,41 +64,56 @@ public class ParseLogTest { fail(); } Mockito.doNothing().when(im).endTransaction(); - + ClassLoader classLoader = getClass().getClassLoader(); + configFile = classLoader.getResource("test_config.properties").getFile(); + if(configFile.startsWith("/C:/")){ + configFile = configFile.substring(1); + } + testFile1 = classLoader.getResource("LineTest.txt").getFile(); + testFile2 = classLoader.getResource("LineTest2.txt").getFile(); + } @After public void tearDown() { + + logger.debug("tearDown: enter"); + File file = new File("nonExistFile.txt"); file.delete(); - } - - //@Test - public void testMain() { - try { - ParseLog.main(null); - } catch (Exception e) { - fail(); - } + logger.debug("tearDown: exit"); } @Test public void testCountLines() throws IOException { - String fileName = "LineTest.txt"; - int returnValue = ParseLog.countLines(fileName); - assertEquals(9, returnValue); + logger.debug("testCountLines: enter"); + + int returnValue = ParseLog.countLines(testFile1); + logger.debug("testCountLines: returnValue: " + returnValue); + assertEquals(12, returnValue); + + logger.debug("testCountLines: exit"); } - + @Test public void testParseRemoteSystem() { + + logger.debug("testParseRemoteSystem: enter"); + String line = "||org.openecomp.policy.pap.xacml.rest.XACMLPapServlet$Heartbeat.run(XACMLPapServlet.java:2801)||Heartbeat 'https://localhost:8081/pdp/' status='UP_TO_DATE'"; String returnValue = ParseLog.parseRemoteSystem(line); + logger.debug("testParseRemoteSystem: returnValue: " + returnValue); assertEquals("localhost:8081", returnValue); + + logger.debug("testParseRemoteSystem: exit"); } @Test public void testGetPropertiesValue() { + + logger.debug("testGetPropertiesValue: enter"); + config = new Properties(); config.put("RESOURCE_NAME", "logparser_pap01"); config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); @@ -108,76 +128,123 @@ public class ParseLogTest { config.put("PARSERLOGPATH", "IntegrityMonitor.log"); Properties returnConfig = ParseLog.getPropertiesValue(configFile); - - + logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig); assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); + + logger.debug("testGetPropertiesValue: exit"); } - + @Test public void testGetPropertiesFail() { - Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); + logger.debug("testGetPropertiesFail: enter"); + + Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); + logger.debug("testGetPropertiesFail: returnValue: " + returnValue); assertEquals(null, returnValue); + + logger.debug("testGetPropertiesFail: exit"); } @Test public void testParseDate(){ + + logger.debug("testParseDate: enter"); + String line = "2016-02-23 08:07:30"; Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", false); + logger.debug("testParseDate: returnValue: " + returnValue); line = returnValue.toString().substring(0, returnValue.toString().lastIndexOf(":30")+3); assertEquals("Tue Feb 23 08:07:30", line); + + logger.debug("testParseDate: exit"); } - + @Test public void testParseDateFail(){ + + logger.debug("testParseDateFail: enter"); + String line = "2016-02-23 08:07:30"; Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", true); - + logger.debug("testParseDateFail: returnValue: " + returnValue); assertEquals(null, returnValue); + + logger.debug("testParseDateFail: exit"); } - + @Test public void testPullLastLineRead(){ - File file = new File("LineTest.txt"); + logger.debug("testPullLastLineRead: enter"); + File file = new File(testFile1); String returnValue = null; try { - returnValue = ParseLog.PullLastLineRead(file).trim(); + returnValue = ParseLog.PullLastLineRead(file, "pap-rest.log"); + logger.debug("testPullLastLineRead: returnValue for pap-rest.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("52", returnValue); + + try { + returnValue = ParseLog.PullLastLineRead(file, "debug.log"); + logger.debug("testPullLastLineRead: returnValue for debug.log: " + returnValue); } catch (IOException e) { fail(); } - assertEquals("12", returnValue); + assertEquals("17", returnValue); + + try { + returnValue = ParseLog.PullLastLineRead(file, "error.log"); + logger.debug("testPullLastLineRead: returnValue for error.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("22", returnValue); + logger.debug("testPullLastLineRead: exit"); } - + @Test public void testPullLastLineReadNoFile(){ + logger.debug("testPullLastLineReadNoFile: enter"); + File file = new File("nonExistFile.txt"); try { - assertEquals(null, ParseLog.PullLastLineRead(file)); + assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); } catch (IOException e) { fail(); } + + logger.debug("testPullLastLineReadNoFile: exit"); } + @Test public void testPullLastLineReadFail(){ - File file = new File("LineTest2.txt"); + logger.debug("testPullLastLineReadFail: enter"); + + File file = new File(testFile2); try { - assertEquals(null, ParseLog.PullLastLineRead(file)); + assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); } catch (IOException e) { fail(); } + + logger.debug("testPullLastLineReadFail: exit"); } @Test public void testPullOutLogValues(){ + + logger.debug("testPullOutLogValues: enter"); //ERROR_VALUE // Open the file FileInputStream fstream; try { - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "ERROR"); @@ -186,15 +253,47 @@ public class ParseLogTest { } catch (IOException e) { fail(); } -// assert(true); + + logger.debug("testPullOutLogValues: exit"); } + + @Test + public void testGetPaths(){ + + logger.debug("testGetPaths: enter"); + + try { + // valid test + String logPaths = "C:\\pap-log\\pap-rest.log;C:\\pap-log\\debug.log;C:\\pap-log\\error.log"; + String [] retrunObject = ParseLog.getPaths(logPaths); + assertEquals(3, retrunObject.length); + + // valid test + logPaths = "C:\\pap-log\\pap-rest.log"; + retrunObject = ParseLog.getPaths(logPaths); + assertEquals(1, retrunObject.length); + + // invalid test + logPaths = ""; + retrunObject = ParseLog.getPaths(logPaths); + assertTrue(retrunObject == null); + + } catch (Exception e) { + fail(); + } + + logger.debug("testGetPaths: exit"); + } + @Test public void testPullOutLogValuesSecond(){ + + logger.debug("testPullOutLogValuesSecond: enter"); //ERROR_VALUE // Open the file FileInputStream fstream; try { - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); strLine = br.readLine(); @@ -204,16 +303,20 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesSecond: exit"); } - + @Test public void testPullOutLogValuesThird(){ + + logger.debug("testPullOutLogValuesThird: enter"); //ERROR_VALUE // Open the file FileInputStream fstream; try { int number = 3; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -225,15 +328,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesThird: exit"); } @Test public void testPullOutLogValuesFourth(){ + + logger.debug("testPullOutLogValuesFourth: enter"); // Open the file FileInputStream fstream; try { int number = 4; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -245,15 +352,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesFourth: exit"); } - + @Test public void testPullOutLogValuesFith(){ + + logger.debug("testPullOutLogValuesFith: enter"); // Open the file FileInputStream fstream; try { int number = 5; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -265,15 +376,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesFith: exit"); } - + @Test public void testPullOutLogValuesSixth(){ + + logger.debug("testPullOutLogValuesSixth: enter"); // Open the file FileInputStream fstream; try { int number = 6; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -285,15 +400,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesSixth: exit"); } @Test public void testPullOutLogValuesSeven(){ + + logger.debug("testPullOutLogValuesSeven: enter"); // Open the file FileInputStream fstream; try { int number = 7; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -305,15 +424,19 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesSeven: exit"); } - + @Test public void testPullOutLogValuesEight(){ + + logger.debug("testPullOutLogValuesEight: enter"); // Open the file FileInputStream fstream; try { int number = 8; - fstream = new FileInputStream("LineTest.txt"); + fstream = new FileInputStream(testFile1); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine = br.readLine(); for (int i =0; i < number; i++){ @@ -325,17 +448,26 @@ public class ParseLogTest { } catch (IOException e) { fail(); } + + logger.debug("testPullOutLogValuesEight: exit"); } - + @Test public void testPullOutLogValuesNull(){ + + logger.debug("testPullOutLogValuesNull: enter"); // Open the file LogEntryObject retrunObject = ParseLog.pullOutLogValues("", "Console"); assertEquals(null, retrunObject); + + logger.debug("testPullOutLogValuesNull: exit"); } - + @Test public void testLogEntryObject(){ + + logger.debug("testLogEntryObject: enter"); + Date date = new Date(); // Open the file @@ -349,10 +481,15 @@ public class ParseLogTest { assertEquals("pap", logObject.getSystemType()); assertEquals(date, logObject.getDate()); assertEquals("remote", logObject.getRemote()); + + logger.debug("testLogEntryObject: exit"); } @Test public void testProcess(){ + + logger.debug("testProcess: enter"); + String line = "2015-04-01 09:13:44.947 DEBUG 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved "; im = Mockito.mock(IntegrityMonitor.class); @@ -362,6 +499,8 @@ public class ParseLogTest { fail(); } Mockito.doNothing().when(im).endTransaction(); - ParseLog.process(line, "pap"); + ParseLog.process(line, "pap", LOGTYPE.INFO); + + logger.debug("testProcess: exit"); } }
\ No newline at end of file |