2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.logging.api;
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertTrue;
22 import java.lang.reflect.Field;
23 import java.util.concurrent.Callable;
24 import org.testng.annotations.Test;
30 public class LoggingContextTest {
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");
41 @Test(expectedExceptions = NullPointerException.class)
42 public void throwNpeWhenPartnerNameIsNull() {
43 LoggingContext.putPartnerName(null);
46 @Test(expectedExceptions = NullPointerException.class)
47 public void throwNpeWhenServiceNameIsNull() {
48 LoggingContext.putServiceName(null);
51 @Test(expectedExceptions = NullPointerException.class)
52 public void throwNpeWhenRequestIdIsNull() {
53 LoggingContext.putRequestId(null);
57 public void clearDoesNotFail() {
58 LoggingContext.clear();
62 public void toRunnableReturnsSameInstance() {
63 Runnable test = () -> { /* do nothing */ };
64 assertTrue(test == LoggingContext.copyToRunnable(test));
67 @Test(expectedExceptions = NullPointerException.class)
68 public void throwNpeWhenToRunnableWithNull() {
69 LoggingContext.copyToRunnable(null);
73 public void toCallableReturnsSameInstance() {
74 Callable<String> test = () -> "";
75 assertTrue(test == LoggingContext.copyToCallable(test));
78 @Test(expectedExceptions = NullPointerException.class)
79 public void throwNpeWhenToCallableWithNull() {
80 LoggingContext.copyToCallable(null);