2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2018 - 2019 IBM, Bell Canada.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
21 import kotlinx.coroutines.runBlocking
22 import org.junit.Assert
23 import org.junit.Before
25 import org.junit.runner.RunWith
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
30 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
31 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
32 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
33 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
34 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
35 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
36 import org.slf4j.LoggerFactory
37 import org.springframework.beans.factory.annotation.Autowired
38 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
39 import org.springframework.context.annotation.ComponentScan
40 import org.springframework.test.context.ContextConfiguration
41 import org.springframework.test.context.TestPropertySource
42 import org.springframework.test.context.junit4.SpringRunner
43 import kotlin.test.assertNotNull
44 import kotlin.test.assertTrue
47 * ResourceResolutionServiceTest
49 * @author Brinda Santh DATE : 8/15/2018
51 @RunWith(SpringRunner::class)
52 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
53 InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
54 DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
55 CapabilityResourceResolutionProcessor::class,
56 BlueprintPropertyConfiguration::class, BluePrintProperties::class,
57 BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
58 @TestPropertySource(locations = ["classpath:application-test.properties"])
59 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
60 @EnableAutoConfiguration
61 class ResourceResolutionServiceTest {
63 private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
66 lateinit var resourceResolutionService: ResourceResolutionService
68 private val props = hashMapOf<String, Any>()
69 private val resolutionKey = "resolutionKey"
70 private val resourceId = "1"
71 private val resourceType = "ServiceInstance"
72 private val occurrence = 0
76 props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
77 props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
78 props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
79 props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
80 props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
84 fun testRegisteredSource() {
85 val sources = resourceResolutionService.registeredResourceSources()
86 assertNotNull(sources, "failed to get registered sources")
87 assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
88 "source-rest")), "failed to get registered sources : $sources")
92 @Throws(Exception::class)
93 fun testResolveResource() {
96 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
98 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
99 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
101 val executionServiceInput =
102 JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
103 ExecutionServiceInput::class.java)!!
106 val resourceAssignmentRuntimeService =
107 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
108 "testResolveResource")
112 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
113 executionServiceInput.payload,
114 "resource-assignment")
116 resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
117 "resource-assignment",
125 @Throws(Exception::class)
126 fun testResolveResources() {
128 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
130 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
131 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
133 val executionServiceInput =
134 JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
135 ExecutionServiceInput::class.java)!!
137 val artefactNames = listOf("baseconfig", "another")
140 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
141 executionServiceInput.payload,
142 "resource-assignment")
144 resourceResolutionService.resolveResources(bluePrintRuntimeService,
145 "resource-assignment",
153 @Throws(Exception::class)
154 fun testResolveResourcesWithMappingAndTemplate() {
156 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
158 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
159 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
161 val executionServiceInput =
162 JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
163 ExecutionServiceInput::class.java)!!
165 val resourceAssignmentRuntimeService =
166 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
167 "testResolveResourcesWithMappingAndTemplate")
169 val artifactPrefix = "another"
172 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
173 executionServiceInput.payload,
174 "resource-assignment")
176 resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
177 "resource-assignment",
185 fun testResolveResourcesWithResourceIdAndResourceType() {
187 props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
190 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
192 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
193 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
195 val executionServiceInput =
196 JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
197 ExecutionServiceInput::class.java)!!
199 val resourceAssignmentRuntimeService =
200 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
201 "testResolveResourcesWithMappingAndTemplate")
203 val artifactPrefix = "another"
206 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
207 executionServiceInput.payload,
208 "resource-assignment")
210 resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
211 "resource-assignment",