Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / message-lib / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / message / utils / BlueprintMessageUtilsTest.kt
1 /*
2  * Copyright © 2021 Bell Canada.
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.blueprintsprocessor.message.utils
18
19 import io.micrometer.core.instrument.Tag
20 import io.mockk.every
21 import io.mockk.mockkStatic
22 import org.junit.Test
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
27
28 import kotlin.test.assertEquals
29
30 class BlueprintMessageUtilsTest {
31
32     @Test
33     fun testKafkaMetricTag() {
34         val expected = mutableListOf<Tag>(
35             Tag.of(BluePrintConstants.METRIC_TAG_TOPIC, "my-topic")
36         )
37         val tags = BlueprintMessageUtils.kafkaMetricTag("my-topic")
38
39         assertEquals(expected, tags)
40     }
41
42     @Test
43     fun testGetHostnameSuffix() {
44         mockkStatic(System::class)
45         every { System.getenv("HOSTNAME") } returns "qwertyuiop"
46         assertEquals("yuiop", BlueprintMessageUtils.getHostnameSuffix())
47     }
48
49     @Test
50     fun testGetNullHostnameSuffix() {
51         mockkStatic(System::class)
52         every { System.getenv("HOSTNAME") } returns null
53         assertEquals(5, BlueprintMessageUtils.getHostnameSuffix().length)
54     }
55
56     @Test
57     fun testGetMessageLogData() {
58         var header = CommonHeader().apply {
59             requestId = "myrequestid"
60             subRequestId = "mysubrequestid"
61         }
62
63         val input = ExecutionServiceInput().apply {
64             actionIdentifiers = ActionIdentifiers().apply {
65                 blueprintName = "bpInput"
66                 blueprintVersion = "1.0.0-input"
67                 actionName = "bpActionInput"
68             }
69             commonHeader = header
70         }
71         val expectedOnInput = "requestID(myrequestid), subrequestID(mysubrequestid) CBA(bpInput/1.0.0-input/bpActionInput)"
72
73         val output = ExecutionServiceInput().apply {
74             actionIdentifiers = ActionIdentifiers().apply {
75                 blueprintName = "bpOutput"
76                 blueprintVersion = "1.0.0-output"
77                 actionName = "bpActionOutput"
78             }
79             commonHeader = header
80         }
81         val expectedOnOutput = "requestID(myrequestid), subrequestID(mysubrequestid) CBA(bpOutput/1.0.0-output/bpActionOutput)"
82
83         val otherMessage = "some other message"
84         val expectedOnOtherMessage = "message(some other message)"
85
86         assertEquals(expectedOnInput, BlueprintMessageUtils.getMessageLogData(input))
87         assertEquals(expectedOnOutput, BlueprintMessageUtils.getMessageLogData(output))
88         assertEquals(expectedOnOtherMessage, BlueprintMessageUtils.getMessageLogData(otherMessage))
89     }
90 }