From e4a0eef7b713551e075f71b00ff20f2448492c59 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Thu, 19 Sep 2019 16:58:46 -0400 Subject: Refactoring Resource Resolution Component Use Case: ---------- Input Value (IV): It can be API Input Value or API Default value If a Resource is marked as Input -> pick IV If a Resource is marked as other than Input -> pick IV -> if IV is not present then resolve it as per DataDictionary Definition ** Return Error if Resource is not resolved using assert : ResourceAssignmentUtils.assertTemplateKeyValueNotNull Issue-ID: CCSDK-1746 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ia3aaaa36d0e32b0b468f016d57ed5d2c4ddf6a32 --- .../mock/MockRestResourceResolutionProcessor.kt | 21 +++++------ .../CapabilityResourceResolutionProcessorTest.kt | 44 ++++++++++++++-------- 2 files changed, 39 insertions(+), 26 deletions(-) (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/test') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt index e80663094..203b7ea30 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockRestResourceResolutionProcessor.kt @@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.moc import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.ArrayNode -import com.fasterxml.jackson.databind.node.MissingNode import org.apache.commons.collections.MapUtils import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.RestResourceSource @@ -55,8 +54,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe override suspend fun processNB(executionRequest: ResourceAssignment) { try { // Check if It has Input - val value = getFromInput(executionRequest) - if (value == null || value is MissingNode) { + if (!setFromInput(executionRequest)) { val dName = executionRequest.dictionaryName val dSource = executionRequest.dictionarySource val resourceDefinition = resourceDictionaries[dName] @@ -66,7 +64,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe val resourceSourceProperties = resourceSource!!.properties val sourceProperties = - JacksonUtils.getInstanceFromMap(resourceSourceProperties!!, RestResourceSource::class.java) + JacksonUtils.getInstanceFromMap(resourceSourceProperties!!, RestResourceSource::class.java) val path = nullToEmpty(sourceProperties.path) val inputKeyMapping = sourceProperties.inputKeyMapping @@ -76,7 +74,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe // Resolving content Variables val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping) val urlPath = - resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping) + resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping) val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping) logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") @@ -98,8 +96,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe } } catch (e: Exception) { ResourceAssignmentUtils.setFailedResourceDataValue(executionRequest, e.message) - throw BluePrintProcessorException("Failed in template resolutionKey ($executionRequest) assignments with: ${e.message}", - e) + throw BluePrintProcessorException("Failed in template resolutionKey ($executionRequest) assignments with: ${e.message}", e) } } @@ -139,10 +136,12 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe outputKeyMapping!!.map { val responseKeyValue = responseSingleJsonNode.get(it.key) val propertyTypeForDataType = ResourceAssignmentUtils - .getPropertyType(raRuntimeService, entrySchemaType, it.key) + .getPropertyType(raRuntimeService, entrySchemaType, it.key) - JacksonUtils.populateJsonNodeValues(it.value, - responseKeyValue, propertyTypeForDataType, arrayChildNode) + JacksonUtils.populateJsonNodeValues( + it.value, + responseKeyValue, propertyTypeForDataType, arrayChildNode + ) } arrayNode.add(arrayChildNode) } @@ -157,7 +156,7 @@ class MockRestResourceResolutionProcessor(private val blueprintRestLibPropertySe outputKeyMapping!!.map { val responseKeyValue = responseNode.get(it.key) val propertyTypeForDataType = ResourceAssignmentUtils - .getPropertyType(raRuntimeService, entrySchemaType, it.key) + .getPropertyType(raRuntimeService, entrySchemaType, it.key) JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode) } // Set the List of Complex Values diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt index f020f2952..98f68ebaa 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor +import com.fasterxml.jackson.databind.node.NullNode import io.mockk.coEvery import io.mockk.every import io.mockk.mockk @@ -48,12 +49,16 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class, - BluePrintScriptsServiceImpl::class, - BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class]) -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"]) +@ContextConfiguration( + classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class, + BluePrintScriptsServiceImpl::class, + BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class] +) +@TestPropertySource( + properties = + ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"] +) class CapabilityResourceResolutionProcessorTest { @Autowired @@ -65,17 +70,21 @@ class CapabilityResourceResolutionProcessorTest { val componentFunctionScriptingService = mockk() coEvery { componentFunctionScriptingService - .scriptInstance(any(), any(), any()) + .scriptInstance(any(), any(), any()) } returns MockCapabilityScriptRA() val raRuntimeService = mockk() every { raRuntimeService.bluePrintContext() } returns mockk() + every { raRuntimeService.getInputValue("test-property") } returns NullNode.getInstance() - val capabilityResourceResolutionProcessor = CapabilityResourceResolutionProcessor(componentFunctionScriptingService) + val capabilityResourceResolutionProcessor = + CapabilityResourceResolutionProcessor(componentFunctionScriptingService) capabilityResourceResolutionProcessor.raRuntimeService = raRuntimeService - val resourceAssignment = BluePrintTypes.resourceAssignment(name = "test-property", dictionaryName = "ra-dict-name", - dictionarySource = "capability") { + val resourceAssignment = BluePrintTypes.resourceAssignment( + name = "test-property", dictionaryName = "ra-dict-name", + dictionarySource = "capability" + ) { property("string", true, "") sourceCapability { definedProperties { @@ -87,8 +96,10 @@ class CapabilityResourceResolutionProcessorTest { } val status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment) assertTrue(status, "failed to execute capability source") - assertEquals("assigned-data".asJsonPrimitive(), resourceAssignment.property!!.value, - "assigned value miss match") + assertEquals( + "assigned-data".asJsonPrimitive(), resourceAssignment.property!!.value, + "assigned value miss match" + ) } } @@ -97,15 +108,18 @@ class CapabilityResourceResolutionProcessorTest { runBlocking { val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python") + "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python" + ) val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService val resourceDefinition = JacksonUtils - .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json", - ResourceDefinition::class.java)!! + .readValueFromClassPathFile( + "mapping/capability/jython-resource-definitions.json", + ResourceDefinition::class.java + )!! val resourceDefinitions: MutableMap = mutableMapOf() resourceDefinitions[resourceDefinition.name] = resourceDefinition capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions -- cgit 1.2.3-korg