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;
20 import org.openecomp.sdc.logging.spi.LoggingContextService;
21 import org.testng.annotations.DataProvider;
23 import java.util.concurrent.Callable;
29 public abstract class BaseContextPropagationTest {
31 // Disable if an old version of ctx implementation is being used.
32 // ctxPropagationFactory should be used when ctx is not propagated to child threads.
33 // See https://jira.qos.ch/browse/LOGBACK-422 and https://jira.qos.ch/browse/LOGBACK-624
34 static final boolean ENABLED = false;
36 static final String PROVIDER = "context";
37 static final String KEY = "test-data";
39 static final String EXPECT_PROPAGATED_TO_CHILD = "Expected the data to be propagated to the child thread's context";
40 static final String EXPECT_RETAINED_IN_CURRENT = "Expected the data to be retained in this thread";
41 static final String EXPECT_REPLACED_WITH_STORED = "Expected context data to be replaced with stored data";
42 static final String EXPECT_INNER_RUN = "Expected the inner thread to run";
43 static final String EXPECT_OUTER_RUN = "Expected the outer thread to run";
44 static final String EXPECT_NOT_COPIED = "Expected context data not to be copied to this thread";
45 static final String EXPECT_RETAINED_IN_PARENT = "Expected context data to be retained in parent thread";
46 static final String EXPECT_POPULATED = "Expected context data to be populated in this thread";
47 static final String EXPECT_EMPTY = "Expected context data to be empty";
48 static final String EXPECT_REMAIN_EMPTY = "Expected context data to remain empty in this thread";
49 static final String EXPECT_REVERTED_ON_EXCEPTION = "Expected context data to be reverted even in case of exception";
50 static final String EXPECT_EXCEPTION_FROM_INNER = "Expected the inner class to throw exception";
52 @DataProvider(name = PROVIDER)
53 public static Object[][] contextServices() {
54 // try both directly call the implementation and get it via the binding
55 return new Object[][] {
56 { new SLF4JLoggingServiceProvider() },
57 { new LoggingContextAdaptor() }
61 private static class LoggingContextAdaptor implements LoggingContextService {
64 public void put(String key, String value) {
65 LoggingContext.put(key, value);
69 public String get(String key) {
70 return LoggingContext.get(key);
74 public void remove(String key) {
75 LoggingContext.remove(key);
80 LoggingContext.clear();
84 public Runnable copyToRunnable(Runnable runnable) {
85 return LoggingContext.copyToRunnable(runnable);
89 public <V> Callable<V> copyToCallable(Callable<V> callable) {
90 return LoggingContext.copyToCallable(callable);
94 public String toString() {
95 return this.getClass().getName();