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 static org.junit.Assert.*;
25 import java.util.concurrent.TimeUnit;
27 import org.junit.After;
28 import org.junit.Test;
31 public class LoggingContextTest {
34 public void cleanup() {
39 public void elapsedTimeTest() {
40 LoggingContext.elapsedTime(300, TimeUnit.MILLISECONDS);
41 assertEquals(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()), "300");
42 LoggingContext.init();
43 assertNull(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()));
47 public void stopWatchTest() {
48 LoggingContext.init();
49 assertFalse(LoggingContext.isStopWatchStarted());
51 LoggingContext.stopWatchStart();
52 assertTrue(LoggingContext.isStopWatchStarted());
54 double elapsedTime = LoggingContext.stopWatchStop();
55 assertFalse(LoggingContext.isStopWatchStarted());
56 assertTrue(elapsedTime > 0);
60 public void putClearTest() {
61 String testServiceName = "TEST-SVC-NAME";
62 LoggingContext.put(LoggingContext.LoggingField.SERVICE_NAME.toString(), testServiceName);
63 assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
65 LoggingContext.clear();
66 assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
71 public void removeTest() {
72 String testServiceName = "TEST-SVC-NAME";
73 LoggingContext.put(LoggingContext.LoggingField.SERVICE_NAME.toString(), testServiceName);
74 assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
76 LoggingContext.remove(LoggingContext.LoggingField.SERVICE_NAME.toString());
77 assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));