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.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
31 class BluePrintMetadataUtilsTest {
34 fun testToscaMetaData() {
37 val basePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG
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")
50 fun testKotlinBluePrintContext() {
51 val path = normalizedPathName("src/test/resources/compile")
52 val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(path)
53 assertNotNull(blueprintContext, "failed to get blueprint context")
54 assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
55 assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
56 assertNotNull(blueprintContext.otherDefinitions, "failed to get blueprint contextother definitions")
58 var cachePresent = BluePrintCompileCache.hasClassLoader(path)
59 assertTrue(cachePresent, "failed to generate cache key ($path)")
62 BluePrintCompileCache.cleanClassLoader(path)
63 cachePresent = BluePrintCompileCache.hasClassLoader(path)
64 assertTrue(!cachePresent, "failed to remove cache key ($path)")
68 fun environmentDataTest() {
69 val environmentPath = "./src/test/resources/environments"
71 val properties = BluePrintMetadataUtils.bluePrintEnvProperties(environmentPath)
73 assertNotNull(properties, "Could not read the properties")
74 assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.username"), "username1", "failed 1")
75 assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.password"), "password1", "failed 2")
76 assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.username"), "username2", "failed 3")
77 assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.password"), "password2", "failed 4")
78 assertNull(properties.getProperty("blueprintsprocessor.database.alt3.password"), "failed 5")