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