2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 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.scripts
20 import kotlinx.coroutines.runBlocking
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
23 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintDefinitions
24 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
25 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
26 import kotlin.script.experimental.jvm.util.classpathFromClass
27 import kotlin.script.experimental.jvm.util.classpathFromClassloader
28 import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
29 import kotlin.test.assertNotNull
31 class BluePrintScriptsServiceImplTest {
33 private fun viewClassPathInfo() {
35 println(" *********** classpathFromClass *********** ")
37 BluePrintScriptsServiceImplTest::class.java.classLoader,
38 BluePrintScriptsServiceImplTest::class
42 println(" *********** classpathFromClassloader *********** ")
43 classpathFromClassloader(BluePrintScriptsServiceImplTest::class.java.classLoader)!!
46 println(" *********** classpathFromClasspathProperty *********** ")
47 classpathFromClasspathProperty()!!
52 fun testCachedService() {
55 val bluePrintScriptsService = BluePrintScriptsServiceImpl()
57 val basePath = normalizedPathName("src/test/resources/compile")
59 /** Load the Definitions */
60 val bluePrintDefinitions = bluePrintScriptsService
61 .scriptInstance<BluePrintDefinitions>(
63 "cba.scripts.ActivateBlueprintDefinitions", true
65 assertNotNull(bluePrintDefinitions, "failed to get blueprint definitions")
67 val serviceTemplate = bluePrintDefinitions.serviceTemplate()
68 assertNotNull(serviceTemplate, "failed to get service template")
70 val customDataType = bluePrintDefinitions.otherDefinition<DataType>("datatype-custom-datatype")
71 assertNotNull(customDataType, "failed to get custom definitions")
73 val instance = bluePrintScriptsService
74 .scriptInstance<BlueprintFunctionNode<String, String>>(
76 "cba.scripts.SampleBlueprintFunctionNode", false
78 assertNotNull(instance, "failed to get compiled instance")
80 val cachedInstance = bluePrintScriptsService
81 .scriptInstance<BlueprintFunctionNode<String, String>>(
83 "cba.scripts.SampleBlueprintFunctionNode", false
85 assertNotNull(cachedInstance, "failed to get cached compile instance")