2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.logging;
23 import org.junit.After;
24 import org.junit.Test;
27 import java.util.concurrent.TimeUnit;
29 import static org.junit.Assert.*;
31 public class LoggingContextTest {
34 public void cleanup(){
38 public void elapsedTimeTest() {
39 LoggingContext.elapsedTime(300, TimeUnit.MILLISECONDS);
40 assertEquals(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()), "300");
41 LoggingContext.init();
42 assertTrue(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()) == null);
45 public void stopWatchTest() {
46 LoggingContext.init();
47 assertFalse(LoggingContext.isStopWatchStarted());
49 LoggingContext.stopWatchStart();
50 assertTrue(LoggingContext.isStopWatchStarted());
52 double elapsedTime = LoggingContext.stopWatchStop();
53 assertFalse(LoggingContext.isStopWatchStarted());
54 assertTrue(elapsedTime > 0);
57 public void putClearTest() {
58 String testServiceName = "TEST-SVC-NAME";
59 LoggingContext.put(LoggingContext.LoggingField.SERVICE_NAME.toString(), testServiceName);
60 assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
62 LoggingContext.clear();
63 assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null);
68 public void removeTest() {
69 String testServiceName = "TEST-SVC-NAME";
70 LoggingContext.put(LoggingContext.LoggingField.SERVICE_NAME.toString(), testServiceName);
71 assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
73 LoggingContext.remove(LoggingContext.LoggingField.SERVICE_NAME.toString());
74 assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null);