2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2018 IBM.
6 * Modifications Copyright © 2019 IBM, Bell Canada.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
23 import kotlinx.coroutines.runBlocking
24 import org.junit.Assert
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.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
69 fun testRegisteredSource() {
70 val sources = resourceResolutionService.registeredResourceSources()
71 assertNotNull(sources, "failed to get registered sources")
72 assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
73 "source-rest")), "failed to get registered sources : $sources")
77 @Throws(Exception::class)
78 fun testResolveResource() {
81 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
83 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
84 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
86 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
87 ExecutionServiceInput::class.java)!!
90 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
92 resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig", mapOf())
98 @Throws(Exception::class)
99 fun testResolveResources() {
101 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
103 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
104 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
106 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
107 ExecutionServiceInput::class.java)!!
109 val artefactNames = listOf("baseconfig", "another")
112 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
114 resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artefactNames, mapOf())
120 @Throws(Exception::class)
121 fun testResolveResourcesWithMappingAndTemplate() {
123 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
125 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
126 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
128 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
129 ExecutionServiceInput::class.java)!!
131 val artifactPrefix = "another"
133 // Velocity Artifact Definition Name
134 val artifactTemplate = "$artifactPrefix-template"
135 // Resource Assignment Artifact Definition Name
136 val artifactMapping = "$artifactPrefix-mapping"
139 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
141 resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artifactMapping, artifactTemplate)