summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/test
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-01-21 11:27:14 -0500
committerJozsef Csongvai <jozsef.csongvai@bell.ca>2020-02-21 10:42:19 -0500
commitebcc45b8c8703cadc49cf3a0b888545845ccb9e6 (patch)
tree83ea2525f5eee56e47d6a2650677ee11eebf0e86 /ms/blueprintsprocessor/functions/resource-resolution/src/test
parent9e3c594bc3cf74ab5748c14bcde81dec7f062fa0 (diff)
Eliminate Template Requirement
Enables resource assignment without the use of a template. If no template is defined by the CBA, the default output is a kev-value map. If operation input: resolution-summary is set to true, output will be a list of ResolutionSummary. Issue-ID: CCSDK-2038 Change-Id: I5f6bcefcacec6e83cffac1134b13690b500a7563 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
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/ResourceResolutionComponentDSLTest.kt1
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt97
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt58
3 files changed, 155 insertions, 1 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt
index ae9b4208f..d1347113a 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt
@@ -41,6 +41,7 @@ class ResourceResolutionComponentDSLTest {
occurrence(2)
resourceType("vnf")
storeResult(false)
+ resolutionSummary(true)
artifactPrefixNames(arrayListOf("template1", "template2"))
dynamicProperties(
"""{
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 2f338a3a1..0a12540d4 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
@@ -36,6 +36,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
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.ResolutionSummary
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -44,6 +45,7 @@ import org.springframework.context.annotation.ComponentScan
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@@ -79,6 +81,7 @@ class ResourceResolutionServiceTest {
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = false
}
@Test
@@ -214,6 +217,100 @@ class ResourceResolutionServiceTest {
}
@Test
+ @Throws(Exception::class)
+ fun testResolveResourcesResolutionSummary() {
+ runBlocking {
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = true
+ Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ "1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ )
+
+ val executionServiceInput =
+ JacksonUtils.readValueFromClassPathFile(
+ "payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java
+ )!!
+
+ val resourceAssignmentRuntimeService =
+ ResourceAssignmentUtils.transformToRARuntimeService(
+ bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate"
+ )
+
+ val artifactPrefix = "notemplate"
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(
+ bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment"
+ )
+
+ resourceResolutionService.resolveResources(
+ resourceAssignmentRuntimeService,
+ "resource-assignment",
+ artifactPrefix,
+ props
+ )
+ }.let {
+ val list = JacksonUtils.getListFromJson(it, ResolutionSummary::class.java)
+ assertEquals(list.size, 3)
+ }
+ }
+
+ @Test
+ @Throws(Exception::class)
+ fun testResolveResourcesWithoutTemplate() {
+ runBlocking {
+ Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ "1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ )
+
+ val executionServiceInput =
+ JacksonUtils.readValueFromClassPathFile(
+ "payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java
+ )!!
+
+ val resourceAssignmentRuntimeService =
+ ResourceAssignmentUtils.transformToRARuntimeService(
+ bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate"
+ )
+
+ val artifactPrefix = "notemplate"
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(
+ bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment"
+ )
+
+ resourceResolutionService.resolveResources(
+ resourceAssignmentRuntimeService,
+ "resource-assignment",
+ artifactPrefix,
+ props
+ )
+ }.let {
+ assertEquals("""
+ {
+ "service-instance-id" : "siid_1234",
+ "vnf-id" : "vnf_1234",
+ "vnf_name" : "temp_vnf"
+ }
+ """.trimIndent(), it)
+ }
+ }
+
+ @Test
fun testResolveResourcesWithResourceIdAndResourceType() {
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
runBlocking {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
index 3251dcacb..8ca401664 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
@@ -33,10 +33,12 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
import org.onap.ccsdk.cds.controllerblueprints.core.data.EntrySchema
+import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
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.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import kotlin.test.assertEquals
data class IpAddress(val port: String, val ip: String)
@@ -46,6 +48,7 @@ data class ExpectedResponseIpAddress(val ipAddress: IpAddress)
class ResourceAssignmentUtilsTest {
private lateinit var resourceAssignmentRuntimeService: ResourceAssignmentRuntimeService
+ private lateinit var resourceAssignment: ResourceAssignment
private lateinit var inputMapToTestPrimitiveTypeWithValue: JsonNode
private lateinit var inputMapToTestPrimitiveTypeWithKeyValue: JsonNode
@@ -156,6 +159,34 @@ class ResourceAssignmentUtilsTest {
assertEquals(expected, outcome.replace("\r\n", "\n"), "unexpected outcome generated")
}
+ @Test
+ fun generate() {
+ val resourceAssignment = createResourceAssignmentForTest(null)
+ val resourceDefinition = ResourceDefinition()
+ val nodeTemplate = NodeTemplate().apply {
+ properties = mutableMapOf("payload" to JacksonUtils.jsonNode("{\"mock\": true}"))
+ }
+ resourceDefinition.sources = mutableMapOf("input" to nodeTemplate)
+
+ val result = ResourceAssignmentUtils.generateResolutionSummaryData(
+ listOf(resourceAssignment), mapOf("pnf-id" to resourceDefinition))
+
+ assertEquals("""
+ [{
+ "name":"pnf-id",
+ "value":null,
+ "required":null,
+ "type":"string",
+ "key-identifiers":[],
+ "dictionary-name":"pnf-id",
+ "request-payload":{"mock":true},
+ "dictionary-source":"input",
+ "status":null,
+ "message":null
+ }]
+ """.replace("\n|\\s".toRegex(), ""), result)
+ }
+
private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment {
val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
val resourceAssignmentForTest = ResourceAssignment().apply {
@@ -181,6 +212,7 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for primitive type of simple String"
)
+ assertEquals(0, resourceAssignment.keyIdentifiers.size)
outcome = prepareResponseNodeForTest(
"sample-key-value", "string", "",
@@ -191,6 +223,10 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for primitive type of key-value String"
)
+ assertEquals(
+ expectedValueToTestPrimitiveType,
+ resourceAssignment.keyIdentifiers[0].value
+ )
}
@Test
@@ -204,6 +240,13 @@ class ResourceAssignmentUtilsTest {
outcome,
"unexpected outcome returned for list of String"
)
+
+ val expectedKeyIdentifierValue = JacksonUtils.getJsonNode(outcome.map { it["ip"] })
+ assertEquals(
+ expectedKeyIdentifierValue,
+ resourceAssignment.keyIdentifiers[0].value
+ )
+
// FIXME("Map is not collection type, It is known complex type")
// outcome = prepareResponseNodeForTest(
// "mapOfString", "map", "string",
@@ -250,6 +293,9 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for complex type"
)
+ assertEquals(
+ expectedValueToTestComplexTypeWithOneOutputKeyMapping["host"],
+ resourceAssignment.keyIdentifiers[0].value)
}
@Test
@@ -263,6 +309,16 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for complex type"
)
+ assertEquals(2, resourceAssignment.keyIdentifiers.size)
+ assertEquals(
+ expectedValueToTestComplexTypeWithAllOutputKeyMapping["name"],
+ resourceAssignment.keyIdentifiers[0].value
+ )
+
+ assertEquals(
+ expectedValueToTestComplexTypeWithAllOutputKeyMapping["ipAddress"],
+ resourceAssignment.keyIdentifiers[1].value
+ )
}
private fun initInputMapAndExpectedValuesForPrimitiveType() {
@@ -359,7 +415,7 @@ class ResourceAssignmentUtilsTest {
response: Any
): JsonNode {
- val resourceAssignment = when (sourceType) {
+ resourceAssignment = when (sourceType) {
"list" -> {
prepareRADataDictionaryCollection(dictionary_source, sourceType, entrySchema)
}