refactoring tests in Common-App-Api util
[sdc.git] / common-app-api / src / test / java / org / openecomp / sdc / common / util / ThreadLocalsHolderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.common.util;
22
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27
28 public class ThreadLocalsHolderTest {
29
30     @Test
31     public void validateSetAngGetMdcProcessReturnsValidThreadLocalBoolean() {
32         final boolean testBoolean01 = false;
33         final boolean testBoolean02 = true;
34
35         ThreadLocalsHolder.setMdcProcessed(testBoolean01);
36         assertEquals(ThreadLocalsHolder.isMdcProcessed(), testBoolean01);
37         ThreadLocalsHolder.setMdcProcessed(testBoolean02);
38         assertEquals(ThreadLocalsHolder.isMdcProcessed(), testBoolean02);
39     }
40
41     @Test
42     public void validateSetAngGetUUIDReturnsValidThreadLocalString() {
43         final String UUID01 = "testId01";
44         final String UUID02 = "testId02";
45
46         ThreadLocalsHolder.setUuid(UUID01);
47         assertEquals(ThreadLocalsHolder.getUuid(), UUID01);
48         ThreadLocalsHolder.setUuid(UUID02);
49         assertEquals(ThreadLocalsHolder.getUuid(), UUID02);
50     }
51
52     @Test
53     public void validateSetAngGetRequestStartTimeReturnsValidThreadLocalString() {
54         final Long requestStartTime01 = 10L;
55         final Long requestStartTime02 = 50L;
56
57         ThreadLocalsHolder.setRequestStartTime(requestStartTime01);
58         assertEquals(ThreadLocalsHolder.getRequestStartTime(), requestStartTime01);
59         ThreadLocalsHolder.setRequestStartTime(requestStartTime02);
60         assertEquals(ThreadLocalsHolder.getRequestStartTime(), requestStartTime02);
61     }
62
63     @Test
64     public void validateCleanupResetsAllParameters() {
65         final Long requestStartTime = 10L;
66         final String UUID = "testId01";
67         final boolean testBoolean = true;
68
69         ThreadLocalsHolder.setMdcProcessed(testBoolean);
70         ThreadLocalsHolder.setUuid(UUID);
71         ThreadLocalsHolder.setRequestStartTime(requestStartTime);
72
73         ThreadLocalsHolder.cleanup();
74
75         assertNull(ThreadLocalsHolder.getRequestStartTime());
76         assertNull(ThreadLocalsHolder.getUuid());
77         assertEquals(ThreadLocalsHolder.isMdcProcessed(), false);
78     }
79 }