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