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.designer.api.DesignerApiTestConfiguration
25 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.ModelTypeLoadService
26 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.ResourceDictionaryLoadService
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.normalizedPathName
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
36 @RunWith(SpringRunner::class)
37 @ContextConfiguration(
38 classes = [DesignerApiTestConfiguration::class]
40 @TestPropertySource(locations = ["classpath:application-test.properties"])
41 class BluePrintEnhancerServiceImplTest {
44 lateinit var modelTypeLoadService: ModelTypeLoadService
47 lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService
50 lateinit var bluePrintEnhancerService: BluePrintEnhancerService
53 lateinit var bluePrintValidatorService: BluePrintValidatorService
56 @Throws(Exception::class)
57 fun testEnhancementAndValidation() {
60 modelTypeLoadService.loadPathModelType("./../../../../../components/model-catalog/definition-type/starter-type")
62 val dictPaths: MutableList<String> = arrayListOf()
63 dictPaths.add("./../../../../../components/model-catalog/resource-dictionary/starter-dictionary")
64 dictPaths.add("./../../../../../components/model-catalog/resource-dictionary/test-dictionary")
65 resourceDictionaryLoadService.loadPathsResourceDictionary(dictPaths)
67 testBaseConfigEnhancementAndValidation()
68 testGoldenEnhancementAndValidation()
69 testRemoteScriptsEnhancementAndValidation()
70 testCapabilityCliEnhancementAndValidation()
74 private fun testBaseConfigEnhancementAndValidation() {
75 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
76 testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
79 private fun testGoldenEnhancementAndValidation() {
80 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
81 testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
84 private fun testRemoteScriptsEnhancementAndValidation() {
85 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
86 testComponentInvokeEnhancementAndValidation(basePath, "remote_scripts-enhance")
89 private fun testCapabilityCliEnhancementAndValidation() {
90 val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/capability_cli"
91 testComponentInvokeEnhancementAndValidation(basePath, "capability_cli-enhance")
94 private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
96 val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName)
100 val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
101 Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
103 // Validate the Generated BluePrints
104 val valid = bluePrintValidatorService.validateBluePrints(targetPath)
105 Assert.assertTrue("blueprint($basePath) validation failed ", valid)
107 // Enable this to get the enhanced zip file
108 // val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip")
109 // normalizedFile(targetPath).compress(compressFile)
111 deleteDir(targetPath)