abf0011e67722664b59a5dceb32c5950cc47b9cc
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2018 - 2019 IBM, Bell Canada.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
20
21 import kotlinx.coroutines.runBlocking
22 import org.junit.Assert
23 import org.junit.Test
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
44
45 /**
46  * ResourceResolutionServiceTest
47  *
48  * @author Brinda Santh DATE : 8/15/2018
49  */
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 {
61
62     private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
63
64     @Autowired
65     lateinit var resourceResolutionService: ResourceResolutionService
66
67     @Test
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")
73     }
74
75     @Test
76     @Throws(Exception::class)
77     fun testResolveResource() {
78         runBlocking {
79
80             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
81
82             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
83                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
84
85             val resourceAssignmentRuntimeService =
86                 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
87
88             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
89                     ExecutionServiceInput::class.java)!!
90
91             // Prepare Inputs
92             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
93
94             resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", "baseconfig", mapOf())
95
96         }
97     }
98
99     @Test
100     @Throws(Exception::class)
101     fun testResolveResources() {
102         runBlocking {
103             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
104
105             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
106                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
107
108             val resourceAssignmentRuntimeService =
109                 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
110
111             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
112                     ExecutionServiceInput::class.java)!!
113
114             val artefactNames = listOf("baseconfig", "another")
115
116             // Prepare Inputs
117             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
118
119             resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artefactNames, mapOf())
120         }
121
122     }
123
124     @Test
125     @Throws(Exception::class)
126     fun testResolveResourcesWithMappingAndTemplate() {
127         runBlocking {
128             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
129
130             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
131                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
132
133             val resourceAssignmentRuntimeService =
134                 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, "test")
135
136             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
137                     ExecutionServiceInput::class.java)!!
138
139             val artifactPrefix = "another"
140
141             // Prepare Inputs
142             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
143
144             resourceResolutionService.resolveResources(resourceAssignmentRuntimeService, "resource-assignment", artifactPrefix, mapOf<String, String>())
145         }
146     }
147 }