1f872c2da6b97da469c49663f8e5d27467efd3d6
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / test / kotlin / org / onap / ccsdk / cds / controllerblueprints / service / enhancer / BluePrintEnhancerServiceImplTest.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.cds.controllerblueprints.service.enhancer
19
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Assert
22 import org.junit.Test
23 import org.junit.runner.RunWith
24 import org.onap.ccsdk.cds.controllerblueprints.TestApplication
25 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
28 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
29 import org.onap.ccsdk.cds.controllerblueprints.service.load.ModelTypeLoadService
30 import org.onap.ccsdk.cds.controllerblueprints.service.load.ResourceDictionaryLoadService
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
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
54     @Test
55     @Throws(Exception::class)
56     fun testEnhancementAndValidation() {
57
58         runBlocking {
59             modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type")
60
61             val dictPaths: MutableList<String> = arrayListOf()
62             dictPaths.add("./../../../../components/model-catalog/resource-dictionary/starter-dictionary")
63             dictPaths.add("./../../../../components/model-catalog/resource-dictionary/test-dictionary")
64             resourceDictionaryLoadService.loadPathsResourceDictionary(dictPaths)
65
66             testBaseConfigEnhancementAndValidation()
67             testVFWEnhancementAndValidation()
68             testGoldenEnhancementAndValidation()
69             testCapabilityRestconfEnhancementAndValidation()
70             testRemoteScriptsEnhancementAndValidation()
71             testCapabilityCliEnhancementAndValidation()
72         }
73     }
74
75     fun testBaseConfigEnhancementAndValidation() {
76         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
77         testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
78     }
79
80     fun testVFWEnhancementAndValidation() {
81         val basePath = "./../../../../components/model-catalog/blueprint-model/service-blueprint/vFW"
82         testComponentInvokeEnhancementAndValidation(basePath, "vFW-enhance")
83     }
84
85     fun testGoldenEnhancementAndValidation() {
86         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
87         testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
88     }
89
90     fun testCapabilityRestconfEnhancementAndValidation() {
91         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_restconf"
92         testComponentInvokeEnhancementAndValidation(basePath, "capability_restconf-enhance")
93
94     }
95
96     fun testRemoteScriptsEnhancementAndValidation() {
97         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
98         testComponentInvokeEnhancementAndValidation(basePath, "remote_scripts-enhance")
99
100     }
101
102     fun testCapabilityCliEnhancementAndValidation() {
103         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_cli"
104         testComponentInvokeEnhancementAndValidation(basePath, "capability_cli-enhance")
105     }
106
107     private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
108         runBlocking {
109             val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName)
110
111             deleteDir(targetPath)
112
113             val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
114             Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
115
116             // Validate the Generated BluePrints
117             val valid = bluePrintValidatorService.validateBluePrints(targetPath)
118             Assert.assertTrue("blueprint($basePath) validation failed ", valid)
119
120             // Enable this to get the enhanced zip file
121 //            val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip")
122 //            normalizedFile(targetPath).compress(compressFile)
123
124             deleteDir(targetPath)
125         }
126     }
127
128
129 }