bfc53a3146dbca8d45ddf828f13c1092981b32a6
[sdc.git] /
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.logging.api;
18
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertTrue;
21
22 import java.lang.reflect.Field;
23 import java.util.concurrent.Callable;
24 import org.testng.annotations.Test;
25
26 /**
27  * @author EVITALIY
28  * @since 08 Jan 18
29  */
30 public class LoggingContextTest {
31
32     @Test
33     public void shouldHoldNoOpWhenNoBinding() throws Exception {
34         Field factory = LoggingContext.class.getDeclaredField("SERVICE");
35         factory.setAccessible(true);
36         Object impl = factory.get(null);
37         assertEquals(impl.getClass().getName(),
38                 "org.openecomp.sdc.logging.api.LoggingContext$NoOpLoggingContextService");
39     }
40
41     @Test(expectedExceptions = NullPointerException.class)
42     public void throwNpeWhenPartnerNameIsNull() {
43         LoggingContext.putPartnerName(null);
44     }
45
46     @Test(expectedExceptions = NullPointerException.class)
47     public void throwNpeWhenServiceNameIsNull() {
48         LoggingContext.putServiceName(null);
49     }
50
51     @Test(expectedExceptions = NullPointerException.class)
52     public void throwNpeWhenRequestIdIsNull() {
53         LoggingContext.putRequestId(null);
54     }
55
56     @Test
57     public void clearDoesNotFail() {
58         LoggingContext.clear();
59     }
60
61     @Test
62     public void toRunnableReturnsSameInstance() {
63         Runnable test = () -> { /* do nothing */ };
64         assertTrue(test == LoggingContext.copyToRunnable(test));
65     }
66
67     @Test(expectedExceptions = NullPointerException.class)
68     public void throwNpeWhenToRunnableWithNull() {
69         LoggingContext.copyToRunnable(null);
70     }
71
72     @Test
73     public void toCallableReturnsSameInstance() {
74         Callable<String> test = () -> "";
75         assertTrue(test == LoggingContext.copyToCallable(test));
76     }
77
78     @Test(expectedExceptions = NullPointerException.class)
79     public void throwNpeWhenToCallableWithNull() {
80         LoggingContext.copyToCallable(null);
81     }
82 }