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