c8c2f0b9baf2f4705fa16cb3ef6ff6c39d14a8f9
[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.blueprintsprocessor.designer.api.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.blueprintsprocessor.core.BluePrintPropertiesService
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration
26 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
27 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiTestConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.ModelTypeLoadService
29 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.ResourceDictionaryLoadService
30 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
31 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
32 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
33 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
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(
41     classes = [DesignerApiTestConfiguration::class,
42         BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]
43 )
44 @TestPropertySource(locations = ["classpath:application-test.properties"])
45 class BluePrintEnhancerServiceImplTest {
46
47     @Autowired
48     lateinit var modelTypeLoadService: ModelTypeLoadService
49
50     @Autowired
51     lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService
52
53     @Autowired
54     lateinit var bluePrintEnhancerService: BluePrintEnhancerService
55
56     @Autowired
57     lateinit var bluePrintValidatorService: BluePrintValidatorService
58
59     @Test
60     @Throws(Exception::class)
61     fun testEnhancementAndValidation() {
62
63         runBlocking {
64             modelTypeLoadService.loadPathModelType("./../../../../../components/model-catalog/definition-type/starter-type")
65
66             val dictPaths: MutableList<String> = arrayListOf()
67             dictPaths.add("./../../../../../components/model-catalog/resource-dictionary/starter-dictionary")
68             dictPaths.add("./../../../../../components/model-catalog/resource-dictionary/test-dictionary")
69             resourceDictionaryLoadService.loadPathsResourceDictionary(dictPaths)
70
71             testBaseConfigEnhancementAndValidation()
72             testVFWEnhancementAndValidation()
73             testGoldenEnhancementAndValidation()
74             testRemoteScriptsEnhancementAndValidation()
75             testCapabilityCliEnhancementAndValidation()
76         }
77     }
78
79     fun testBaseConfigEnhancementAndValidation() {
80         val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
81         testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
82     }
83
84     fun testVFWEnhancementAndValidation() {
85         val basePath = "./../../../../../components/model-catalog/blueprint-model/service-blueprint/vFW"
86         testComponentInvokeEnhancementAndValidation(basePath, "vFW-enhance")
87     }
88
89     fun testGoldenEnhancementAndValidation() {
90         val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
91         testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
92     }
93
94     fun testRemoteScriptsEnhancementAndValidation() {
95         val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
96         testComponentInvokeEnhancementAndValidation(basePath, "remote_scripts-enhance")
97     }
98
99     fun testCapabilityCliEnhancementAndValidation() {
100         val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/capability_cli"
101         testComponentInvokeEnhancementAndValidation(basePath, "capability_cli-enhance")
102     }
103
104     private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
105         runBlocking {
106             val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName)
107
108             deleteDir(targetPath)
109
110             val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
111             Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
112
113             // Validate the Generated BluePrints
114             val valid = bluePrintValidatorService.validateBluePrints(targetPath)
115             Assert.assertTrue("blueprint($basePath) validation failed ", valid)
116
117             // Enable this to get the enhanced zip file
118             //            val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip")
119             //            normalizedFile(targetPath).compress(compressFile)
120
121             deleteDir(targetPath)
122         }
123     }
124 }