diff options
Diffstat (limited to 'ms/blueprintsprocessor/functions')
11 files changed, 223 insertions, 139 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index fd14cc8c1..ee7c31ad2 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index 929e9e8df..fb32aa78b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -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" diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index e08ac520a..0e97267da 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt index e9679eeba..5335b14b1 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt @@ -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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt index 44662965d..55f7e770b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt @@ -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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index 39ffe5ea9..1abcea825 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -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 } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt index 3a30ae90e..39076b4f5 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt @@ -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. @@ -21,98 +17,150 @@ 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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt index abf0011e6..f1ad03054 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt @@ -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) } } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt index cfd00ac1d..dcf2e64a5 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt @@ -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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionServiceTest.kt index da1957190..48c6f02ef 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionServiceTest.kt @@ -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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt index f73197e0b..153e88937 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt @@ -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 |