X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Flogging%2FTestApplicationLogger.java;h=27193155c1c6f0b8f40e6a881a87b862f69a55cc;hb=5d7c9960d7fd51e79b19adafcc2b2625ea474ed6;hp=ed9dac4ce04e54823846faa87819a7fbcae7195d;hpb=e651abed417b8a173a0745042c7dc5b20c0b7036;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/logging/TestApplicationLogger.java b/src/test/java/org/onap/aai/babel/logging/TestApplicationLogger.java index ed9dac4..2719315 100644 --- a/src/test/java/org/onap/aai/babel/logging/TestApplicationLogger.java +++ b/src/test/java/org/onap/aai/babel/logging/TestApplicationLogger.java @@ -1,5 +1,5 @@ /** - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.logging; import static org.hamcrest.CoreMatchers.containsString; @@ -39,7 +40,7 @@ import org.onap.aai.cl.mdc.MdcOverride; /** * Simple test to log each of the validation messages in turn. - * + * * This version tests only the error logger at INFO level. * */ @@ -53,15 +54,15 @@ public class TestApplicationLogger { /** * Check that each message can be logged and that (by implication of successful logging) there is a corresponding * resource (message format). - * - * @throws IOException + * + * @throws IOException if the log files cannot be read */ @Test public void logAllMessages() throws IOException { Logger logger = LogHelper.INSTANCE; LogReader errorReader = new LogReader(LogHelper.getLogDirectory(), "error"); LogReader debugReader = new LogReader(LogHelper.getLogDirectory(), "debug"); - String[] args = {"1", "2", "3", "4"}; + String[] args = { "1", "2", "3", "4" }; for (ApplicationMsgs msg : Arrays.asList(ApplicationMsgs.values())) { if (msg.name().endsWith("ERROR")) { logger.error(msg, args); @@ -88,26 +89,26 @@ public class TestApplicationLogger { /** * Check that each message can be logged and that (by implication of successful logging) there is a corresponding * resource (message format). - * - * @throws IOException + * + * @throws IOException if the log file cannot be read */ @Test public void logDebugMessages() throws IOException { LogReader reader = new LogReader(LogHelper.getLogDirectory(), "debug"); LogHelper.INSTANCE.debug("a message"); - String s = reader.getNewLines(); - assertThat(s, is(notNullValue())); + String str = reader.getNewLines(); + assertThat(str, is(notNullValue())); } /** - * Check logAudit with HTTP headers - * - * @throws IOException + * Check logAudit with HTTP headers. + * + * @throws IOException if the log file cannot be read */ @Test public void logAuditMessage() throws IOException { - LogHelper logger = LogHelper.INSTANCE; - LogReader reader = new LogReader(LogHelper.getLogDirectory(), "audit"); + final LogHelper logger = LogHelper.INSTANCE; + final LogReader reader = new LogReader(LogHelper.getLogDirectory(), "audit"); HttpHeaders headers = Mockito.mock(HttpHeaders.class); Mockito.when(headers.getHeaderString("X-ECOMP-RequestID")).thenReturn("ecomp-request-id"); @@ -115,26 +116,26 @@ public class TestApplicationLogger { // Call logAudit without first calling startAudit logger.logAuditSuccess("first call: bob"); - String s = reader.getNewLines(); - assertThat(s, is(notNullValue())); - assertThat("audit message log level", s, containsString("INFO")); - assertThat("audit message content", s, containsString("bob")); + String str = reader.getNewLines(); + assertThat(str, is(notNullValue())); + assertThat("audit message log level", str, containsString("INFO")); + assertThat("audit message content", str, containsString("bob")); // This time call the start method logger.startAudit(headers, null); logger.logAuditSuccess("second call: foo"); - s = reader.getNewLines(); - assertThat(s, is(notNullValue())); - assertThat("audit message log level", s, containsString("INFO")); - assertThat("audit message content", s, containsString("foo")); - assertThat("audit message content", s, containsString("ecomp-request-id")); - assertThat("audit message content", s, containsString("app-id")); + str = reader.getNewLines(); + assertThat(str, is(notNullValue())); + assertThat("audit message log level", str, containsString("INFO")); + assertThat("audit message content", str, containsString("foo")); + assertThat("audit message content", str, containsString("ecomp-request-id")); + assertThat("audit message content", str, containsString("app-id")); } /** - * Check logAudit with no HTTP headers - * - * @throws IOException + * Check logAudit with no HTTP headers. + * + * @throws IOException if the log file cannot be read */ @Test public void logAuditMessageWithoutHeaders() throws IOException { @@ -142,26 +143,26 @@ public class TestApplicationLogger { LogReader reader = new LogReader(LogHelper.getLogDirectory(), "audit"); logger.startAudit(null, null); logger.logAuditSuccess("foo"); - String s = reader.getNewLines(); - assertThat(s, is(notNullValue())); - assertThat("audit message log level", s, containsString("INFO")); - assertThat("audit message content", s, containsString("foo")); + String str = reader.getNewLines(); + assertThat(str, is(notNullValue())); + assertThat("audit message log level", str, containsString("INFO")); + assertThat("audit message content", str, containsString("foo")); } /** - * Check logMetrics - * - * @throws IOException + * Check logMetrics. + * + * @throws IOException if the log file cannot be read */ @Test public void logMetricsMessage() throws IOException { LogReader reader = new LogReader(LogHelper.getLogDirectory(), "metrics"); LogHelper logger = LogHelper.INSTANCE; logger.logMetrics("metrics: fred"); - String s = reader.getNewLines(); - assertThat(s, is(notNullValue())); - assertThat("metrics message log level", s, containsString("INFO")); - assertThat("metrics message content", s, containsString("fred")); + String str = reader.getNewLines(); + assertThat(str, is(notNullValue())); + assertThat("metrics message log level", str, containsString("INFO")); + assertThat("metrics message content", str, containsString("fred")); } @Test @@ -204,15 +205,15 @@ public class TestApplicationLogger { } /** - * Call a logger method which is expected to throw an UnsupportedOperationException - * - * @param logMethod - * @param dummyMsg + * Call a logger method which is expected to throw an UnsupportedOperationException. + * + * @param logMethod the logger method to invoke + * @param dummyMsg any Application Message enumeration value */ private void callUnsupportedOperationMethod(TriConsumer, LogFields, String[]> logMethod, ApplicationMsgs dummyMsg) { try { - logMethod.accept(dummyMsg, new LogFields(), new String[] {""}); + logMethod.accept(dummyMsg, new LogFields(), new String[] { "" }); org.junit.Assert.fail("method should have thrown execption"); // NOSONAR as code not reached } catch (UnsupportedOperationException e) { // Expected to reach here @@ -220,16 +221,16 @@ public class TestApplicationLogger { } /** - * Assert that a log message was logged to the expected log file at the expected severity - * - * @param msg - * @param reader - * @param severity - * @throws IOException + * Assert that a log message was logged to the expected log file at the expected severity. + * + * @param msg the Application Message enumeration value + * @param reader the log reader for the message + * @param severity log level + * @throws IOException if the log file cannot be read */ private void validateLoggedMessage(ApplicationMsgs msg, LogReader reader, String severity) throws IOException { - String s = reader.getNewLines(); - assertThat(s, is(notNullValue())); - assertThat(msg.toString() + " log level", s, containsString(severity)); + String str = reader.getNewLines(); + assertThat(str, is(notNullValue())); + assertThat(msg.toString() + " log level", str, containsString(severity)); } }