X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=inline;f=ms%2Fblueprintsprocessor%2Ffunctions%2Fresource-resolution%2Fsrc%2Ftest%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Ffunctions%2Fresource%2Fresolution%2Fprocessor%2FRestResourceResolutionProcessorTest.kt;h=75c12a0f286abf420062fa1abad02e51077f96e7;hb=77891f46278488702aeed2fe970861a2f1b9a1a7;hp=1c0f33fcdace33ceef1085ea431c065a1c98a691;hpb=daab2a792144ffa728de67e24c801c3d0742c9b9;p=ccsdk%2Fcds.git diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt index 1c0f33fcd..75c12a0f2 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt @@ -15,6 +15,7 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor +import com.fasterxml.jackson.databind.JsonNode import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.runner.RunWith @@ -22,118 +23,235 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockBluePrintRestLibPropertyService +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockBlueprintWebClientService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockRestResourceResolutionProcessor import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.AfterTest import kotlin.test.BeforeTest -import kotlin.test.assertNotNull +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [MockRestResourceResolutionProcessor::class, MockBluePrintRestLibPropertyService::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, RestClientProperties::class]) +@ContextConfiguration( + classes = [ + MockRestResourceResolutionProcessor::class, MockBluePrintRestLibPropertyService::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, RestClientProperties::class + ] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class RestResourceResolutionProcessorTest { + @Autowired lateinit var bluePrintRestLibPropertyService: MockBluePrintRestLibPropertyService private lateinit var restResourceResolutionProcessor: MockRestResourceResolutionProcessor @BeforeTest - fun init(){ + fun init() { restResourceResolutionProcessor = MockRestResourceResolutionProcessor(bluePrintRestLibPropertyService) - } - - @Test - fun `test rest resource resolution`() { runBlocking { val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + ) val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils - .resourceDefinitions(bluePrintContext.rootPath) + .resourceDefinitions(bluePrintContext.rootPath) val scriptPropertyInstances: MutableMap = mutableMapOf() scriptPropertyInstances["mock-service1"] = MockCapabilityService() scriptPropertyInstances["mock-service2"] = MockCapabilityService() restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances + } + } + + @AfterTest + fun tearDown() { + bluePrintRestLibPropertyService.tearDown() + } + + private fun getExpectedJsonResponse(field: String? = null): JsonNode { + val node = JacksonUtils.jsonNode(MockBlueprintWebClientService.JSON_OUTPUT) + return if (field != null) + node.get(field) + else + node + } + @Test + fun `test rest resource resolution sdnc`() { + runBlocking { val resourceAssignment = ResourceAssignment().apply { - name = "rr-name" - dictionaryName = "vnf_name" + name = "vnf_name" + dictionaryName = "vnf_parameter" dictionarySource = "sdnc" + templatingConstants = mutableMapOf("parameter-name" to "vnf_name") property = PropertyDefinition().apply { type = "string" + required = true } } - val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment) - assertNotNull(processorName, "couldn't get Rest resource assignment processor name") - println(processorName) + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertTrue(result, "get Rest resource assignment failed") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_SUCCESS, + "get Rest resource assignment failed" + ) + val value = restResourceResolutionProcessor.raRuntimeService.getResolutionStore(resourceAssignment.name) + println("Resolution result: $result, status: ${resourceAssignment.status}, value: ${value.asText()}") + assertEquals( + getExpectedJsonResponse(resourceAssignment.name).asText(), + value.asText(), + "get Rest resource assignment failed - enexpected value" + ) } } @Test - fun `test rest aai get resource resolution`() { + fun `test rest resource resolution get required fails`() { runBlocking { - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + val resourceAssignment = ResourceAssignment().apply { + name = "rr-aai-empty" + dictionaryName = "aai-get-resource-null" + dictionarySource = "aai-data" + property = PropertyDefinition().apply { + type = "string" + required = true + } + } - restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService - restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils - .resourceDefinitions(bluePrintContext.rootPath) + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertFalse(result, "get Rest resource assignment succeeded while it should fail") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_FAILURE, + "get Rest resource assignment succeeded while it should fail" + ) + println("Resolution result: $result, status: ${resourceAssignment.status}") + } + } - val scriptPropertyInstances: MutableMap = mutableMapOf() - scriptPropertyInstances["mock-service1"] = MockCapabilityService() - scriptPropertyInstances["mock-service2"] = MockCapabilityService() + @Test + fun `test rest resource resolution get with wrong mapping fails`() { + runBlocking { + val resourceAssignment = ResourceAssignment().apply { + name = "rr-aai-wrong-mapping" + dictionaryName = "aai-get-resource-wrong-mapping" + dictionarySource = "aai-data" + property = PropertyDefinition().apply { + type = "string" + required = false + } + } - restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertFalse(result, "get Rest resource assignment succeeded while it should fail") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_FAILURE, + "get Rest resource assignment succeeded while it should fail" + ) + println("Resolution result: $result, status: ${resourceAssignment.status}") + } + } + @Test + fun `test rest resource resolution get without output mapping`() { + runBlocking { val resourceAssignment = ResourceAssignment().apply { - name = "rr-aai" - dictionaryName = "aai-get-resource" + name = "rr-aai-empty" + dictionaryName = "aai-get-resource-null" dictionarySource = "aai-data" property = PropertyDefinition().apply { type = "string" + required = false } } - val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment) - assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name") - println(processorName) + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertTrue(result, "get Rest resource assignment failed") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_SUCCESS, + "get Rest resource assignment failed" + ) + println("Resolution result: $result, status: ${resourceAssignment.status}") } } @Test - fun `test rest aai put resource resolution`() { + fun `test rest resource resolution aai get string`() { runBlocking { - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + val resourceAssignment = ResourceAssignment().apply { + name = "vnf-id" + dictionaryName = "aai-get-resource" + dictionarySource = "aai-data" + property = PropertyDefinition().apply { + type = "string" + required = true + } + } - restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService - restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils - .resourceDefinitions(bluePrintContext.rootPath) + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertTrue(result, "get AAI string Rest resource assignment failed") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_SUCCESS, + "get AAI string Rest resource assignment failed" + ) + val value = restResourceResolutionProcessor.raRuntimeService.getResolutionStore(resourceAssignment.name) + println("Resolution result: $result, status: ${resourceAssignment.status}, value: ${value.asText()}") + assertEquals( + getExpectedJsonResponse(resourceAssignment.name).asText(), + value.asText(), + "get Rest resource assignment failed - enexpected value" + ) + } + } - val scriptPropertyInstances: MutableMap = mutableMapOf() - scriptPropertyInstances["mock-service1"] = MockCapabilityService() - scriptPropertyInstances["mock-service2"] = MockCapabilityService() + @Test + fun `test rest resource resolution aai get json`() { + runBlocking { + val resourceAssignment = ResourceAssignment().apply { + name = "generic-vnf" + dictionaryName = "aai-get-json-resource" + dictionarySource = "aai-data" + property = PropertyDefinition().apply { + type = "json" + required = true + } + } - restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertTrue(result, "get AAI json Rest resource assignment failed") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_SUCCESS, + "get AAI json Rest resource assignment failed" + ) + val value = restResourceResolutionProcessor.raRuntimeService.getResolutionStore(resourceAssignment.name) + println("Resolution result: $result, status: ${resourceAssignment.status}, value: ${value.toPrettyString()}") + assertEquals( + getExpectedJsonResponse().toPrettyString(), + value.toPrettyString(), + "get Rest resource assignment failed - enexpected value" + ) + } + } + @Test + fun `test rest resource resolution aai put`() { + runBlocking { val resourceAssignment = ResourceAssignment().apply { name = "rr-aai" dictionaryName = "aai-put-resource" @@ -143,9 +261,13 @@ class RestResourceResolutionProcessorTest { } } - val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment) - assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name") - println(processorName) + val result = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertTrue(result, "put AAI Rest resource assignment failed") + assertEquals( + resourceAssignment.status, BluePrintConstants.STATUS_SUCCESS, + "put AAI json Rest resource assignment failed" + ) + println("Resolution result: $result, status: ${resourceAssignment.status}") } } }