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.selfservice.api.utils
19 import io.micrometer.core.instrument.Tag
20 import org.junit.Assert.assertEquals
22 import org.junit.runner.RunWith
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.blueprintsprocessor.core.api.data.ExecutionServiceOutput
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status
27 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
28 import org.springframework.http.HttpStatus
29 import org.springframework.test.context.junit4.SpringRunner
31 @RunWith(SpringRunner::class)
32 class BlueprintProcessingUtilsTest {
35 fun `valid Http status codes should be produced for valid parameters`() {
36 val httpStatusCode200 = determineHttpStatusCode(200)
37 assertEquals(HttpStatus.OK, httpStatusCode200)
39 val httpStatusCode500 = determineHttpStatusCode(500)
40 assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpStatusCode500)
44 fun `Http status code 500 should be produced for any invalid parameter`() {
45 val nonExistentHttpStatusCode = determineHttpStatusCode(999999)
46 assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, nonExistentHttpStatusCode)
50 fun testCbaMetricExecutionInputTags() {
51 val executionServiceInput = ExecutionServiceInput().apply {
52 actionIdentifiers = ActionIdentifiers().apply {
53 blueprintName = "bpName"
54 blueprintVersion = "1.0.0"
55 actionName = "bpAction"
59 val expectedTags = mutableListOf(
60 Tag.of(BluePrintConstants.METRIC_TAG_BP_NAME, executionServiceInput.actionIdentifiers.blueprintName),
61 Tag.of(BluePrintConstants.METRIC_TAG_BP_VERSION, executionServiceInput.actionIdentifiers.blueprintVersion),
62 Tag.of(BluePrintConstants.METRIC_TAG_BP_ACTION, executionServiceInput.actionIdentifiers.actionName)
65 val metricTag = cbaMetricTags(executionServiceInput)
67 assertEquals(expectedTags, metricTag)
71 fun testCbaMetricExecutionOutputTags() {
72 val executionServiceOutput = ExecutionServiceOutput().apply {
73 actionIdentifiers = ActionIdentifiers().apply {
74 blueprintName = "bpName"
75 blueprintVersion = "1.0.0"
76 actionName = "bpAction"
78 status = Status().apply {
84 val expectedTags = mutableListOf(
85 Tag.of(BluePrintConstants.METRIC_TAG_BP_NAME, executionServiceOutput.actionIdentifiers.blueprintName),
86 Tag.of(BluePrintConstants.METRIC_TAG_BP_VERSION, executionServiceOutput.actionIdentifiers.blueprintVersion),
87 Tag.of(BluePrintConstants.METRIC_TAG_BP_ACTION, executionServiceOutput.actionIdentifiers.actionName),
88 Tag.of(BluePrintConstants.METRIC_TAG_BP_STATUS, executionServiceOutput.status.code.toString()),
89 Tag.of(BluePrintConstants.METRIC_TAG_BP_OUTCOME, executionServiceOutput.status.message)
92 val metricTag = cbaMetricTags(executionServiceOutput)
94 assertEquals(expectedTags, metricTag)