Rename slf4j ref impl, add constants
[logging-analytics.git] / reference / logging-slf4j / src / test / java / org / onap / logging / ref / slf4j / ONAPLogConstantsTest.java
@@ -19,7 +19,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.logging.ref.slf4j.common;
+package org.onap.logging.ref.slf4j;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -37,14 +37,11 @@ import static org.hamcrest.core.IsInstanceOf.instanceOf;
 public class ONAPLogConstantsTest {
 
     @Test
-    public void testConstructor() throws Exception {
-        try {
-            ONAPLogConstants.class.getDeclaredConstructors()[0].newInstance();
-            Assert.fail("Should fail for hidden constructor.");
-        }
-        catch (final IllegalAccessException e) {
-
-        }
+    public void testConstructors() throws Exception {
+        assertInaccessibleConstructor(ONAPLogConstants.class);
+        assertInaccessibleConstructor(ONAPLogConstants.MDCs.class);
+        assertInaccessibleConstructor(ONAPLogConstants.Markers.class);
+        assertInaccessibleConstructor(ONAPLogConstants.Headers.class);
     }
 
     @Test
@@ -62,9 +59,9 @@ public class ONAPLogConstantsTest {
 
     @Test
     public void testHeaders() {
-        assertThat(ONAPLogConstants.Headers.REQUEST_ID.toString(), is("X-ONAP-RequestID"));
-        assertThat(ONAPLogConstants.Headers.INVOCATION_ID.toString(), is("X-ONAP-InvocationID"));
-        assertThat(ONAPLogConstants.Headers.PARTNER_NAME.toString(), is("X-ONAP-PartnerName"));
+        assertThat(ONAPLogConstants.Headers.REQUEST_ID, is("X-ONAP-RequestID"));
+        assertThat(ONAPLogConstants.Headers.INVOCATION_ID, is("X-ONAP-InvocationID"));
+        assertThat(ONAPLogConstants.Headers.PARTNER_NAME, is("X-ONAP-PartnerName"));
     }
 
     @Test
@@ -83,4 +80,54 @@ public class ONAPLogConstantsTest {
         assertThat(ONAPLogConstants.InvocationMode.ASYNCHRONOUS.getMarker(),
                 is(ONAPLogConstants.Markers.INVOKE_ASYNCHRONOUS));
     }
+
+    @Test
+    public void testInvocationModeToString() {
+        assertThat(ONAPLogConstants.InvocationMode.SYNCHRONOUS.toString(),
+                is("SYNCHRONOUS"));
+    }
+
+    @Test
+    public void testResponseStatus() {
+        assertThat(ONAPLogConstants.ResponseStatus.COMPLETED.toString(), is("COMPLETED"));
+        assertThat(ONAPLogConstants.ResponseStatus.ERROR.toString(), is("ERROR"));
+    }
+
+    @Test
+    public void testMDCs() {
+
+        assertThat(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS.toString(), is("ClientIPAddress"));
+        assertThat(ONAPLogConstants.MDCs.SERVER_FQDN.toString(), is("ServerFQDN"));
+
+        assertThat(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP.toString(), is("EntryTimestamp"));
+        assertThat(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP.toString(), is("InvokeTimestamp"));
+
+        assertThat(ONAPLogConstants.MDCs.REQUEST_ID.toString(), is("RequestID"));
+        assertThat(ONAPLogConstants.MDCs.INVOCATION_ID.toString(), is("InvocationID"));
+        assertThat(ONAPLogConstants.MDCs.PARTNER_NAME.toString(), is("PartnerName"));
+        assertThat(ONAPLogConstants.MDCs.INSTANCE_UUID.toString(), is("InstanceUUID"));
+        assertThat(ONAPLogConstants.MDCs.SERVICE_NAME.toString(), is("ServiceName"));
+        assertThat(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME.toString(), is("TargetServiceName"));
+
+    }
+
+    static void assertInaccessibleConstructor(final Class<?> c) throws Exception {
+        try {
+            c.getDeclaredConstructors()[0].newInstance();
+            Assert.fail("Should fail for hidden constructor.");
+        }
+        catch (final IllegalAccessException e) {
+
+        }
+
+        try {
+            final Constructor<?> constructor = c.getDeclaredConstructors()[0];
+            constructor.setAccessible(true);
+            constructor.newInstance();
+            Assert.fail("Should fail even when invoked.");
+        }
+        catch (final InvocationTargetException e) {
+            assertThat(e.getCause(), instanceOf(UnsupportedOperationException.class));
+        }
+    }
 }