8a08268d821c7f2ef8a8032e634fd4bc56046c32
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2019 IBM, Bell Canada.
5  * Modifications Copyright © 2019 IBM.
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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  */
19
20 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
21
22 import com.fasterxml.jackson.databind.JsonNode
23 import kotlinx.coroutines.runBlocking
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
28 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
29 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
30 import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
31 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
32 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
33 import org.springframework.beans.factory.annotation.Autowired
34 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
35 import org.springframework.context.annotation.ComponentScan
36 import org.springframework.test.annotation.DirtiesContext
37 import org.springframework.test.context.TestPropertySource
38 import org.springframework.test.context.junit4.SpringRunner
39
40 @RunWith(SpringRunner::class)
41 @EnableAutoConfiguration
42 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
43 @DirtiesContext
44 @TestPropertySource(properties =
45 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints",
46     "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"],
47         locations = ["classpath:application-test.properties"])
48 class ComponentNetconfExecutorTest {
49
50     @Autowired
51     lateinit var componentNetconfExecutor: ComponentNetconfExecutor
52
53
54     @Test
55     fun testComponentNetconfExecutor() {
56
57         runBlocking {
58             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json",
59                     ExecutionServiceInput::class.java)!!
60
61             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
62                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
63
64             val assignmentParams = "{\n" +
65                     "            \"ipAddress\": \"127.0.0.1\",\n" +
66                     "            \"hostName\": \"vnf-host\"\n" +
67                     "          }"
68
69             val json = """{
70                 "hostname" : "127.0.0.1"
71                 }                
72             """.trimIndent()
73
74             bluePrintRuntimeService.assignInputs(json.asJsonType())
75             bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
76                     JacksonUtils.jsonNode(assignmentParams))
77
78             val executionContext = bluePrintRuntimeService.getExecutionContext()
79
80             componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
81
82             //TODO("Set Attribute properties")
83             val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
84             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf")
85             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor")
86             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
87             // Set Step Inputs in Blueprint Runtime Service
88             componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
89             val stepInputData = StepData().apply {
90                 name = "activate-netconf"
91                 properties = stepMetaData
92             }
93             executionServiceInput.stepData = stepInputData
94             componentNetconfExecutor.applyNB(executionServiceInput)
95         }
96
97     }
98 }
99