2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 IBM.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Assert
23 import org.junit.runner.RunWith
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
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.controllerblueprints.core.deleteDir
29 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService
30 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
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
39 @RunWith(SpringRunner::class)
40 @ContextConfiguration(classes = [DesignerApiTestConfiguration::class,
41 BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class])
42 @TestPropertySource(locations = ["classpath:application-test.properties"])
43 class BluePrintEnhancerServiceImplTest {
46 lateinit var modelTypeLoadService: ModelTypeLoadService
49 lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService
52 lateinit var bluePrintEnhancerService: BluePrintEnhancerService
55 lateinit var bluePrintValidatorService: BluePrintValidatorService
59 @Throws(Exception::class)
60 fun testEnhancementAndValidation() {
63 modelTypeLoadService.loadPathModelType("./../../../../../components/model-catalog/definition-type/starter-type")
65 val dictPaths: MutableList<String> = arrayListOf()
66 dictPaths.add("./../../../../../components/model-catalog/resource-dictionary/starter-dictionary")
67 dictPaths.add("./../../../../../components/model-catalog/resource-dictionary/test-dictionary")
68 resourceDictionaryLoadService.loadPathsResourceDictionary(dictPaths)
70 testBaseConfigEnhancementAndValidation()
71 testVFWEnhancementAndValidation()
72 testGoldenEnhancementAndValidation()
73 testRemoteScriptsEnhancementAndValidation()
74 testCapabilityCliEnhancementAndValidation()
78 fun testBaseConfigEnhancementAndValidation() {
79 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
80 testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
83 fun testVFWEnhancementAndValidation() {
84 val basePath = "./../../../../../components/model-catalog/blueprint-model/service-blueprint/vFW"
85 testComponentInvokeEnhancementAndValidation(basePath, "vFW-enhance")
88 fun testGoldenEnhancementAndValidation() {
89 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
90 testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
93 fun testRemoteScriptsEnhancementAndValidation() {
94 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
95 testComponentInvokeEnhancementAndValidation(basePath, "remote_scripts-enhance")
99 fun testCapabilityCliEnhancementAndValidation() {
100 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/capability_cli"
101 testComponentInvokeEnhancementAndValidation(basePath, "capability_cli-enhance")
104 private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
106 val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName)
108 deleteDir(targetPath)
110 val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
111 Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
113 // Validate the Generated BluePrints
114 val valid = bluePrintValidatorService.validateBluePrints(targetPath)
115 Assert.assertTrue("blueprint($basePath) validation failed ", valid)
117 // Enable this to get the enhanced zip file
118 // val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip")
119 // normalizedFile(targetPath).compress(compressFile)
121 deleteDir(targetPath)