SLF4J adapter (in 'common') + call graph demo
[logging-analytics.git] / reference / slf4j-reference / src / test / java / org / onap / logging / ref / slf4j / common / ONAPLogConstantsTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.logging
4  * ================================================================================
5  * Copyright © 2018 Amdocs
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *    http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.logging.ref.slf4j.common;
23
24 import java.lang.reflect.Constructor;
25 import java.lang.reflect.InvocationTargetException;
26
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
29
30 import static org.hamcrest.MatcherAssert.assertThat;
31 import static org.hamcrest.core.Is.is;
32 import static org.hamcrest.core.IsInstanceOf.instanceOf;
33
34 /**
35  * Tests for {@link ONAPLogConstants}.
36  */
37 public class ONAPLogConstantsTest {
38
39     @Test
40     public void testConstructor() throws Exception {
41         try {
42             ONAPLogConstants.class.getDeclaredConstructors()[0].newInstance();
43             Assert.fail("Should fail for hidden constructor.");
44         }
45         catch (final IllegalAccessException e) {
46
47         }
48     }
49
50     @Test
51     public void testConstructorUnsupported() throws Exception {
52         try {
53             Constructor<?> c = ONAPLogConstants.class.getDeclaredConstructors()[0];
54             c.setAccessible(true);
55             c.newInstance();
56             Assert.fail("Should fail for hidden constructor.");
57         }
58         catch (final InvocationTargetException e) {
59             assertThat(e.getCause(), instanceOf(UnsupportedOperationException.class));
60         }
61     }
62
63     @Test
64     public void testHeaders() {
65         assertThat(ONAPLogConstants.Headers.REQUEST_ID.toString(), is("X-ONAP-RequestID"));
66         assertThat(ONAPLogConstants.Headers.INVOCATION_ID.toString(), is("X-ONAP-InvocationID"));
67         assertThat(ONAPLogConstants.Headers.PARTNER_NAME.toString(), is("X-ONAP-PartnerName"));
68     }
69
70     @Test
71     public void testMarkers() {
72         assertThat(ONAPLogConstants.Markers.ENTRY.toString(), is("ENTRY"));
73         assertThat(ONAPLogConstants.Markers.EXIT.toString(), is("EXIT"));
74         assertThat(ONAPLogConstants.Markers.INVOKE.toString(), is("INVOKE"));
75         assertThat(ONAPLogConstants.Markers.INVOKE_ASYNCHRONOUS.toString(), is("INVOKE [ ASYNCHRONOUS ]"));
76         assertThat(ONAPLogConstants.Markers.INVOKE_SYNCHRONOUS.toString(), is("INVOKE [ SYNCHRONOUS ]"));
77     }
78
79     @Test
80     public void testInvocationMode() {
81         assertThat(ONAPLogConstants.InvocationMode.SYNCHRONOUS.getMarker(),
82                 is(ONAPLogConstants.Markers.INVOKE_SYNCHRONOUS));
83         assertThat(ONAPLogConstants.InvocationMode.ASYNCHRONOUS.getMarker(),
84                 is(ONAPLogConstants.Markers.INVOKE_ASYNCHRONOUS));
85     }
86 }