48183f4cb435bfe30ff284c770dcf0b4ad2e48bd
[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.controllerblueprints.service.enhancer
19
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Assert
22 import org.junit.Before
23 import org.junit.Test
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.apps.controllerblueprints.TestApplication
26 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService
27 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
28 import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService
29 import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService
30 import org.springframework.beans.factory.annotation.Autowired
31 import org.springframework.test.context.ContextConfiguration
32 import org.springframework.test.context.TestPropertySource
33 import org.springframework.test.context.junit4.SpringRunner
34 import java.nio.file.Paths
35
36 @RunWith(SpringRunner::class)
37 @ContextConfiguration(classes = arrayOf(TestApplication::class))
38 @TestPropertySource(locations = arrayOf("classpath:application.properties"))
39 class BluePrintEnhancerServiceImplTest {
40
41     @Autowired
42     lateinit var modelTypeLoadService: ModelTypeLoadService
43
44     @Autowired
45     lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService
46
47     @Autowired
48     lateinit var bluePrintEnhancerService: BluePrintEnhancerService
49
50     @Autowired
51     lateinit var bluePrintValidatorService: BluePrintValidatorService
52
53     @Before
54     fun init() {
55         runBlocking {
56             modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type")
57             resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary")
58             resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/test-dictionary")
59         }
60     }
61
62     @Test
63     @Throws(Exception::class)
64     fun testEnhancementAndValidation() {
65
66         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
67         testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
68     }
69
70     @Test
71     @Throws(Exception::class)
72     fun testComponentInvokeEnhancementAndValidation() {
73         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke"
74         testComponentInvokeEnhancementAndValidation(basePath, "component-enhance")
75     }
76
77     @Test
78     @Throws(Exception::class)
79     fun testGoldenEnhancementAndValidation() {
80         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
81         testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
82     }
83
84
85     private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
86
87         val targetPath = Paths.get("target", targetDirName).toUri().path
88
89         val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
90         Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
91
92         // Validate the Generated BluePrints
93         val valid = bluePrintValidatorService.validateBluePrints(targetPath)
94         Assert.assertTrue("blueprint($basePath) validation failed ", valid)
95     }
96
97 }