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.controllerblueprints.core.utils
20 import kotlinx.coroutines.runBlocking
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
30 class BluePrintMetadataUtilsTest {
33 fun testToscaMetaData() {
36 val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
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")
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")
57 var cachePresent = BluePrintCompileCache.hasClassLoader(path)
58 assertTrue(cachePresent, "failed to generate cache key ($path)")
61 BluePrintCompileCache.cleanClassLoader(path)
62 cachePresent = BluePrintCompileCache.hasClassLoader(path)
63 assertTrue(!cachePresent, "failed to remove cache key ($path)")
67 fun environmentDataTest() {
68 val environmentPath = "./src/test/resources/environments"
70 val properties = BluePrintMetadataUtils.bluePrintEnvProperties(environmentPath)
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")