summaryrefslogtreecommitdiffstats
path: root/reference/logging-slf4j/src/test
diff options
context:
space:
mode:
authorAvdhut Kholkar <avdhut.kholkar@amdocs.com>2018-07-12 05:34:37 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-12 05:34:37 +0000
commitaf1410de64d463905dd6deee62efdd88ff616ce8 (patch)
tree01b7286bfd927f34481bab8a4b4920a6a0407e48 /reference/logging-slf4j/src/test
parent1ec5963cd18cd70b6aabe5fe70ab3734dd9f3307 (diff)
parent9eee6ac9daa5b82946b4f7c7eaa817ae3e1f4cab (diff)
Merge "logging library use and k8s"
Diffstat (limited to 'reference/logging-slf4j/src/test')
-rw-r--r--reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java b/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java
index b14df9f..1d11bd3 100644
--- a/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java
+++ b/reference/logging-slf4j/src/test/java/org/onap/logging/ref/slf4j/ONAPLogAdapterTest.java
@@ -166,6 +166,47 @@ public class ONAPLogAdapterTest {
MDC.clear();
}
}
+
+ /**
+ * Test ENTERING with an EMPTY_STRING serviceName.
+ */
+ @Test
+ public void testEnteringWithEMPTY_STRING_serviceName() {
+
+ final Logger logger = LoggerFactory.getLogger(this.getClass());
+ final ONAPLogAdapter adapter = new ONAPLogAdapter(logger);
+ final MockHttpServletRequest http = new MockHttpServletRequest();
+ http.setRequestURI("uri123");
+ http.setServerName("local123");
+ http.setRemoteAddr("remote123");
+ http.addHeader("X-ONAP-RequestID", "request123");
+ http.addHeader("X-ONAP-InvocationID", "invocation123");
+ http.addHeader("X-ONAP-PartnerName", "partner123");
+
+ try {
+ // an empty string should kick in setting the actual service name (treated same as null)
+ adapter.getServiceDescriptor().setServiceName("");
+ adapter.entering(http);
+ final Map<String, String> mdcs = MDC.getCopyOfContextMap();
+ assertThat(mdcs.get("RequestID"), is("request123"));
+ assertThat(mdcs.get("InvocationID"), is("invocation123"));
+ assertThat(mdcs.get("PartnerName"), is("partner123"));
+ assertThat(mdcs.get("ServiceName"), is("uri123"));
+ assertThat(mdcs.get("ServerFQDN"), is("local123"));
+ assertThat(mdcs.get("ClientIPAddress"), is("remote123"));
+
+ // Timestamp format and value:
+
+ final String invokeTimestampString = mdcs.get("InvokeTimestamp");
+ assertThat(invokeTimestampString, notNullValue());
+ assertThat(invokeTimestampString, endsWith("Z"));
+ final long invokeTimestamp = DatatypeConverter.parseDateTime(invokeTimestampString).getTimeInMillis();
+ assertThat(Math.abs(System.currentTimeMillis() - invokeTimestamp), lessThan(5000L));
+ }
+ finally {
+ MDC.clear();
+ }
+ }
@Test
public void testSetServiceDescriptor() {