summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/test')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt110
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json5
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request2.json4
3 files changed, 117 insertions, 2 deletions
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
@@ -249,6 +249,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.
*/
@Test
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
index 3ca754f87..e247ea248 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
@@ -25,7 +25,10 @@
"action-name": "assign-activate",
"scope-type": "vnf-type",
"hostname": "localhost",
- "vnf_name": "temp_vnf"
+ "vnf_name": "temp_vnf",
+ "firmware-version": "firmware-version-0",
+ "ip-address": "192.0.0.1"
+
}
}
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request2.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request2.json
index 726477515..17f5aad52 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request2.json
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request2.json
@@ -24,7 +24,9 @@
"action-name": "assign-activate",
"scope-type": "vnf-type",
"hostname": "localhost",
- "vnf_name": "temp_vnf_new_resolution"
+ "vnf_name": "temp_vnf_new_resolution",
+ "firmware-version": "firmware-version-1",
+ "ip-address": "192.0.0.2"
}
}
}