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.utils.PayloadUtils
31 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
32 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
33 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
34 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
35 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
36 import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
37 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
38 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
39 import org.springframework.beans.factory.annotation.Autowired
40 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
41 import org.springframework.context.annotation.ComponentScan
42 import org.springframework.test.context.ContextConfiguration
43 import org.springframework.test.context.TestPropertySource
44 import org.springframework.test.context.junit4.SpringRunner
46 @RunWith(SpringRunner::class)
47 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
48 InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
49 DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
50 CapabilityResourceResolutionProcessor::class,
51 BlueprintPropertyConfiguration::class, BluePrintProperties::class,
52 BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
53 @TestPropertySource(locations = ["classpath:application-test.properties"])
54 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
55 @EnableAutoConfiguration
56 class ResourceResolutionComponentTest {
59 lateinit var resourceResolutionComponent: ResourceResolutionComponent
65 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
66 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
68 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
69 ExecutionServiceInput::class.java)!!
72 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
74 val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
75 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
76 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
77 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
78 bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
80 resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
81 resourceResolutionComponent.stepName = "resource-assignment"
82 resourceResolutionComponent.applyNB(executionServiceInput)
89 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
90 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
92 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
93 ExecutionServiceInput::class.java)!!
96 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
98 val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
99 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
100 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
101 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
102 bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
104 resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
105 resourceResolutionComponent.stepName = "resource-assignment"
106 resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput)