Created media folders for ResourceDictionary
[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.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
46
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 {
58
59     @Autowired
60     lateinit var resourceResolutionComponent: ResourceResolutionComponent
61
62     @Test
63     fun testProcess() {
64         runBlocking {
65
66             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
67                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
68
69             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
70                     ExecutionServiceInput::class.java)!!
71
72             // Prepare Inputs
73             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
74
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())
80
81             resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
82             val stepInputData = StepData().apply {
83                 name = "resource-assignment"
84                 properties = stepMetaData
85             }
86             executionServiceInput.stepData = stepInputData
87             resourceResolutionComponent.applyNB(executionServiceInput)
88         }
89     }
90
91     @Test
92     fun testRecover() {
93         runBlocking {
94             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
95                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
96
97             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
98                     ExecutionServiceInput::class.java)!!
99
100             // Prepare Inputs
101             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
102
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())
108
109             resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
110             val stepInputData = StepData().apply {
111                 name = "resource-assignment"
112                 properties = stepMetaData
113             }
114             executionServiceInput.stepData = stepInputData
115             resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput)
116         }
117     }
118 }