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.controllerblueprints.core.config.BluePrintLoadConfiguration
32 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
33 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
34 import org.slf4j.LoggerFactory
35 import org.springframework.beans.factory.annotation.Autowired
36 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
37 import org.springframework.context.annotation.ComponentScan
38 import org.springframework.test.context.ContextConfiguration
39 import org.springframework.test.context.TestPropertySource
40 import org.springframework.test.context.junit4.SpringRunner
41 import kotlin.test.assertNotNull
42 import kotlin.test.assertTrue
45 * ResourceResolutionServiceTest
47 * @author Brinda Santh DATE : 8/15/2018
49 @RunWith(SpringRunner::class)
50 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
51 InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
52 DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
53 CapabilityResourceResolutionProcessor::class,
54 BlueprintPropertyConfiguration::class, BluePrintProperties::class,
55 BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
56 @TestPropertySource(locations = ["classpath:application-test.properties"])
57 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
58 @EnableAutoConfiguration
59 class ResourceResolutionServiceTest {
61 private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
64 lateinit var resourceResolutionService: ResourceResolutionService
67 fun testRegisteredSource() {
68 val sources = resourceResolutionService.registeredResourceSources()
69 assertNotNull(sources, "failed to get registered sources")
70 assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
71 "source-rest")), "failed to get registered sources : $sources")
75 @Throws(Exception::class)
76 fun testResolveResource() {
79 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
81 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
82 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
84 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
85 ExecutionServiceInput::class.java)!!
88 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
90 resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig", mapOf())
96 @Throws(Exception::class)
97 fun testResolveResources() {
99 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
101 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
102 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
104 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
105 ExecutionServiceInput::class.java)!!
107 val artefactNames = listOf("baseconfig", "another")
110 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
112 resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artefactNames, mapOf())
118 @Throws(Exception::class)
119 fun testResolveResourcesWithMappingAndTemplate() {
121 Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
123 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
124 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
126 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
127 ExecutionServiceInput::class.java)!!
129 val artifactPrefix = "another"
132 PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
134 resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artifactPrefix, mapOf<String, String>())