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.slf4j;
19 import org.openecomp.sdc.logging.api.LoggingContext;
21 import org.testng.annotations.Test;
23 import java.util.UUID;
25 import static org.testng.Assert.assertEquals;
26 import static org.testng.Assert.assertNull;
32 public class LoggingContextTest {
35 public void returnMdcWrapperWhenToRunnableCalled() {
36 assertEquals(LoggingContext.copyToRunnable(() -> {}).getClass(), MDCRunnableWrapper.class);
39 @Test(expectedExceptions = NullPointerException.class)
40 public void throwNpeWhenToRunnableWithNull() {
41 LoggingContext.copyToRunnable(null);
45 public void returnMdcWrapperWhenToCallableCalled() {
46 assertEquals(LoggingContext.copyToCallable(() -> "").getClass(), MDCCallableWrapper.class);
49 @Test(expectedExceptions = NullPointerException.class)
50 public void throwNpeWhenToCallableWithNull() {
51 LoggingContext.copyToCallable(null);
55 public void clearContextWhenClearCalled() {
57 String random = UUID.randomUUID().toString();
60 LoggingContext.put(random, random);
61 LoggingContext.clear();
62 assertNull(MDC.get(random));
63 assertNull(LoggingContext.get(random));
70 public void returnContextWhenGetCalled() {
72 String random = UUID.randomUUID().toString();
75 LoggingContext.put(random, random);
76 assertEquals(random, MDC.get(random));
77 assertEquals(random, LoggingContext.get(random));
84 public void removeContextWhenRemoveCalled() {
86 String random = UUID.randomUUID().toString();
89 LoggingContext.put(random, random);
90 LoggingContext.remove(random);
91 assertNull(MDC.get(random));
92 assertNull(LoggingContext.get(random));
98 @Test(expectedExceptions = NullPointerException.class)
99 public void throwNpeWhenPutWithKeyNull() {
100 LoggingContext.put(null, "---");
103 @Test(expectedExceptions = NullPointerException.class)
104 public void throwNpeWhenGetWithKeyNull() {
105 LoggingContext.get(null);
108 @Test(expectedExceptions = NullPointerException.class)
109 public void throwNpeWhenRemoveWithKeyNull() {
110 LoggingContext.remove(null);