Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / test / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / MDCContextTest.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.core
18
19 import kotlinx.coroutines.GlobalScope
20 import kotlinx.coroutines.launch
21 import kotlinx.coroutines.runBlocking
22 import org.junit.After
23 import org.junit.Before
24 import org.slf4j.MDC
25 import kotlin.test.Test
26 import kotlin.test.assertEquals
27
28 class MDCContextTest {
29
30     val log = logger(MDCContextTest::class)
31
32     @Before
33     fun setup() {
34         MDC.clear()
35     }
36
37     @After
38     fun tearDow() {
39         MDC.clear()
40     }
41
42     @Test
43     fun testContextCanBePassedBetweenCoroutines() {
44         MDC.put(BluePrintConstants.ONAP_REQUEST_ID, "12345")
45         runBlocking {
46             GlobalScope.launch {
47                 assertEquals(null, MDC.get(BluePrintConstants.ONAP_REQUEST_ID))
48             }
49             launch(MDCContext()) {
50                 assertEquals(
51                     "12345", MDC.get(BluePrintConstants.ONAP_REQUEST_ID),
52                     "couldn't get request id"
53                 )
54
55                 MDC.put("client_id", "client-1")
56                 assertEquals("client-1", MDC.get("client_id"), "couldn't get client id")
57             }
58         }
59     }
60 }