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.mockkObject
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
28 import kotlin.test.assertEquals
30 class BlueprintMessageUtilsTest {
33 fun testKafkaMetricTag() {
34 val expected = mutableListOf<Tag>(
35 Tag.of(BluePrintConstants.METRIC_TAG_TOPIC, "my-topic")
37 val tags = BlueprintMessageUtils.kafkaMetricTag("my-topic")
39 assertEquals(expected, tags)
43 fun testGetHostnameSuffix() {
44 mockkObject(BlueprintMessageUtils)
45 every { BlueprintMessageUtils.getHostname() } returns "qwertyuiop"
46 assertEquals("yuiop", BlueprintMessageUtils.getHostnameSuffix())
50 fun testGetNullHostnameSuffix() {
51 mockkObject(BlueprintMessageUtils)
52 every { BlueprintMessageUtils.getHostname() } returns null
53 assertEquals(5, BlueprintMessageUtils.getHostnameSuffix().length)
57 fun testGetMessageLogData() {
58 var header = CommonHeader().apply {
59 requestId = "myrequestid"
60 subRequestId = "mysubrequestid"
63 val input = ExecutionServiceInput().apply {
64 actionIdentifiers = ActionIdentifiers().apply {
65 blueprintName = "bpInput"
66 blueprintVersion = "1.0.0-input"
67 actionName = "bpActionInput"
71 val expectedOnInput = "requestID(myrequestid), subrequestID(mysubrequestid) CBA(bpInput/1.0.0-input/bpActionInput)"
73 val output = ExecutionServiceInput().apply {
74 actionIdentifiers = ActionIdentifiers().apply {
75 blueprintName = "bpOutput"
76 blueprintVersion = "1.0.0-output"
77 actionName = "bpActionOutput"
81 val expectedOnOutput = "requestID(myrequestid), subrequestID(mysubrequestid) CBA(bpOutput/1.0.0-output/bpActionOutput)"
83 val otherMessage = "some other message"
84 val expectedOnOtherMessage = "message(some other message)"
86 assertEquals(expectedOnInput, BlueprintMessageUtils.getMessageLogData(input))
87 assertEquals(expectedOnOutput, BlueprintMessageUtils.getMessageLogData(output))
88 assertEquals(expectedOnOtherMessage, BlueprintMessageUtils.getMessageLogData(otherMessage))