de9ca2c44d764d7b38d092a03fba1279e712b8a3
[ccsdk/cds.git] /
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.ExecutionServiceInput
25 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
26
27 import kotlin.test.assertEquals
28
29 class BlueprintMessageUtilsTest {
30
31     @Test
32     fun testKafkaMetricTag() {
33         val expected = mutableListOf<Tag>(
34             Tag.of(BlueprintConstants.METRIC_TAG_TOPIC, "my-topic")
35         )
36         val tags = BlueprintMessageUtils.kafkaMetricTag("my-topic")
37
38         assertEquals(expected, tags)
39     }
40
41     @Test
42     fun testGetHostnameSuffix() {
43         mockkStatic(System::class)
44         every { System.getenv("HOSTNAME") } returns "qwertyuiop"
45         assertEquals("yuiop", BlueprintMessageUtils.getHostnameSuffix())
46     }
47
48     @Test
49     fun testGetNullHostnameSuffix() {
50         mockkStatic(System::class)
51         every { System.getenv("HOSTNAME") } returns null
52         assertEquals(5, BlueprintMessageUtils.getHostnameSuffix().length)
53     }
54
55     @Test
56     fun testGetMessageLogData() {
57         val input = ExecutionServiceInput().apply {
58             actionIdentifiers = ActionIdentifiers().apply {
59                 blueprintName = "bpInput"
60                 blueprintVersion = "1.0.0-input"
61                 actionName = "bpActionInput"
62             }
63         }
64         val expectedOnInput = "CBA(bpInput/1.0.0-input/bpActionInput)"
65
66         val output = ExecutionServiceInput().apply {
67             actionIdentifiers = ActionIdentifiers().apply {
68                 blueprintName = "bpOutput"
69                 blueprintVersion = "1.0.0-output"
70                 actionName = "bpActionOutput"
71             }
72         }
73         val expectedOnOutput = "CBA(bpOutput/1.0.0-output/bpActionOutput)"
74
75         val otherMessage = "some other message"
76         val expectedOnOtherMessage = "message(some other message)"
77
78         assertEquals(expectedOnInput, BlueprintMessageUtils.getMessageLogData(input))
79         assertEquals(expectedOnOutput, BlueprintMessageUtils.getMessageLogData(output))
80         assertEquals(expectedOnOtherMessage, BlueprintMessageUtils.getMessageLogData(otherMessage))
81     }
82 }