import com.fasterxml.jackson.databind.node.JsonNodeFactory
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
-import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component
@Component("component-resource-resolution")
override suspend fun processNB(executionRequest: ExecutionServiceInput) {
val occurrence = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE).asInt()
- val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY)?.asText() ?: ""
+ val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.asText() ?: ""
val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)?.asBoolean() ?: false
val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.asText() ?: ""
val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.asText() ?: ""
val properties: MutableMap<String, Any> = mutableMapOf()
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult
- properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = resolutionKey
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
- const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key"
+ const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY = "resolution-key"
const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"
const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence"
const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id"
properties: Map<String, Any>,
artifactPrefix: String): List<ResourceResolution> {
val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
- val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] as String
+ val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
-import org.springframework.dao.DataIntegrityViolationException
import org.springframework.dao.EmptyResultDataAccessException
import org.springframework.stereotype.Service
import java.util.*
val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
- val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] as String
+ val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
- val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] as String
+ val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
} catch (runtimeException: RuntimeException) {
log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
recoverNB(runtimeException, resourceAssignment)
+ return false
}
return true
}
/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * Modifications Copyright © 2018 IBM.
- *
- * Modifications Copyright © 2019 IBM, Bell Canada.
+ * Copyright © 2018 Bell Canada
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
import com.fasterxml.jackson.databind.JsonNode
+import io.mockk.coEvery
+import io.mockk.every
+import io.mockk.mockk
import kotlinx.coroutines.runBlocking
+import org.junit.Before
import org.junit.Test
-import org.junit.runner.RunWith
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
-import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
-import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
-import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
-import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintError
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration
-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
-
-@RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
- InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
- DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
- CapabilityResourceResolutionProcessor::class,
- BlueprintPropertyConfiguration::class, BluePrintProperties::class,
- BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
-@TestPropertySource(locations = ["classpath:application-test.properties"])
-@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
-@EnableAutoConfiguration
+import java.lang.RuntimeException
+import kotlin.test.assertEquals
+import kotlin.test.fail
+
class ResourceResolutionComponentTest {
- @Autowired
- lateinit var resourceResolutionComponent: ResourceResolutionComponent
+ private val resourceResolutionService = mockk<ResourceResolutionService>()
+ private val resourceResolutionComponent = ResourceResolutionComponent(resourceResolutionService)
- @Test
- fun testProcess() {
- runBlocking {
+ private val resolutionKey = "resolutionKey"
+ private val resourceId = "1"
+ private val resourceType = "ServiceInstance"
+ private val occurrence = 1
+ private val props = mutableMapOf<String, JsonNode>()
+ private val bluePrintRuntimeService = mockk<BluePrintRuntimeService<*>>()
+ private val artifactNames = listOf("template")
+ private val nodeTemplateName = "nodeTemplateName"
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ private val executionRequest = ExecutionServiceInput()
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
- // Prepare Inputs
- PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+ @Before
+ fun setup() {
- val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
- bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true.asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey.asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId.asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType.asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence.asJsonPrimitive()
+ props[ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES] = JacksonUtils.jsonNodeFromObject(artifactNames)
- resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
- val stepInputData = StepData().apply {
- name = "resource-assignment"
- properties = stepMetaData
+ resourceResolutionComponent.operationInputs = props
+ resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
+ resourceResolutionComponent.nodeTemplateName = nodeTemplateName
+
+ resourceResolutionComponent.executionServiceInput = executionRequest
+ resourceResolutionComponent.processId = "12"
+ resourceResolutionComponent.workflowName = "workflow"
+ resourceResolutionComponent.stepName = "step"
+ resourceResolutionComponent.interfaceName = "interfaceName"
+ resourceResolutionComponent.operationName = "operationName"
+ }
+
+ @Test
+ fun processNBWithResolutionKeyAndResourceIdAndResourceTypeTestException() {
+ runBlocking {
+ try {
+ resourceResolutionComponent.processNB(executionRequest)
+ } catch (e: BluePrintProcessorException) {
+ assertEquals("Can't proceed with the resolution: either provide resolution-key OR combination of resource-id and resource-type.",
+ e.message)
+ return@runBlocking
}
- executionServiceInput.stepData = stepInputData
- resourceResolutionComponent.applyNB(executionServiceInput)
+ fail()
}
}
@Test
- fun testRecover() {
+ fun processNBWithResourceIdTestException() {
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive()
+
+ runBlocking {
+ try {
+ resourceResolutionComponent.processNB(executionRequest)
+ } catch (e: BluePrintProcessorException) {
+ assertEquals("Can't proceed with the resolution: both resource-id and resource-type should be provided, one of them is missing.",
+ e.message)
+ return@runBlocking
+ }
+ fail()
+ }
+ }
+
+ @Test
+ fun processNBWithEmptyResourceTypeResourceIdResolutionKeyTestException() {
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive()
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = "".asJsonPrimitive()
+
runBlocking {
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ try {
+ resourceResolutionComponent.processNB(executionRequest)
+ } catch (e: BluePrintProcessorException) {
+ assertEquals("Can't proceed with the resolution: can't persist resolution without a correlation key. " +
+ "Either provide a resolution-key OR combination of resource-id and resource-type OR set `storeResult` to false.",
+ e.message)
+ return@runBlocking
+ }
+ fail()
+ }
+ }
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
+ @Test
+ fun processNBTest() {
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
- // Prepare Inputs
- PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+ val properties = mutableMapOf<String, Any>()
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
- val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
- bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+ coEvery {
+ resourceResolutionService.resolveResources(any<BluePrintRuntimeService<*>>(),
+ any<String>(),
+ any<List<String>>(),
+ any<MutableMap<String, Any>>())
+ } returns mutableMapOf()
+ every { bluePrintRuntimeService.setNodeTemplateAttributeValue(any(), any(), any()) } returns Unit
- resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
- val stepInputData = StepData().apply {
- name = "resource-assignment"
- properties = stepMetaData
- }
- executionServiceInput.stepData = stepInputData
- resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput)
+
+ runBlocking {
+ resourceResolutionComponent.processNB(executionRequest)
+ }
+
+// FIXME add verification
+// coVerify {
+// resourceResolutionService.resolveResources(eq(bluePrintRuntimeService),
+// eq(nodeTemplateName), eq(artifactNames), eq(properties))
+// }
+ }
+
+ @Test
+ fun testRecover() {
+ runBlocking {
+ val blueprintError = BluePrintError()
+ val exception = RuntimeException("message")
+ every { bluePrintRuntimeService.getBluePrintError() } returns blueprintError
+ resourceResolutionComponent.recoverNB(exception, executionRequest)
+
+ assertEquals(1, blueprintError.errors.size)
}
}
}
\ No newline at end of file
import kotlinx.coroutines.runBlocking
import org.junit.Assert
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
@Autowired
lateinit var resourceResolutionService: ResourceResolutionService
+ private val props = hashMapOf<String, Any>()
+ private val resolutionKey = "resolutionKey"
+ private val resourceId = "1"
+ private val resourceType = "ServiceInstance"
+ private val occurrence = 0
+
+ @Before
+ fun setup() {
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
+ }
+
@Test
fun testRegisteredSource() {
val sources = resourceResolutionService.registeredResourceSources()
assertNotNull(sources, "failed to get registered sources")
assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
- "source-rest")), "failed to get registered sources : $sources")
+ "source-rest")), "failed to get registered sources : $sources")
}
@Test
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ "./../../../../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, "test")
+ ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+ "testResolveResource")
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
// Prepare Inputs
- PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment")
- resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", "baseconfig", mapOf())
+ resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
+ "resource-assignment",
+ "baseconfig",
+ props)
}
}
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
-
- val resourceAssignmentRuntimeService =
- ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ val executionServiceInput =
+ JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
ExecutionServiceInput::class.java)!!
val artefactNames = listOf("baseconfig", "another")
// Prepare Inputs
- PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
-
- resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artefactNames, mapOf())
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment")
+
+ resourceResolutionService.resolveResources(bluePrintRuntimeService,
+ "resource-assignment",
+ artefactNames,
+ props)
}
}
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ "./../../../../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, "test")
+ ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate")
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ val artifactPrefix = "another"
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment")
+
+ resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
+ "resource-assignment",
+ artifactPrefix,
+ props)
+ }
+ }
+
+
+ @Test
+ fun testResolveResourcesWithResourceIdAndResourceType() {
+
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
+
+ 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 = "another"
// Prepare Inputs
- PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
-
- resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artifactPrefix, mapOf<String, String>())
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment")
+
+ resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
+ "resource-assignment",
+ artifactPrefix,
+ props)
}
}
}
metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] = blueprintVersion
metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = blueprintName
- props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = resolutionKey
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
-import io.mockk.confirmVerified
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.Test
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
-import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.springframework.dao.EmptyResultDataAccessException
import kotlin.test.assertEquals
metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] = blueprintVersion
metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = blueprintName
- props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = resolutionKey
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
@Test
fun writeWithResourceIdResourceTypeExistingTest() {
- props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = ""
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
val tr = TemplateResolution()
runBlocking {
every { templateResolutionRepository.saveAndFlush(any<TemplateResolution>()) } returns tr
val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment)
assertNotNull(processorName, "couldn't get Database resource assignment processor name")
- println(processorName)
- }
- }
-
- @Test
- fun `test database resource resolution primary db`() {
- runBlocking {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
-
- val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
-
- databaseResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
- databaseResourceAssignmentProcessor.resourceDictionaries = ResourceAssignmentUtils
- .resourceDefinitions(bluePrintContext.rootPath)
-
- val resourceAssignment = ResourceAssignment().apply {
- name = "service-instance-id"
- dictionaryName = "service-instance-id"
- dictionarySource = "primary-db"
- property = PropertyDefinition().apply {
- type = "string"
- }
- }
-
- val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment)
- assertNotNull(processorName, "couldn't get Database resource assignment processor name")
- println(processorName)
}
}
}
\ No newline at end of file