diff options
author | 2018-03-09 15:02:18 -0500 | |
---|---|---|
committer | 2018-03-09 15:08:14 -0500 | |
commit | 96b5a685d0c3afddb632e4a68ca7483f933b55dc (patch) | |
tree | 246399de05a3d429bf45ef1e5af2b9b0218d99f3 /common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java | |
parent | 4475278c81668109b2b37a1d2720d8f2910641c4 (diff) |
Revert Reduce log noise/warnings
This reverts commit 327b17ab250b4c17cf3f91f5e4cd9bffd89f3d1e.
It is seriously impeding our ability complete the promised merge of AT&T
1802 code.
While I'm all for coding standards, if we are serious about using spaces
instead of tabs, then I think we need to (1) agree with the community when
this will happen, (2) do consistently in all files, and (3) enforce it.
Change-Id: Ib9b996f6b6c7d81ac9ac95d58b0c7d8cc39675ff
Issue-ID: SO-368
Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java')
-rw-r--r-- | common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java | 516 |
1 files changed, 238 insertions, 278 deletions
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java index faef522fbf..473f5320df 100644 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java @@ -40,340 +40,300 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; - /** * This class implements all test methods of the MsoLogger features. + * + * */ public class MsoLoggerTest { - static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); - /** + /** * This method is called before any test occurs. * It creates a fake tree from scratch */ @BeforeClass - public static final void prepare() { + public static final void prepare () { } @Before public final void cleanErrorLogFile() throws FileNotFoundException { - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + - "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; - PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); - asdcConfigFileWriter.print(""); - asdcConfigFileWriter.flush(); - asdcConfigFileWriter.close(); - } - + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; + PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); + asdcConfigFileWriter.print(""); + asdcConfigFileWriter.flush(); + asdcConfigFileWriter.close(); + } + @Before public final void cleanMetricLogFile() throws FileNotFoundException { - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + - "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; - PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); - asdcConfigFileWriter.print(""); - asdcConfigFileWriter.flush(); - asdcConfigFileWriter.close(); - } - + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; + PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); + asdcConfigFileWriter.print(""); + asdcConfigFileWriter.flush(); + asdcConfigFileWriter.close(); + } + @Before public final void cleanAuditLogFile() throws FileNotFoundException { - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/auditjbo ss.server.name_IS_UNDEFINED.log"; - PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); - asdcConfigFileWriter.print(""); - asdcConfigFileWriter.flush(); - asdcConfigFileWriter.close(); - } + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/auditjbo ss.server.name_IS_UNDEFINED.log"; + PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); + asdcConfigFileWriter.print(""); + asdcConfigFileWriter.flush(); + asdcConfigFileWriter.close(); + } + /** * This method implements a test of getSeverifyLevel method. */ - @Test - public final void testGetSeverityLevel() { + @Test + public final void testGetSeverityLevel () { - try { - String levelInfo = (String) invokePriveMethod("getSeverityLevel", "INFO"); - Assert.assertEquals(levelInfo, "0"); + try { + String levelInfo = (String)invokePriveMethod("getSeverityLevel", "INFO"); + Assert.assertEquals (levelInfo, "0"); - String levelWarn = (String) invokePriveMethod("getSeverityLevel", "WARN"); - Assert.assertEquals(levelWarn, "1"); + String levelWarn = (String)invokePriveMethod("getSeverityLevel", "WARN"); + Assert.assertEquals (levelWarn, "1"); - String levelERROR = (String) invokePriveMethod("getSeverityLevel", "ERROR"); - Assert.assertEquals(levelERROR, "2"); + String levelERROR = (String)invokePriveMethod("getSeverityLevel", "ERROR"); + Assert.assertEquals (levelERROR, "2"); - String levelDEBUG = (String) invokePriveMethod("getSeverityLevel", "DEBUG"); - Assert.assertEquals(levelDEBUG, "0"); + String levelDEBUG = (String)invokePriveMethod("getSeverityLevel", "DEBUG"); + Assert.assertEquals (levelDEBUG, "0"); - String levelFATAL = (String) invokePriveMethod("getSeverityLevel", "FATAL"); - Assert.assertEquals(levelFATAL, "3"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + String levelFATAL = (String)invokePriveMethod("getSeverityLevel", "FATAL"); + Assert.assertEquals (levelFATAL, "3"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } /** * This method implements a test of getFinalServiceName method. */ - @Test - public final void testGetFinalServiceName() { - try { - String serviceName1 = (String) invokePriveMethod("getFinalServiceName", - "testServiceName1"); - Assert.assertEquals(serviceName1, "testServiceName1"); - - MsoLogger.setServiceName("testServiceName2"); - String serviceName2 = (String) invokePriveMethod("getFinalServiceName", - "testServiceName1"); - Assert.assertEquals(serviceName2, "testServiceName1"); - - String msgNull = null; - String serviceName3 = (String) invokePriveMethod("getFinalServiceName", msgNull); - Assert.assertEquals(serviceName3, "testServiceName2"); - - MsoLogger.resetServiceName(); - String serviceName4 = (String) invokePriveMethod("getFinalServiceName", msgNull); - Assert.assertEquals(serviceName4, "invoke0"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public final void testGetFinalServiceName () { + try { + String serviceName1 = (String)invokePriveMethod("getFinalServiceName", "testServiceName1"); + Assert.assertEquals(serviceName1, "testServiceName1"); + + MsoLogger.setServiceName("testServiceName2"); + String serviceName2 = (String)invokePriveMethod("getFinalServiceName", "testServiceName1"); + Assert.assertEquals(serviceName2, "testServiceName1"); + + String msgNull = null; + String serviceName3 = (String)invokePriveMethod("getFinalServiceName", msgNull); + Assert.assertEquals(serviceName3, "testServiceName2"); + + MsoLogger.resetServiceName(); + String serviceName4 = (String)invokePriveMethod("getFinalServiceName", msgNull); + Assert.assertEquals(serviceName4, "invoke0"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - @Test - public final void testPrepareMsg() { - try { - String msgNull = null; - MDC.clear(); - invokePrepareMsg("INFO", null, null); - - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("trace-#") && - MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("trace-#") && - MDC.get(MsoLogger.SERVICE_NAME).equals("invoke0") - && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("0")); - - MsoLogger.setLoggerParameters("testRemoteIp", "testUser"); - MsoLogger.setLogContext("testReqId", "testSvcId"); - invokePrepareMsg("ERROR", "testServiceName3", null); - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") && - MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") && - MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName3") - && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("2")); - - MsoLogger.setServiceName("testServiceName2"); - invokePrepareMsg("WARN", msgNull, msgNull); - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") && - MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") && - MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName2") - && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("1")); - - MDC.clear(); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("reqId2"); - msoRequest.setServiceInstanceId("servId2"); - MsoLogger.setLogContext(msoRequest); + @Test + public final void testPrepareMsg () { + try { + String msgNull = null; + MDC.clear(); + invokePrepareMsg("INFO", null, null); + + Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("trace-#") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("trace-#") && MDC.get(MsoLogger.SERVICE_NAME).equals("invoke0") + && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("0")); + + MsoLogger.setLoggerParameters("testRemoteIp", "testUser"); + MsoLogger.setLogContext("testReqId", "testSvcId"); + invokePrepareMsg("ERROR", "testServiceName3", null); + Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName3") + && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("2") ); + + MsoLogger.setServiceName("testServiceName2"); + invokePrepareMsg("WARN", msgNull, msgNull); + Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName2") + && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("1")); + + MDC.clear (); + MsoRequest msoRequest = new MsoRequest (); + msoRequest.setRequestId ("reqId2"); + msoRequest.setServiceInstanceId ("servId2"); + MsoLogger.setLogContext (msoRequest); invokePrepareMsg("FATAL", null, "123"); - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("reqId2") && - MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("servId2") && - MDC.get(MsoLogger.TIMER).equals("123") && MDC.get(MsoLogger.ALERT_SEVERITY).equals("3")); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("reqId2") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("servId2") && MDC.get(MsoLogger.TIMER).equals("123") && MDC.get(MsoLogger.ALERT_SEVERITY).equals("3")); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } /** * This method implements a test of log methods */ - @Test - public final void testLogMethods() { - try { - MDC.clear(); - MsoLogger.setLogContext("reqId2", "servId2"); - MsoLogger.setServiceName("MSO.testServiceName"); - msoLogger.info(MessageEnum.LOGGER_UPDATE_SUC, "testLogger", "INFO", - "DEBUG", "target entity", "target service"); - msoLogger.warn(MessageEnum.GENERAL_WARNING, "warning test", "", - "", MsoLogger.ErrorCode.UnknownError, "warning test"); - msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "target entity", - "target service", MsoLogger.ErrorCode.UnknownError, "error test"); - - //Fetch from the error log - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + - "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; - - Path filePath = new File(logFile).toPath(); - Charset charset = Charset.defaultCharset(); - List<String> stringList = Files.readAllLines(filePath, charset); - String[] stringArray = stringList.toArray(new String[]{}); - int size = stringArray.length; - - Assert.assertTrue(stringArray[size - 3]. - contains("|reqId2|main|MSO.testServiceName||target entity|target service|INFO|null||") && - stringArray[size - 3].contains("||MSO-GENERAL-5408I Successfully update Logger: " + - "testLogger from level INFO to level DEBUG")); - Assert.assertTrue(stringArray[size - 2]. - contains("|reqId2|main|MSO.testServiceName||||WARN|UnknownError|warning test|") && - stringArray[size - 2].contains("|MSO-GENERAL-5401W WARNING: warning test")); - Assert.assertTrue(stringArray[size - 1]. - contains("|reqId2|main|MSO.testServiceName||target entity|target " + - "service|ERROR|UnknownError|error test|") && stringArray[size - 1]. - contains("|MSO-GENERAL-9401E Exception encountered")); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public final void testLogMethods () { + try { + MDC.clear(); + MsoLogger.setLogContext("reqId2", "servId2"); + MsoLogger.setServiceName("MSO.testServiceName"); + msoLogger.info (MessageEnum.LOGGER_UPDATE_SUC, "testLogger", "INFO", "DEBUG", "target entity", "target service"); + msoLogger.warn (MessageEnum.GENERAL_WARNING, "warning test", "", "", MsoLogger.ErrorCode.UnknownError, "warning test"); + msoLogger.error (MessageEnum.GENERAL_EXCEPTION, "target entity", "target service", MsoLogger.ErrorCode.UnknownError, "error test"); + + //Fetch from the error log + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; + + Path filePath = new File(logFile).toPath(); + Charset charset = Charset.defaultCharset(); + List<String> stringList = Files.readAllLines(filePath, charset); + String[] stringArray = stringList.toArray(new String[]{}); + int size = stringArray.length; + + Assert.assertTrue(stringArray[size-3].contains("|reqId2|main|MSO.testServiceName||target entity|target service|INFO|null||") && stringArray[size-3].contains("||MSO-GENERAL-5408I Successfully update Logger: testLogger from level INFO to level DEBUG")); + Assert.assertTrue(stringArray[size-2].contains("|reqId2|main|MSO.testServiceName||||WARN|UnknownError|warning test|") && stringArray[size-2].contains("|MSO-GENERAL-5401W WARNING: warning test")); + Assert.assertTrue(stringArray[size-1].contains("|reqId2|main|MSO.testServiceName||target entity|target service|ERROR|UnknownError|error test|") && stringArray[size-1].contains("|MSO-GENERAL-9401E Exception encountered")); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - /** + /** * This method implements a test of recordMetricEvent method. */ - @Test - public final void testRecordMetricEvent() { - try { - MDC.clear(); - MsoLogger.setLogContext("reqId", "servId"); - msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successful", "VNF", "createVNF", null); - MDC.put(MsoLogger.REMOTE_HOST, "127.0.0.1"); - MDC.put(MsoLogger.PARTNERNAME, "testUser"); - msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.ServiceNotAvailable, "Exception", "SDNC", - "removeSDNC", "testVNF"); - - //Fetch from the metric log - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + - "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; - - Path filePath = new File(logFile).toPath(); - Charset charset = Charset.defaultCharset(); - List<String> stringList = Files.readAllLines(filePath, charset); - String[] stringArray = stringList.toArray(new String[]{}); - msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "", - MsoLogger.ErrorCode.UnknownError, "test error msg"); - - Assert.assertTrue(stringArray[0].contains("|reqId|servId|main||testRecordMetricEvent||" + - "VNF|createVNF|COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|")); - // count the occurance of symbol "|" - Assert.assertTrue((stringArray[0].length() - stringArray[0].replace("|", - "").length()) == 28); - Assert.assertTrue(stringArray[1].contains("|reqId|servId|main||testRecordMetricEvent|" + - "testUser|SDNC|removeSDNC|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") && - stringArray[1].contains("|127.0.0.1||||testVNF|||||")); - Assert.assertTrue((stringArray[1].length() - stringArray[1].replace("|", - "").length()) == 28); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public final void testRecordMetricEvent () { + try { + MDC.clear(); + MsoLogger.setLogContext("reqId", "servId"); + msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful", "VNF" , "createVNF", null); + MDC.put (MsoLogger.REMOTE_HOST, "127.0.0.1"); + MDC.put (MsoLogger.PARTNERNAME, "testUser"); + msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Exception", "SDNC", "removeSDNC", "testVNF"); + + //Fetch from the metric log + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; + + Path filePath = new File(logFile).toPath(); + Charset charset = Charset.defaultCharset(); + List<String> stringList = Files.readAllLines(filePath, charset); + String[] stringArray = stringList.toArray(new String[]{}); + msoLogger.error (MessageEnum.GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.UnknownError, "test error msg"); + + Assert.assertTrue(stringArray[0].contains("|reqId|servId|main||testRecordMetricEvent||VNF|createVNF|COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|")); + // count the occurance of symbol "|" + Assert.assertTrue ((stringArray[0].length() - stringArray[0].replace("|", "").length()) == 28); + Assert.assertTrue(stringArray[1].contains("|reqId|servId|main||testRecordMetricEvent|testUser|SDNC|removeSDNC|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") && stringArray[1].contains("|127.0.0.1||||testVNF|||||")); + Assert.assertTrue ((stringArray[1].length() - stringArray[1].replace("|", "").length()) == 28); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } /** * This method implements a test of testRecordAuditEvent method. */ - @Test - public final void testRecordAuditEvent() { - - try { - - MDC.clear(); - MsoLogger.setLogContext("reqId", "servId"); - msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successful"); - MDC.put(MsoLogger.REMOTE_HOST, "127.0.0.1"); - MDC.put(MsoLogger.PARTNERNAME, "testUser"); - msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.ServiceNotAvailable, "Exception"); - - //Fetch from the metric log - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + - "/MSO/Test/auditjboss.server.name_IS_UNDEFINED.log"; - - Path filePath = new File(logFile).toPath(); - Charset charset = Charset.defaultCharset(); - List<String> stringList = Files.readAllLines(filePath, charset); - String[] stringArray = stringList.toArray(new String[]{}); - msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "", - ErrorCode.UnknownError, "log error"); - - Assert.assertTrue(stringArray[0].contains("|reqId|servId|main||testRecordAuditEvent||" + - "COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|")); - // count the occurance of symbol "|" - Assert.assertTrue((stringArray[0].length() - stringArray[0].replace("|", - "").length()) == 25); - Assert.assertTrue(stringArray[1].contains("|reqId|servId|main||testRecordAuditEvent" + - "|testUser|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") && - stringArray[1].contains("|127.0.0.1||||||||")); - Assert.assertTrue((stringArray[1].length() - stringArray[1].replace("|", - "").length()) == 25); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public final void testRecordAuditEvent () { + + try { + + MDC.clear(); + MsoLogger.setLogContext("reqId", "servId"); + msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful"); + MDC.put (MsoLogger.REMOTE_HOST, "127.0.0.1"); + MDC.put (MsoLogger.PARTNERNAME, "testUser"); + msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Exception"); + + //Fetch from the metric log + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/auditjboss.server.name_IS_UNDEFINED.log"; + + Path filePath = new File(logFile).toPath(); + Charset charset = Charset.defaultCharset(); + List<String> stringList = Files.readAllLines(filePath, charset); + String[] stringArray = stringList.toArray(new String[]{}); + msoLogger.error (MessageEnum.GENERAL_EXCEPTION, "", "", ErrorCode.UnknownError, "log error"); + + Assert.assertTrue (stringArray[0].contains("|reqId|servId|main||testRecordAuditEvent||COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|")); + // count the occurance of symbol "|" + Assert.assertTrue ((stringArray[0].length() - stringArray[0].replace("|", "").length()) == 25); + Assert.assertTrue (stringArray[1].contains("|reqId|servId|main||testRecordAuditEvent|testUser|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") && stringArray[1].contains("|127.0.0.1||||||||")); + Assert.assertTrue ((stringArray[1].length() - stringArray[1].replace("|", "").length()) == 25); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + + // User reflection to invoke to avoid change the publicity of the method - private static String invokePrepareMsg(String arg1, String arg2, String arg3) { - Method method; - try { - method = MsoLogger.class.getDeclaredMethod("prepareMsg", String.class, String.class, String.class); - method.setAccessible(true); - return (String) method.invoke(msoLogger, arg1, arg2, arg3); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; + private static String invokePrepareMsg (String arg1, String arg2, String arg3) { + Method method; + try { + method = MsoLogger.class.getDeclaredMethod("prepareMsg", String.class, String.class, String.class); + method.setAccessible(true); + return (String)method.invoke(msoLogger, arg1, arg2, arg3); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; } // User reflection to invoke to avoid change the publicity of the method - private static Object invokePriveMethod(String methodName, String arg) { - Method method; - try { - method = MsoLogger.class.getDeclaredMethod(methodName, String.class); - method.setAccessible(true); - return method.invoke(msoLogger, arg); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; + private static Object invokePriveMethod (String methodName, String arg) { + Method method; + try { + method = MsoLogger.class.getDeclaredMethod(methodName, String.class); + method.setAccessible(true); + return method.invoke(msoLogger, arg); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; } } |