2 * Copyright © 2021 Bell Canada.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.message.utils
19 import io.micrometer.core.instrument.Tag
21 import io.mockk.mockkStatic
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
27 import kotlin.test.assertEquals
29 class BlueprintMessageUtilsTest {
32 fun testKafkaMetricTag() {
33 val expected = mutableListOf<Tag>(
34 Tag.of(BlueprintConstants.METRIC_TAG_TOPIC, "my-topic")
36 val tags = BlueprintMessageUtils.kafkaMetricTag("my-topic")
38 assertEquals(expected, tags)
42 fun testGetHostnameSuffix() {
43 mockkStatic(System::class)
44 every { System.getenv("HOSTNAME") } returns "qwertyuiop"
45 assertEquals("yuiop", BlueprintMessageUtils.getHostnameSuffix())
49 fun testGetNullHostnameSuffix() {
50 mockkStatic(System::class)
51 every { System.getenv("HOSTNAME") } returns null
52 assertEquals(5, BlueprintMessageUtils.getHostnameSuffix().length)
56 fun testGetMessageLogData() {
57 val input = ExecutionServiceInput().apply {
58 actionIdentifiers = ActionIdentifiers().apply {
59 blueprintName = "bpInput"
60 blueprintVersion = "1.0.0-input"
61 actionName = "bpActionInput"
64 val expectedOnInput = "CBA(bpInput/1.0.0-input/bpActionInput)"
66 val output = ExecutionServiceInput().apply {
67 actionIdentifiers = ActionIdentifiers().apply {
68 blueprintName = "bpOutput"
69 blueprintVersion = "1.0.0-output"
70 actionName = "bpActionOutput"
73 val expectedOnOutput = "CBA(bpOutput/1.0.0-output/bpActionOutput)"
75 val otherMessage = "some other message"
76 val expectedOnOtherMessage = "message(some other message)"
78 assertEquals(expectedOnInput, BlueprintMessageUtils.getMessageLogData(input))
79 assertEquals(expectedOnOutput, BlueprintMessageUtils.getMessageLogData(output))
80 assertEquals(expectedOnOtherMessage, BlueprintMessageUtils.getMessageLogData(otherMessage))