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
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
29 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
30 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
31 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
32 import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
33 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
34 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
35 import org.slf4j.LoggerFactory
36 import org.springframework.beans.factory.annotation.Autowired
37 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
38 import org.springframework.context.annotation.ComponentScan
39 import org.springframework.test.context.ContextConfiguration
40 import org.springframework.test.context.TestPropertySource
41 import org.springframework.test.context.junit4.SpringRunner
42 import kotlin.test.assertNotNull
43 import kotlin.test.assertTrue
46 * ResourceResolutionServiceTest
48 * @author Brinda Santh DATE : 8/15/2018
50 @RunWith(SpringRunner::class)
51 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
52 InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
53 DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
54 CapabilityResourceResolutionProcessor::class,
55 BlueprintPropertyConfiguration::class, BluePrintProperties::class,
56 BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
57 @TestPropertySource(locations = ["classpath:application-test.properties"])
58 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
59 @EnableAutoConfiguration
60 class ResourceResolutionServiceTest {
62 private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
65 lateinit var resourceResolutionService: ResourceResolutionService
68 fun testRegisteredSource() {
69 val sources = resourceResolutionService.registeredResourceSources()
70 assertNotNull(sources, "failed to get registered sources")
71 assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
72 "source-rest")), "failed to get registered sources : $sources")
76 @Throws(Exception::class)
77 fun testResolveResource() {
80 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
82 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
83 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
85 val resourceAssignmentRuntimeService =
86 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
88 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
89 ExecutionServiceInput::class.java)!!
92 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
94 resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", "baseconfig", mapOf())
100 @Throws(Exception::class)
101 fun testResolveResources() {
103 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
105 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
106 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
108 val resourceAssignmentRuntimeService =
109 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
111 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
112 ExecutionServiceInput::class.java)!!
114 val artefactNames = listOf("baseconfig", "another")
117 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
119 resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artefactNames, mapOf())
125 @Throws(Exception::class)
126 fun testResolveResourcesWithMappingAndTemplate() {
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 resourceAssignmentRuntimeService =
134 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
136 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
137 ExecutionServiceInput::class.java)!!
139 val artifactPrefix = "another"
142 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
144 resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artifactPrefix, mapOf<String, String>())