Blueprint Processor Python Script Components
[ccsdk/cds.git] / components / core / src / test / kotlin / org / onap / ccsdk / apps / controllerblueprints / core / service / BluePrintRuntimeServiceTest.kt
index f1980d2..02148f0 100644 (file)
 \r
 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
 \r
+import com.att.eelf.configuration.EELFLogger\r
+import com.att.eelf.configuration.EELFManager\r
 import com.fasterxml.jackson.databind.JsonNode\r
-import org.junit.Before\r
+import com.fasterxml.jackson.databind.node.NullNode\r
 import org.junit.Test\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
-import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory\r
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils\r
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromFile\r
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromObject\r
-import com.att.eelf.configuration.EELFLogger\r
-import com.att.eelf.configuration.EELFManager\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import kotlin.test.assertEquals\r
 import kotlin.test.assertNotNull\r
 \r
@@ -37,99 +37,91 @@ import kotlin.test.assertNotNull
  */\r
 class BluePrintRuntimeServiceTest {\r
     private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())\r
-    val basepath = "load/blueprints"\r
-\r
-\r
-    @Before\r
-    fun setUp(): Unit {\r
-\r
-    }\r
 \r
     @Test\r
-    fun testResolveNodeTemplateProperties() {\r
+    fun `test Resolve NodeTemplate Properties`() {\r
         log.info("************************ testResolveNodeTemplateProperties **********************")\r
 \r
         val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
         val inputDataPath = "src/test/resources/data/default-context.json"\r
 \r
-        val inputNode: JsonNode = jsonNodeFromFile(inputDataPath)\r
+        val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)\r
         bluePrintRuntimeService.assignInputs(inputNode)\r
 \r
-        val propContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateProperties("resource-assignment-action")\r
-        log.info("Context {}", bluePrintRuntimeService.context)\r
+        val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService\r
+                .resolveNodeTemplateProperties("activate-process")\r
 \r
         assertNotNull(propContext, "Failed to populate interface property values")\r
-        assertEquals(propContext.get("mode"), jsonNodeFromObject("sync"), "Failed to populate parameter process-name")\r
-        assertEquals(propContext.get("version"), jsonNodeFromObject("1.0.0"), "Failed to populate parameter version")\r
     }\r
 \r
     @Test\r
-    fun testResolveNodeTemplateInterfaceOperationInputs() {\r
-        log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")\r
-        val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
-                .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
-        assertNotNull(bluePrintContext, "Failed to populate Blueprint context")\r
+    fun `test resolve NodeTemplate Capability Properties`() {\r
+        log.info("************************ testResolveNodeTemplateRequirementProperties **********************")\r
+        val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
-        val context: MutableMap<String, Any> = hashMapOf()\r
-        context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
+        val executionContext = bluePrintRuntimeService.getExecutionContext()\r
 \r
-        val inputDataPath = "src/test/resources/data/default-context.json"\r
-        BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context)\r
+        BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),\r
+                "data/default-context.json", executionContext)\r
 \r
+        val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device",\r
+                "netconf")\r
+        assertNotNull(capProperties, "Failed to populate capability property values")\r
+        assertEquals(capProperties["target-ip-address"], JacksonUtils.jsonNodeFromObject("localhost"), "Failed to populate parameter target-ip-address")\r
+        assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")\r
+    }\r
 \r
-        val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)\r
+    @Test\r
+    fun `test Resolve NodeTemplate Interface Operation Inputs`() {\r
+        log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")\r
+\r
+        val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
-        log.info("Prepared Context {}", context)\r
+        val executionContext = bluePrintRuntimeService.getExecutionContext()\r
 \r
-        val inContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment-ra-component",\r
-                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")\r
+        BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),\r
+                "data/default-context.json", executionContext)\r
 \r
-        log.info("In Context {}", inContext)\r
+        val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService\r
+                .resolveNodeTemplateInterfaceOperationInputs("resource-assignment",\r
+                        "ResourceAssignmentComponent", "process")\r
 \r
         assertNotNull(inContext, "Failed to populate interface input property values")\r
-        assertEquals(inContext.get("action-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")\r
-        assertEquals(inContext.get("request-id"), jsonNodeFromObject("12345"), "Failed to populate parameter action-name")\r
+        assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")\r
+        assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")\r
     }\r
 \r
     @Test\r
-    fun testResolveNodeTemplateInterfaceOperationOutputs() {\r
+    fun `test Resolve NodeTemplate Interface Operation Outputs`() {\r
         log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")\r
 \r
         val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
-        val successValue: JsonNode = jsonNodeFromObject("Success")\r
-        val paramValue: JsonNode = jsonNodeFromObject("param-content")\r
+        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())\r
 \r
-        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "params", paramValue)\r
+        bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",\r
+                "ResourceAssignmentComponent", "process")\r
 \r
-        bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment-ra-component",\r
-                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")\r
-\r
-        val resourceAssignmentParamsNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment-ra-component",\r
-                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", "resource-assignment-params")\r
-\r
-        val statusNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment-ra-component",\r
-                "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", "status")\r
-\r
-        assertEquals(paramValue, resourceAssignmentParamsNode, "Failed to get operation property resource-assignment-params")\r
-\r
-        assertEquals(successValue, statusNode, "Failed to get operation property status")\r
+        val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",\r
+                "ResourceAssignmentComponent", "process", "status")\r
+        assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")\r
 \r
+        val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",\r
+                "ResourceAssignmentComponent", "process", "resource-assignment-params")\r
+        assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")\r
 \r
     }\r
 \r
     @Test\r
-    fun testNodeTemplateContextProperty() {\r
+    fun `test NodeTemplate Context Property`() {\r
         log.info("************************ testNodeTemplateContextProperty **********************")\r
         val bluePrintRuntimeService = getBluePrintRuntimeService()\r
 \r
         bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",\r
-                jsonNodeFromObject("context1-value"))\r
+                JacksonUtils.jsonNodeFromObject("context1-value"))\r
         bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",\r
-                jsonNodeFromObject("context2-value"))\r
-\r
-        log.info("Context {}", bluePrintRuntimeService.context)\r
+                JacksonUtils.jsonNodeFromObject("context2-value"))\r
 \r
         val keys = listOf("context1", "context2")\r
 \r
@@ -139,15 +131,14 @@ class BluePrintRuntimeServiceTest {
 \r
     }\r
 \r
-    private fun getBluePrintRuntimeService(): BluePrintRuntimeService {\r
-        val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
-                .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
-        assertNotNull(bluePrintContext, "Failed to populate Blueprint context")\r
+    private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {\r
+        val blueprintBasePath: String = ("./../model-catalog/blueprint-model/starter-blueprint/baseconfiguration")\r
+        val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)\r
+        val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)\r
 \r
-        val context: MutableMap<String, Any> = hashMapOf()\r
-        context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
+        assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")\r
 \r
-        return BluePrintRuntimeService(bluePrintContext, context)\r
+        return blueprintRuntime\r
     }\r
 \r
 }
\ No newline at end of file