2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2018 IBM.
6 * Modifications Copyright © 2019 IBM, Bell Canada.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
23 import com.fasterxml.jackson.databind.JsonNode
24 import kotlinx.coroutines.runBlocking
26 import org.junit.runner.RunWith
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
31 import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
32 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
33 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
34 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
35 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
36 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
37 import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
38 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
39 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
40 import org.springframework.beans.factory.annotation.Autowired
41 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
42 import org.springframework.context.annotation.ComponentScan
43 import org.springframework.test.context.ContextConfiguration
44 import org.springframework.test.context.TestPropertySource
45 import org.springframework.test.context.junit4.SpringRunner
47 @RunWith(SpringRunner::class)
48 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
49 InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
50 DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
51 CapabilityResourceResolutionProcessor::class,
52 BlueprintPropertyConfiguration::class, BluePrintProperties::class,
53 BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
54 @TestPropertySource(locations = ["classpath:application-test.properties"])
55 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
56 @EnableAutoConfiguration
57 class ResourceResolutionComponentTest {
60 lateinit var resourceResolutionComponent: ResourceResolutionComponent
66 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
67 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
69 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
70 ExecutionServiceInput::class.java)!!
73 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
75 val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
76 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
77 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
78 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
79 bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
81 resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
82 val stepInputData = StepData().apply {
83 name = "resource-assignment"
84 properties = stepMetaData
86 executionServiceInput.stepData = stepInputData
87 resourceResolutionComponent.applyNB(executionServiceInput)
94 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
95 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
97 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
98 ExecutionServiceInput::class.java)!!
101 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
103 val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
104 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
105 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
106 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
107 bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
109 resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
110 val stepInputData = StepData().apply {
111 name = "resource-assignment"
112 properties = stepMetaData
114 executionServiceInput.stepData = stepInputData
115 resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput)