X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fblueprintsprocessor%2Ffunctions%2Fresource-resolution%2Fsrc%2Ftest%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Ffunctions%2Fresource%2Fresolution%2FResourceResolutionServiceTest.kt;h=b39e709d0be5622c544efcea130d5ba76721eb61;hb=89c17ae2e3222b98450e7c8d17566cd76ecf113b;hp=a801a7eb9ce3b8ba1ca40cce97a0dfe9a9b78962;hpb=e8e0087c6aea0bf9b2d3d17207574e8db84ba0f3;p=ccsdk%2Fcds.git 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 a801a7eb9..b39e709d0 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 @@ -248,6 +248,116 @@ class ResourceResolutionServiceTest { } } + /** + * Always perform new resolution even if resolution exists in the database. + */ + @Test + @Throws(Exception::class) + fun testResolveResourcesForMaxOccurrence() { + runBlocking { + // Occurrence <= 0 indicates to perform new resolution even if resolution exists in the database. + props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = -1 + Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) + + // Run time for Request#1 + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime( + "1234", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + ) + + // Request#1 + val executionServiceInput = + JacksonUtils.readValueFromClassPathFile( + "payload/requests/sample-resourceresolution-request.json", + ExecutionServiceInput::class.java + )!! + + // Prepare inputs from Request#1 + PayloadUtils.prepareInputsFromWorkflowPayload( + bluePrintRuntimeService, + executionServiceInput.payload, + "resource-assignment" + ) + + val resourceAssignmentRuntimeService = + ResourceAssignmentUtils.transformToRARuntimeService( + bluePrintRuntimeService, + "testResolveResource" + ) + + // Resolve resources as per Request#1 + resourceResolutionService.resolveResources( + resourceAssignmentRuntimeService, + "resource-assignment", + "maxoccurrence", + props + ) + + // Run time for Request#2 + val bluePrintRuntimeService2 = BluePrintMetadataUtils.getBluePrintRuntime( + "1234", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + ) + + // Request#2 + val executionServiceInput2 = + JacksonUtils.readValueFromClassPathFile( + "payload/requests/sample-resourceresolution-request2.json", + ExecutionServiceInput::class.java + )!! + + val resourceAssignmentRuntimeService2 = + ResourceAssignmentUtils.transformToRARuntimeService( + bluePrintRuntimeService2, + "testResolveResource" + ) + + // Prepare inputs from Request#2 + PayloadUtils.prepareInputsFromWorkflowPayload( + bluePrintRuntimeService2, + executionServiceInput2.payload, + "resource-assignment" + ) + + // Resolve resources as per Request#2 + resourceResolutionService.resolveResources( + resourceAssignmentRuntimeService2, + "resource-assignment", + "maxoccurrence", + props + ) + }.let { (template, assignmentList) -> + assertEquals("This is maxoccurrence Velocity Template", template) + + val assignmentListForRequest1 = mutableListOf( + "firmware-version" to "firmware-version-0", + "ip-address" to "192.0.0.1" + ) + val assignmentListForRequest2 = mutableListOf( + "firmware-version" to "firmware-version-1", + "ip-address" to "192.0.0.1" + ) + assertEquals(assignmentListForRequest1.size, assignmentList.size) + assertEquals(assignmentListForRequest2.size, assignmentList.size) + + // firmware-version has max-occurrence = 0 means perform new resolution all the time. + // ip-address has max-occurrence = 1 so its resolution should only be done once. + // + // AlwaysPerformNewResolution + max-occurrence feature use case - resolution request #2 should returns + // the resolution as per assignmentListForRequest2 since new resolution is only performed for + // firmware-version and not for ip-address. + var areEqual = assignmentListForRequest1.zip(assignmentList).all { (it1, it2) -> + it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null + } + assertEquals(false, areEqual) + + areEqual = assignmentListForRequest2.zip(assignmentList).all { (it1, it2) -> + it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null + } + assertEquals(true, areEqual) + } + } + /** * Don't perform new resolution in case resolution already exists in the database. */