Merge "Skeleton of CDS-SDC Listener ms"
[ccsdk/apps.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / functions / resource / resolution / ResourceResolutionServiceTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
19
20 import org.junit.Assert
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
24 import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
25 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils
27 import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration
28 import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
29 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
30 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
31 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
32 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
33 import org.slf4j.LoggerFactory
34 import org.springframework.beans.factory.annotation.Autowired
35 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
36 import org.springframework.context.annotation.ComponentScan
37 import org.springframework.test.context.ContextConfiguration
38 import org.springframework.test.context.TestPropertySource
39 import org.springframework.test.context.junit4.SpringRunner
40 import kotlin.test.assertNotNull
41 import kotlin.test.assertTrue
42
43 /**
44  * ResourceResolutionServiceTest
45  *
46  * @author Brinda Santh DATE : 8/15/2018
47  */
48 @RunWith(SpringRunner::class)
49 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
50     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
51     PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class,
52     CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class,
53     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
54     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
55 @TestPropertySource(locations = ["classpath:application-test.properties"])
56 @ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
57 @EnableAutoConfiguration
58 class ResourceResolutionServiceTest {
59
60     private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
61
62     @Autowired
63     lateinit var resourceResolutionService: ResourceResolutionService
64
65     @Test
66     fun testRegisteredSource() {
67         val sources = resourceResolutionService.registeredResourceSources()
68         assertNotNull(sources, "failed to get registered sources")
69         assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db",
70                 "source-rest")), "failed to get registered sources")
71     }
72
73     @Test
74     @Throws(Exception::class)
75     fun testResolveResource() {
76
77         Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
78
79         val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
80                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
81
82         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
83                 ExecutionServiceInput::class.java)!!
84
85         // Prepare Inputs
86         PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
87
88         resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig")
89
90     }
91
92 }