Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionComponentTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
19
20 import com.fasterxml.jackson.databind.JsonNode
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
27 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
29 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
30 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
31 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
32 import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
33 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
34 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
35 import org.springframework.beans.factory.annotation.Autowired
36 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
37 import org.springframework.context.annotation.ComponentScan
38 import org.springframework.test.context.ContextConfiguration
39 import org.springframework.test.context.TestPropertySource
40 import org.springframework.test.context.junit4.SpringRunner
41
42 @RunWith(SpringRunner::class)
43 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
44     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
45     DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
46     CapabilityResourceResolutionProcessor::class,
47     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
48     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
49 @TestPropertySource(locations = ["classpath:application-test.properties"])
50 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
51 @EnableAutoConfiguration
52 class ResourceResolutionComponentTest {
53
54     @Autowired
55     lateinit var resourceResolutionComponent: ResourceResolutionComponent
56
57     @Test
58     fun testProcess() {
59
60         val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
61                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
62
63         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
64                 ExecutionServiceInput::class.java)!!
65
66         // Prepare Inputs
67         PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
68
69         val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
70         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
71         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
72         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
73         bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
74
75         resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
76         resourceResolutionComponent.stepName = "resource-assignment"
77         resourceResolutionComponent.apply(executionServiceInput)
78     }
79 }