1 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils
3 import io.micrometer.core.instrument.Tag
4 import org.junit.Assert.assertEquals
6 import org.junit.runner.RunWith
7 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
8 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
9 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
10 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status
11 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.SelfServiceMetricConstants
12 import org.springframework.http.HttpStatus
13 import org.springframework.test.context.junit4.SpringRunner
15 @RunWith(SpringRunner::class)
19 fun `valid Http status codes should be produced for valid parameters`() {
20 val httpStatusCode200 = determineHttpStatusCode(200)
21 assertEquals(HttpStatus.OK, httpStatusCode200)
23 val httpStatusCode500 = determineHttpStatusCode(500)
24 assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpStatusCode500)
28 fun `Http status code 500 should be produced for any invalid parameter`() {
29 val nonExistentHttpStatusCode = determineHttpStatusCode(999999)
30 assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, nonExistentHttpStatusCode)
34 fun testCbaMetricExecutionInputTags() {
35 val executionServiceInput = ExecutionServiceInput().apply {
36 actionIdentifiers = ActionIdentifiers().apply {
37 blueprintName = "bpName"
38 blueprintVersion = "1.0.0"
39 actionName = "bpAction"
43 val expectedTags = mutableListOf(
44 Tag.of(SelfServiceMetricConstants.TAG_BP_NAME, executionServiceInput.actionIdentifiers.blueprintName),
45 Tag.of(SelfServiceMetricConstants.TAG_BP_VERSION, executionServiceInput.actionIdentifiers.blueprintVersion),
46 Tag.of(SelfServiceMetricConstants.TAG_BP_ACTION, executionServiceInput.actionIdentifiers.actionName)
49 val metricTag = cbaMetricTags(executionServiceInput)
51 assertEquals(expectedTags, metricTag)
55 fun testCbaMetricExecutionOutputTags() {
56 val executionServiceOutput = ExecutionServiceOutput().apply {
57 actionIdentifiers = ActionIdentifiers().apply {
58 blueprintName = "bpName"
59 blueprintVersion = "1.0.0"
60 actionName = "bpAction"
62 status = Status().apply {
68 val expectedTags = mutableListOf(
69 Tag.of(SelfServiceMetricConstants.TAG_BP_NAME, executionServiceOutput.actionIdentifiers.blueprintName),
70 Tag.of(SelfServiceMetricConstants.TAG_BP_VERSION, executionServiceOutput.actionIdentifiers.blueprintVersion),
71 Tag.of(SelfServiceMetricConstants.TAG_BP_ACTION, executionServiceOutput.actionIdentifiers.actionName),
72 Tag.of(SelfServiceMetricConstants.TAG_BP_STATUS, executionServiceOutput.status.code.toString()),
73 Tag.of(SelfServiceMetricConstants.TAG_BP_OUTCOME, executionServiceOutput.status.message)
76 val metricTag = cbaMetricTags(executionServiceOutput)
78 assertEquals(expectedTags, metricTag)