e82ffc458deacfcebe4bceed79a442b38cb7eb4b
[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.cds.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.cds.controllerblueprints.TestApplication
26 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
28 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
29 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
30 import org.onap.ccsdk.cds.controllerblueprints.service.load.ModelTypeLoadService
31 import org.onap.ccsdk.cds.controllerblueprints.service.load.ResourceDictionaryLoadService
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.test.context.ContextConfiguration
34 import org.springframework.test.context.TestPropertySource
35 import org.springframework.test.context.junit4.SpringRunner
36
37 @RunWith(SpringRunner::class)
38 @ContextConfiguration(classes = arrayOf(TestApplication::class))
39 @TestPropertySource(locations = arrayOf("classpath:application.properties"))
40 class BluePrintEnhancerServiceImplTest {
41
42     @Autowired
43     lateinit var modelTypeLoadService: ModelTypeLoadService
44
45     @Autowired
46     lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService
47
48     @Autowired
49     lateinit var bluePrintEnhancerService: BluePrintEnhancerService
50
51     @Autowired
52     lateinit var bluePrintValidatorService: BluePrintValidatorService
53
54     @Before
55     fun init() {
56         runBlocking {
57             modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type")
58
59             val dictPaths: MutableList<String> = arrayListOf()
60             dictPaths.add("./../../../../components/model-catalog/resource-dictionary/starter-dictionary")
61             dictPaths.add("./../../../../components/model-catalog/resource-dictionary/test-dictionary")
62             resourceDictionaryLoadService.loadPathsResourceDictionary(dictPaths)
63         }
64     }
65
66     @Test
67     @Throws(Exception::class)
68     fun testEnhancementAndValidation() {
69         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
70         testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
71     }
72
73     @Test
74     @Throws(Exception::class)
75     fun testVFWEnhancementAndValidation() {
76         val basePath = "./../../../../components/model-catalog/blueprint-model/service-blueprint/vFW"
77         testComponentInvokeEnhancementAndValidation(basePath, "vFW-enhance")
78     }
79
80     @Test
81     @Throws(Exception::class)
82     fun testGoldenEnhancementAndValidation() {
83         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
84         testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
85     }
86
87     @Test
88     @Throws(Exception::class)
89     fun testCapabilityRestconfEnhancementAndValidation() {
90         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_restconf"
91         testComponentInvokeEnhancementAndValidation(basePath, "capability_restconf-enhance")
92
93     }
94
95     private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
96         runBlocking {
97             val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName)
98
99             deleteDir(targetPath)
100
101             val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
102             Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
103
104             // Validate the Generated BluePrints
105             val valid = bluePrintValidatorService.validateBluePrints(targetPath)
106             Assert.assertTrue("blueprint($basePath) validation failed ", valid)
107
108 //            deleteDir(targetPath)
109         }
110     }
111
112
113 }