cd51b338e88fdeb5eb64e4a78cd04a3c93471346
[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  *
4  * Modifications Copyright © 2018 IBM.
5  *
6  *  Modifications Copyright © 2019 IBM, Bell Canada.
7  *
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
22
23 import com.fasterxml.jackson.databind.JsonNode
24 import kotlinx.coroutines.runBlocking
25 import org.junit.Test
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
45
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 {
57
58     @Autowired
59     lateinit var resourceResolutionComponent: ResourceResolutionComponent
60
61     @Test
62     fun testProcess() {
63         runBlocking {
64
65             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
66                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
67
68             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
69                     ExecutionServiceInput::class.java)!!
70
71             // Prepare Inputs
72             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
73
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())
79
80             resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
81             resourceResolutionComponent.stepName = "resource-assignment"
82             resourceResolutionComponent.applyNB(executionServiceInput)
83         }
84     }
85
86     @Test
87     fun testRecover() {
88         runBlocking {
89             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
90                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
91
92             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
93                     ExecutionServiceInput::class.java)!!
94
95             // Prepare Inputs
96             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
97
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())
103
104             resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
105             resourceResolutionComponent.stepName = "resource-assignment"
106             resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput)
107         }
108     }
109 }