diff options
author | Dan Timoney <dtimoney@att.com> | 2019-07-15 19:18:46 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-07-15 19:18:46 +0000 |
commit | 47df1fc1660658ff5c4b5074e7313b10ed3ea359 (patch) | |
tree | 3a95a7eb539a9bf922cf401cc6ca58cd9c5dbb5d /ms/blueprintsprocessor/functions/resource-resolution | |
parent | 4d4e27fe9d08ff92e356b465cbdef227b10fe38a (diff) | |
parent | 631adb1e2542b3fe22b7d080072a7c6d9cfbdc72 (diff) |
Merge "Minor updates in ResourceResolutionComponent class"
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution')
2 files changed, 25 insertions, 22 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 8b7889d6c..b38ebb1b0 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 @@ -23,6 +23,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractCompone import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode +import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope @@ -31,15 +32,16 @@ import org.springframework.stereotype.Component @Component("component-resource-resolution") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : - AbstractComponentFunction() { + AbstractComponentFunction() { override suspend fun processNB(executionRequest: ExecutionServiceInput) { val occurrence = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE).asInt() - val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.textValue() ?: "" + val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.returnNullIfMissing()?.textValue() ?: "" val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)?.asBoolean() ?: false - val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.textValue() ?: "" - val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.textValue() ?: "" + val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.returnNullIfMissing()?.textValue() ?: "" + + val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.returnNullIfMissing()?.textValue() ?: "" val properties: MutableMap<String, Any> = mutableMapOf() properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult @@ -69,9 +71,9 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = j val response = resourceResolutionService.resolveResources(bluePrintRuntimeService, - nodeTemplateName, - artifactPrefixNames, - properties) + nodeTemplateName, + artifactPrefixNames, + properties) // provide indexed result in output if we have multiple resolution if (occurrence != 1) { @@ -84,7 +86,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re // Set Output Attributes bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse) + ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse) } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { 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 39076b4f5..560bc4142 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 @@ -17,6 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.MissingNode +import com.fasterxml.jackson.databind.node.NullNode import io.mockk.coEvery import io.mockk.every import io.mockk.mockk @@ -29,7 +31,6 @@ 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 java.lang.RuntimeException import kotlin.test.assertEquals import kotlin.test.fail @@ -79,7 +80,7 @@ class ResourceResolutionComponentTest { 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) + e.message) return@runBlocking } fail() @@ -88,15 +89,15 @@ class ResourceResolutionComponentTest { @Test fun processNBWithResourceIdTestException() { - props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive() - props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive() + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = NullNode.getInstance() + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = NullNode.getInstance() 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) + e.message) return@runBlocking } fail() @@ -105,9 +106,9 @@ class ResourceResolutionComponentTest { @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() + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = MissingNode.getInstance() + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = NullNode.getInstance() + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = NullNode.getInstance() runBlocking { try { @@ -115,7 +116,7 @@ class ResourceResolutionComponentTest { } 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) + e.message) return@runBlocking } fail() @@ -124,7 +125,7 @@ class ResourceResolutionComponentTest { @Test fun processNBTest() { - props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive() + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = NullNode.getInstance() val properties = mutableMapOf<String, Any>() properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true @@ -133,10 +134,10 @@ class ResourceResolutionComponentTest { properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence coEvery { - resourceResolutionService.resolveResources(any<BluePrintRuntimeService<*>>(), - any<String>(), - any<List<String>>(), - any<MutableMap<String, Any>>()) + resourceResolutionService.resolveResources(any(), + any(), + any<List<String>>(), + any<MutableMap<String, Any>>()) } returns mutableMapOf() every { bluePrintRuntimeService.setNodeTemplateAttributeValue(any(), any(), any()) } returns Unit |