Add UT for ResourceResolutionService/Component 03/90703/4
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Sun, 30 Jun 2019 02:25:49 +0000 (22:25 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Thu, 4 Jul 2019 19:53:42 +0000 (15:53 -0400)
Change-Id: I460b3747ffdf5f4cfcb486803097939d1ae1fec0
Issue-ID: CCSDK-1046
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionServiceTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt

index fd14cc8..ee7c31a 100644 (file)
@@ -19,7 +19,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
 
 import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
@@ -27,7 +26,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
-import org.springframework.http.ResponseEntity
 import org.springframework.stereotype.Component
 
 @Component("component-resource-resolution")
@@ -38,14 +36,14 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
 
         val occurrence = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE).asInt()
-        val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY)?.asText() ?: ""
+        val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.asText() ?: ""
         val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)?.asBoolean() ?: false
         val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.asText() ?: ""
         val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.asText() ?: ""
 
         val properties: MutableMap<String, Any> = mutableMapOf()
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult
-        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = resolutionKey
+        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
index 929e9e8..fb32aa7 100644 (file)
@@ -24,7 +24,7 @@ object ResourceResolutionConstants {
         const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
         const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
         const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
-        const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key"
+        const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY = "resolution-key"
         const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"
         const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence"
         const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id"
index e08ac52..0e97267 100644 (file)
@@ -256,7 +256,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
                                         properties: Map<String, Any>,
                                         artifactPrefix: String): List<ResourceResolution> {
         val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
-        val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] as String
+        val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
         val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
         val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
 
index e9679ee..5335b14 100644 (file)
@@ -24,7 +24,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeServ
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 import org.slf4j.LoggerFactory
-import org.springframework.dao.DataIntegrityViolationException
 import org.springframework.dao.EmptyResultDataAccessException
 import org.springframework.stereotype.Service
 import java.util.*
@@ -126,7 +125,7 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
         val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
         val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
 
-        val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] as String
+        val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
         val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
         val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
         val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
index 4466296..55f7e77 100644 (file)
@@ -89,7 +89,7 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa
 
         val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
         val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
-        val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] as String
+        val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
         val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
         val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
         val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
index 39ffe5e..1abcea8 100644 (file)
@@ -93,6 +93,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
         } catch (runtimeException: RuntimeException) {
             log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
             recoverNB(runtimeException, resourceAssignment)
+            return false
         }
         return true
     }
index 3a30ae9..39076b4 100644 (file)
@@ -1,9 +1,5 @@
 /*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * Modifications Copyright © 2018 IBM.
- *
- *  Modifications Copyright © 2019 IBM, Bell Canada.
+ * Copyright © 2018 Bell Canada
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
 
 import com.fasterxml.jackson.databind.JsonNode
+import io.mockk.coEvery
+import io.mockk.every
+import io.mockk.mockk
 import kotlinx.coroutines.runBlocking
+import org.junit.Before
 import org.junit.Test
-import org.junit.runner.RunWith
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
-import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
-import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
-import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
-import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintError
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration
-import org.springframework.context.annotation.ComponentScan
-import org.springframework.test.context.ContextConfiguration
-import org.springframework.test.context.TestPropertySource
-import org.springframework.test.context.junit4.SpringRunner
-
-@RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
-    InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
-    DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class,
-    BlueprintPropertyConfiguration::class, BluePrintProperties::class,
-    BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
-@TestPropertySource(locations = ["classpath:application-test.properties"])
-@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
-@EnableAutoConfiguration
+import java.lang.RuntimeException
+import kotlin.test.assertEquals
+import kotlin.test.fail
+
 class ResourceResolutionComponentTest {
 
-    @Autowired
-    lateinit var resourceResolutionComponent: ResourceResolutionComponent
+    private val resourceResolutionService = mockk<ResourceResolutionService>()
+    private val resourceResolutionComponent = ResourceResolutionComponent(resourceResolutionService)
 
-    @Test
-    fun testProcess() {
-        runBlocking {
+    private val resolutionKey = "resolutionKey"
+    private val resourceId = "1"
+    private val resourceType = "ServiceInstance"
+    private val occurrence = 1
+    private val props = mutableMapOf<String, JsonNode>()
+    private val bluePrintRuntimeService = mockk<BluePrintRuntimeService<*>>()
+    private val artifactNames = listOf("template")
+    private val nodeTemplateName = "nodeTemplateName"
 
-            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                    "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+    private val executionRequest = ExecutionServiceInput()
 
-            val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
-                    ExecutionServiceInput::class.java)!!
 
-            // Prepare Inputs
-            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+    @Before
+    fun setup() {
 
-            val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
-            stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
-            stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
-            stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
-            bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true.asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey.asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId.asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType.asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence.asJsonPrimitive()
+        props[ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES] = JacksonUtils.jsonNodeFromObject(artifactNames)
 
-            resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
-            val stepInputData = StepData().apply {
-                name = "resource-assignment"
-                properties = stepMetaData
+        resourceResolutionComponent.operationInputs = props
+        resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
+        resourceResolutionComponent.nodeTemplateName = nodeTemplateName
+
+        resourceResolutionComponent.executionServiceInput = executionRequest
+        resourceResolutionComponent.processId = "12"
+        resourceResolutionComponent.workflowName = "workflow"
+        resourceResolutionComponent.stepName = "step"
+        resourceResolutionComponent.interfaceName = "interfaceName"
+        resourceResolutionComponent.operationName = "operationName"
+    }
+
+    @Test
+    fun processNBWithResolutionKeyAndResourceIdAndResourceTypeTestException() {
+        runBlocking {
+            try {
+                resourceResolutionComponent.processNB(executionRequest)
+            } catch (e: BluePrintProcessorException) {
+                assertEquals("Can't proceed with the resolution: either provide resolution-key OR combination of resource-id and resource-type.",
+                    e.message)
+                return@runBlocking
             }
-            executionServiceInput.stepData = stepInputData
-            resourceResolutionComponent.applyNB(executionServiceInput)
+            fail()
         }
     }
 
     @Test
-    fun testRecover() {
+    fun processNBWithResourceIdTestException() {
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive()
+
+        runBlocking {
+            try {
+                resourceResolutionComponent.processNB(executionRequest)
+            } catch (e: BluePrintProcessorException) {
+                assertEquals("Can't proceed with the resolution: both resource-id and resource-type should be provided, one of them is missing.",
+                    e.message)
+                return@runBlocking
+            }
+            fail()
+        }
+    }
+
+    @Test
+    fun processNBWithEmptyResourceTypeResourceIdResolutionKeyTestException() {
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = "".asJsonPrimitive()
+
         runBlocking {
-            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                    "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+            try {
+                resourceResolutionComponent.processNB(executionRequest)
+            } catch (e: BluePrintProcessorException) {
+                assertEquals("Can't proceed with the resolution: can't persist resolution without a correlation key. " +
+                        "Either provide a resolution-key OR combination of resource-id and resource-type OR set `storeResult` to false.",
+                    e.message)
+                return@runBlocking
+            }
+            fail()
+        }
+    }
 
-            val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
-                    ExecutionServiceInput::class.java)!!
+    @Test
+    fun processNBTest() {
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
 
-            // Prepare Inputs
-            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+        val properties = mutableMapOf<String, Any>()
+        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
+        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
+        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
+        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
 
-            val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
-            stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
-            stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
-            stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
-            bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+        coEvery {
+            resourceResolutionService.resolveResources(any<BluePrintRuntimeService<*>>(),
+                any<String>(),
+                any<List<String>>(),
+                any<MutableMap<String, Any>>())
+        } returns mutableMapOf()
+        every { bluePrintRuntimeService.setNodeTemplateAttributeValue(any(), any(), any()) } returns Unit
 
-            resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
-            val stepInputData = StepData().apply {
-                name = "resource-assignment"
-                properties = stepMetaData
-            }
-            executionServiceInput.stepData = stepInputData
-            resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput)
+
+        runBlocking {
+            resourceResolutionComponent.processNB(executionRequest)
+        }
+
+// FIXME add verification
+//        coVerify {
+//            resourceResolutionService.resolveResources(eq(bluePrintRuntimeService),
+//                eq(nodeTemplateName), eq(artifactNames), eq(properties))
+//        }
+    }
+
+    @Test
+    fun testRecover() {
+        runBlocking {
+            val blueprintError = BluePrintError()
+            val exception = RuntimeException("message")
+            every { bluePrintRuntimeService.getBluePrintError() } returns blueprintError
+            resourceResolutionComponent.recoverNB(exception, executionRequest)
+
+            assertEquals(1, blueprintError.errors.size)
         }
     }
 }
\ No newline at end of file
index abf0011..f1ad030 100644 (file)
@@ -20,6 +20,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
 
 import kotlinx.coroutines.runBlocking
 import org.junit.Assert
+import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
@@ -64,12 +65,27 @@ class ResourceResolutionServiceTest {
     @Autowired
     lateinit var resourceResolutionService: ResourceResolutionService
 
+    private val props = hashMapOf<String, Any>()
+    private val resolutionKey = "resolutionKey"
+    private val resourceId = "1"
+    private val resourceType = "ServiceInstance"
+    private val occurrence = 0
+
+    @Before
+    fun setup() {
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
+    }
+
     @Test
     fun testRegisteredSource() {
         val sources = resourceResolutionService.registeredResourceSources()
         assertNotNull(sources, "failed to get registered sources")
         assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
-                "source-rest")), "failed to get registered sources : $sources")
+            "source-rest")), "failed to get registered sources : $sources")
     }
 
     @Test
@@ -80,18 +96,27 @@ class ResourceResolutionServiceTest {
             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
 
             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                    "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+            val executionServiceInput =
+                JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+                    ExecutionServiceInput::class.java)!!
+
 
             val resourceAssignmentRuntimeService =
-                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
+                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+                    "testResolveResource")
 
-            val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
-                    ExecutionServiceInput::class.java)!!
 
             // Prepare Inputs
-            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+                executionServiceInput.payload,
+                "resource-assignment")
 
-            resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", "baseconfig", mapOf())
+            resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
+                "resource-assignment",
+                "baseconfig",
+                props)
 
         }
     }
@@ -103,20 +128,23 @@ class ResourceResolutionServiceTest {
             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
 
             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                    "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
-
-            val resourceAssignmentRuntimeService =
-                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
+                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
-            val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+            val executionServiceInput =
+                JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
                     ExecutionServiceInput::class.java)!!
 
             val artefactNames = listOf("baseconfig", "another")
 
             // Prepare Inputs
-            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
-
-            resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artefactNames, mapOf())
+            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+                executionServiceInput.payload,
+                "resource-assignment")
+
+            resourceResolutionService.resolveResources(bluePrintRuntimeService,
+                "resource-assignment",
+                artefactNames,
+                props)
         }
 
     }
@@ -128,20 +156,61 @@ class ResourceResolutionServiceTest {
             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
 
             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                    "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+            val executionServiceInput =
+                JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+                    ExecutionServiceInput::class.java)!!
 
             val resourceAssignmentRuntimeService =
-                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
+                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+                    "testResolveResourcesWithMappingAndTemplate")
 
-            val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+            val artifactPrefix = "another"
+
+            // Prepare Inputs
+            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+                executionServiceInput.payload,
+                "resource-assignment")
+
+            resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
+                "resource-assignment",
+                artifactPrefix,
+                props)
+        }
+    }
+
+
+    @Test
+    fun testResolveResourcesWithResourceIdAndResourceType() {
+
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
+
+        runBlocking {
+            Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
+
+            val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+            val executionServiceInput =
+                JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
                     ExecutionServiceInput::class.java)!!
 
+            val resourceAssignmentRuntimeService =
+                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+                    "testResolveResourcesWithMappingAndTemplate")
+
             val artifactPrefix = "another"
 
             // Prepare Inputs
-            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
-
-            resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artifactPrefix, mapOf<String, String>())
+            PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+                executionServiceInput.payload,
+                "resource-assignment")
+
+            resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
+                "resource-assignment",
+                artifactPrefix,
+                props)
         }
     }
 }
index cfd00ac..dcf2e64 100644 (file)
@@ -53,7 +53,7 @@ open class ResourceResolutionDBServiceTest {
         metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] = blueprintVersion
         metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = blueprintName
 
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = resolutionKey
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
index da19571..48c6f02 100644 (file)
@@ -1,6 +1,5 @@
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
 
-import io.mockk.confirmVerified
 import io.mockk.every
 import io.mockk.mockk
 import io.mockk.verify
@@ -9,10 +8,8 @@ import org.junit.Before
 import org.junit.Test
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
-import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 import org.springframework.dao.EmptyResultDataAccessException
 import kotlin.test.assertEquals
 
@@ -40,7 +37,7 @@ class TemplateResolutionServiceTest {
         metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] = blueprintVersion
         metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = blueprintName
 
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = resolutionKey
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
@@ -117,7 +114,7 @@ class TemplateResolutionServiceTest {
 
     @Test
     fun writeWithResourceIdResourceTypeExistingTest() {
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = ""
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
         val tr = TemplateResolution()
         runBlocking {
             every { templateResolutionRepository.saveAndFlush(any<TemplateResolution>()) } returns tr
index f73197e..153e889 100644 (file)
@@ -71,34 +71,6 @@ class DatabaseResourceResolutionProcessorTest {
 
             val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment)
             assertNotNull(processorName, "couldn't get Database resource assignment processor name")
-            println(processorName)
-        }
-    }
-
-    @Test
-    fun `test database resource resolution primary db`() {
-        runBlocking {
-            val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
-                    "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
-
-            val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
-
-            databaseResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
-            databaseResourceAssignmentProcessor.resourceDictionaries = ResourceAssignmentUtils
-                    .resourceDefinitions(bluePrintContext.rootPath)
-
-            val resourceAssignment = ResourceAssignment().apply {
-                name = "service-instance-id"
-                dictionaryName = "service-instance-id"
-                dictionarySource = "primary-db"
-                property = PropertyDefinition().apply {
-                    type = "string"
-                }
-            }
-
-            val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment)
-            assertNotNull(processorName, "couldn't get Database resource assignment processor name")
-            println(processorName)
         }
     }
 }
\ No newline at end of file