Merge "fixed sonar issue in AssignVlanTagResponse"
[ccsdk/apps.git] / ms / blueprintsprocessor / modules / services / workflow-service / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / services / workflow / BlueprintServiceLogicTest.kt
index 6fe767c..7312d2d 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow
 
-import com.fasterxml.jackson.databind.JsonNode
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
-import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
+import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.PrototypeComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.SingletonComponentFunction
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.context.ApplicationContext
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class])
@@ -38,52 +37,57 @@ class BlueprintServiceLogicTest {
 
     private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java)
 
-    val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-            "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+    @Autowired
+    lateinit var applicationContext: ApplicationContext
 
     @Autowired
-    lateinit var blueprintSvcLogicService: BlueprintSvcLogicService
+    lateinit var blueprintDGExecutionService: BlueprintDGExecutionService
 
     @Test
     fun testExecuteGraphWithSingleComponent() {
 
-        val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/one-component.xml")
-        val svcLogicContext = BlueprintSvcLogicContext()
-        svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
-        svcLogicContext.setRequest(getDefaultExecutionServiceInput())
-        blueprintSvcLogicService.execute(graph, svcLogicContext)
+        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+
+        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!!
+
+
+        blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput)
 
     }
 
     @Test
     fun testExecuteGraphWithMultipleComponents() {
-        val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/two-component.xml")
-        val svcLogicContext = BlueprintSvcLogicContext()
-        svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
-        svcLogicContext.setRequest(getDefaultExecutionServiceInput())
-        blueprintSvcLogicService.execute(graph, svcLogicContext)
+
+        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+
+        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!!
+
+        blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput)
 
     }
 
-    private fun getDefaultExecutionServiceInput(): ExecutionServiceInput {
-        val executionServiceInput = ExecutionServiceInput()
-        val commonHeader = CommonHeader()
-        commonHeader.requestId = "1234"
-        executionServiceInput.commonHeader = commonHeader
-
-        val actionIdentifiers = ActionIdentifiers()
-        actionIdentifiers.blueprintName = "baseconfiguration"
-        actionIdentifiers.blueprintVersion = "1.0.0"
-        actionIdentifiers.actionName = "activate"
-        executionServiceInput.actionIdentifiers = actionIdentifiers
-
-        val metaData: MutableMap<String, JsonNode> = hashMapOf()
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP,"resource-assignment-py")
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment-py")
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "DefaultComponentNode")
-        metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
-        executionServiceInput.metadata = metaData
-
-        return executionServiceInput
+    @Test
+    fun testSingleton() {
+        val singleton1 = applicationContext.getBean(SingletonComponentFunction::class.java)
+        singleton1.stepName = "step1"
+        val singleton2 = applicationContext.getBean(SingletonComponentFunction::class.java)
+        assertEquals(singleton1.stepName, singleton2.stepName, " failed to get singleton data")
     }
+
+    @Test
+    fun testProtoTypeFunction() {
+        val stepName1 = "step1"
+        val stepName2 = "step2"
+        val proto1 = applicationContext.getBean(PrototypeComponentFunction::class.java)
+        proto1.stepName = stepName1
+
+        val proto2 = applicationContext.getBean(PrototypeComponentFunction::class.java)
+        proto2.stepName = stepName2
+
+        assertEquals(stepName1, proto1.stepName, " Failed to match the step1 name")
+        assertEquals(stepName2, proto2.stepName, " Failed to match the step2 name")
+    }
+
 }
\ No newline at end of file