2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts;
23 import com.fasterxml.jackson.databind.JsonNode
24 import com.fasterxml.jackson.databind.node.ObjectNode
27 import kotlinx.coroutines.runBlocking
29 import org.junit.runner.RunWith
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
31 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
32 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
33 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
34 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
35 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
36 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
37 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
38 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
39 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
40 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
41 import org.springframework.test.context.junit4.SpringRunner
42 import kotlin.test.BeforeTest
43 import kotlin.test.assertEquals
44 import kotlin.test.assertNotNull
47 * Unit test cases for abstract component function.
49 @RunWith(SpringRunner::class)
50 class AbstractComponentFunctionTest {
52 lateinit var blueprintContext: BluePrintContext
56 blueprintContext = mockk<BluePrintContext>()
57 every { blueprintContext.rootPath } returns normalizedPathName("target")
61 * Tests the abstract component functionality.
64 fun testAbstractComponent() {
66 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
67 val samp = SampleComponent()
68 val comp = samp as AbstractComponentFunction
70 comp.bluePrintRuntimeService = bluePrintRuntime
71 comp.stepName = "sample-step"
72 assertNotNull(comp, "failed to get kotlin instance")
74 val input = getMockedInput(bluePrintRuntime)
76 val output = comp.applyNB(input)
78 assertEquals(output.actionIdentifiers.actionName, "activate")
79 assertEquals(output.commonHeader.requestId, "1234")
80 assertEquals(output.stepData!!.name, "activate-restconf")
81 assertEquals(output.status.message, "success")
87 * Mocked input for abstract function test.
89 private fun getMockedInput(bluePrintRuntime: DefaultBluePrintRuntimeService):
90 ExecutionServiceInput {
91 val operationInputs = hashMapOf<String, JsonNode>()
92 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] =
93 "activate-restconf".asJsonPrimitive()
94 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] =
95 "interfaceName".asJsonPrimitive()
96 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] =
97 "operationName".asJsonPrimitive()
99 val stepInputData = StepData().apply {
100 name = "activate-restconf"
101 properties = operationInputs
103 val executionServiceInput = ExecutionServiceInput().apply {
104 commonHeader = CommonHeader().apply {
107 actionIdentifiers = ActionIdentifiers().apply {
108 actionName = "activate"
110 payload = JacksonUtils.jsonNode("{}") as ObjectNode
112 executionServiceInput.stepData = stepInputData
115 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
116 "activate-restconf", "interfaceName", "operationName")
117 } returns operationInputs
119 val operationOutputs = hashMapOf<String, JsonNode>()
121 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
122 "activate-restconf", "interfaceName", "operationName")
123 } returns operationOutputs
124 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
126 return executionServiceInput