2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.apps.controllerblueprints.core.service
\r
20 import com.att.eelf.configuration.EELFLogger
\r
21 import com.att.eelf.configuration.EELFManager
\r
22 import com.fasterxml.jackson.databind.JsonNode
\r
23 import com.fasterxml.jackson.databind.node.NullNode
\r
24 import org.junit.Test
\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
\r
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils
\r
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
\r
30 import kotlin.test.assertEquals
\r
31 import kotlin.test.assertNotNull
\r
36 * @author Brinda Santh
\r
38 class BluePrintRuntimeServiceTest {
\r
39 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
\r
42 fun testResolveNodeTemplateProperties() {
\r
43 log.info("************************ testResolveNodeTemplateProperties **********************")
\r
45 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
47 val inputDataPath = "src/test/resources/data/default-context.json"
\r
49 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
\r
50 bluePrintRuntimeService.assignInputs(inputNode)
\r
52 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService.resolveNodeTemplateProperties("activate-process")
\r
54 assertNotNull(propContext, "Failed to populate interface property values")
\r
58 fun testResolveNodeTemplateCapabilityProperties() {
\r
59 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
\r
64 fun testResolveNodeTemplateRequirementProperties() {
\r
65 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
\r
70 fun testResolveNodeTemplateInterfaceOperationInputs() {
\r
71 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
\r
73 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
75 val executionContext = bluePrintRuntimeService.getExecutionContext()
\r
77 BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
\r
78 "data/default-context.json", executionContext)
\r
80 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
\r
81 "ResourceAssignmentComponent", "process")
\r
83 assertNotNull(inContext, "Failed to populate interface input property values")
\r
84 assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
\r
85 assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
\r
89 fun testResolveNodeTemplateInterfaceOperationOutputs() {
\r
90 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
\r
92 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
94 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
\r
96 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
\r
97 "ResourceAssignmentComponent", "process")
\r
99 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
\r
100 "ResourceAssignmentComponent", "process", "status")
\r
101 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
\r
103 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
\r
104 "ResourceAssignmentComponent", "process", "resource-assignment-params")
\r
105 assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
\r
110 fun testNodeTemplateContextProperty() {
\r
111 log.info("************************ testNodeTemplateContextProperty **********************")
\r
112 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
114 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",
\r
115 JacksonUtils.jsonNodeFromObject("context1-value"))
\r
116 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
\r
117 JacksonUtils.jsonNodeFromObject("context2-value"))
\r
119 val keys = listOf("context1", "context2")
\r
121 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
\r
122 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
\r
123 log.info("JSON Prepared Value Context {}", jsonValueNode)
\r
127 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
\r
128 val blueprintBasePath: String = ("./../model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
\r
129 val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
\r
130 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
\r
132 assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
\r
134 return blueprintRuntime
\r