8d32413f24270a083766f4e09724785e5a7c4e91
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
18
19 import kotlinx.coroutines.runBlocking
20 import org.junit.Assert
21 import org.junit.Before
22 import org.junit.Test
23 import org.junit.runner.RunWith
24 import org.onap.ccsdk.apps.controllerblueprints.TestApplication
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService
26 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
27 import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService
28 import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.test.context.ContextConfiguration
31 import org.springframework.test.context.TestPropertySource
32 import org.springframework.test.context.junit4.SpringRunner
33 import java.nio.file.Paths
34
35 @RunWith(SpringRunner::class)
36 @ContextConfiguration(classes = arrayOf(TestApplication::class))
37 @TestPropertySource(locations = arrayOf("classpath:application.properties"))
38 class BluePrintEnhancerServiceImplTest {
39
40     @Autowired
41     private val modelTypeLoadService: ModelTypeLoadService? = null
42
43     @Autowired
44     private val resourceDictionaryLoadService: ResourceDictionaryLoadService? = null
45
46     @Autowired
47     private val bluePrintEnhancerService: BluePrintEnhancerService? = null
48
49     @Autowired
50     private val bluePrintValidatorService: BluePrintValidatorService? = null
51
52     @Before
53     fun init() {
54         runBlocking {
55             modelTypeLoadService!!.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type")
56             resourceDictionaryLoadService!!.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary")
57         }
58     }
59
60     @Test
61     @Throws(Exception::class)
62     fun testEnhancementAndValidation() {
63
64         val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
65
66         val targetPath = Paths.get("target", "bp-enhance").toUri().path
67
68         val bluePrintContext = bluePrintEnhancerService!!.enhance(basePath, targetPath)
69         Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
70
71         // Validate the Generated BluePrints
72         val valid = bluePrintValidatorService!!.validateBluePrints(targetPath)
73         Assert.assertTrue("blueprint validation failed ", valid)
74     }
75 }