Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / selfservice / api / utils / BlueprintProcessingUtilsTest.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.selfservice.api.utils
18
19 import io.micrometer.core.instrument.Tag
20 import org.junit.Assert.assertEquals
21 import org.junit.Test
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
30
31 @RunWith(SpringRunner::class)
32 class BlueprintProcessingUtilsTest {
33
34     @Test
35     fun `valid Http status codes should be produced for valid parameters`() {
36         val httpStatusCode200 = determineHttpStatusCode(200)
37         assertEquals(HttpStatus.OK, httpStatusCode200)
38
39         val httpStatusCode500 = determineHttpStatusCode(500)
40         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpStatusCode500)
41     }
42
43     @Test
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)
47     }
48
49     @Test
50     fun testCbaMetricExecutionInputTags() {
51         val executionServiceInput = ExecutionServiceInput().apply {
52             actionIdentifiers = ActionIdentifiers().apply {
53                 blueprintName = "bpName"
54                 blueprintVersion = "1.0.0"
55                 actionName = "bpAction"
56             }
57         }
58
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)
63         )
64
65         val metricTag = cbaMetricTags(executionServiceInput)
66
67         assertEquals(expectedTags, metricTag)
68     }
69
70     @Test
71     fun testCbaMetricExecutionOutputTags() {
72         val executionServiceOutput = ExecutionServiceOutput().apply {
73             actionIdentifiers = ActionIdentifiers().apply {
74                 blueprintName = "bpName"
75                 blueprintVersion = "1.0.0"
76                 actionName = "bpAction"
77             }
78             status = Status().apply {
79                 code = 200
80                 message = "success"
81             }
82         }
83
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)
90         )
91
92         val metricTag = cbaMetricTags(executionServiceOutput)
93
94         assertEquals(expectedTags, metricTag)
95     }
96 }