c29332d4fff6e785b8b8df5dc300facf2f4279c4
[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.core.utils
19
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Test
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData
23 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
24 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
25 import kotlin.test.assertEquals
26 import kotlin.test.assertNotNull
27 import kotlin.test.assertNull
28 import kotlin.test.assertTrue
29
30 class BluePrintMetadataUtilsTest {
31
32     @Test
33     fun testToscaMetaData() {
34
35         runBlocking {
36             val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
37
38             val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath)
39             assertNotNull(toscaMetaData, "Missing Tosca Definition Object")
40             assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version")
41             assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version")
42             assertNotNull(toscaMetaData.createdBy, "Missing Created by")
43             assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition")
44             assertNotNull(toscaMetaData.templateTags, "Missing Template Tags")
45         }
46     }
47
48     @Test
49     fun testKotlinBluePrintContext() {
50         val path = normalizedPathName("src/test/resources/compile")
51         val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(path)
52         assertNotNull(blueprintContext, "failed to get blueprint context")
53         assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
54         assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
55         assertNotNull(blueprintContext.otherDefinitions, "failed to get blueprint contextother definitions")
56
57         var cachePresent = BluePrintCompileCache.hasClassLoader(path)
58         assertTrue(cachePresent, "failed to generate cache key ($path)")
59
60         /** Cleaning Cache */
61         BluePrintCompileCache.cleanClassLoader(path)
62         cachePresent = BluePrintCompileCache.hasClassLoader(path)
63         assertTrue(!cachePresent, "failed to remove cache key ($path)")
64     }
65
66     @Test
67     fun environmentDataTest() {
68         val environmentPath = "./src/test/resources/environments"
69
70         val properties = BluePrintMetadataUtils.bluePrintEnvProperties(environmentPath)
71
72         assertNotNull(properties, "Could not read the properties")
73         assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.username"), "username1", "failed 1")
74         assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.password"), "password1", "failed 2")
75         assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.username"), "username2", "failed 3")
76         assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.password"), "password2", "failed 4")
77         assertNull(properties.getProperty("blueprintsprocessor.database.alt3.password"), "failed 5")
78     }
79 }