fe824ca2f54be0593248b26ebd1b1a143e7afe96
[ccsdk/cds.git] /
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.DBLibGenericService
29 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.CapabilityResourceResolutionProcessor
30 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.DatabaseResourceAssignmentProcessor
31 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.DefaultResourceResolutionProcessor
32 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.InputResourceResolutionProcessor
33 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.RestResourceResolutionProcessor
34 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
35 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
36 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
37 import org.slf4j.LoggerFactory
38 import org.springframework.beans.factory.annotation.Autowired
39 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
40 import org.springframework.context.annotation.ComponentScan
41 import org.springframework.test.context.ContextConfiguration
42 import org.springframework.test.context.TestPropertySource
43 import org.springframework.test.context.junit4.SpringRunner
44 import kotlin.test.assertNotNull
45 import kotlin.test.assertTrue
46
47 /**
48  * ResourceResolutionServiceTest
49  *
50  * @author Brinda Santh DATE : 8/15/2018
51  */
52 @RunWith(SpringRunner::class)
53 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
54     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
55     DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
56     CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
57     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
58     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
59 @TestPropertySource(locations = ["classpath:application-test.properties"])
60 @ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
61 @EnableAutoConfiguration
62 class ResourceResolutionServiceTest {
63
64     private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
65
66     @Autowired
67     lateinit var resourceResolutionService: ResourceResolutionService
68
69     @Test
70     fun testRegisteredSource() {
71         val sources = resourceResolutionService.registeredResourceSources()
72         assertNotNull(sources, "failed to get registered sources")
73         assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db",
74                 "source-rest")), "failed to get registered sources")
75     }
76
77     @Test
78     @Throws(Exception::class)
79     fun testResolveResource() {
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 }