Merge "Enhance logger to the server"
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionServiceTest.kt
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.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
43
44 /**
45  * ResourceResolutionServiceTest
46  *
47  * @author Brinda Santh DATE : 8/15/2018
48  */
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 {
60
61     private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
62
63     @Autowired
64     lateinit var resourceResolutionService: ResourceResolutionService
65
66     @Test
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")
72     }
73
74     @Test
75     @Throws(Exception::class)
76     fun testResolveResource() {
77         runBlocking {
78
79             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
80
81             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
82                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
83
84             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
85                     ExecutionServiceInput::class.java)!!
86
87             // Prepare Inputs
88             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
89
90             resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig", mapOf())
91
92         }
93     }
94
95     @Test
96     @Throws(Exception::class)
97     fun testResolveResources() {
98         runBlocking {
99             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
100
101             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
102                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
103
104             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
105                     ExecutionServiceInput::class.java)!!
106
107             val artefactNames = listOf("baseconfig", "another")
108
109             // Prepare Inputs
110             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
111
112             resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artefactNames, mapOf())
113         }
114
115     }
116
117     @Test
118     @Throws(Exception::class)
119     fun testResolveResourcesWithMappingAndTemplate() {
120         runBlocking {
121             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
122
123             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
124                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
125
126             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
127                     ExecutionServiceInput::class.java)!!
128
129             val artifactPrefix = "another"
130
131             // Prepare Inputs
132             PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
133
134             resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artifactPrefix, mapOf<String, String>())
135         }
136     }
137 }