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")
58 /** Load the Definitions */
59 val bluePrintDefinitions = bluePrintScriptsService
60 .scriptInstance<BluePrintDefinitions>(
62 "cba.scripts.ActivateBlueprintDefinitions", true
64 assertNotNull(bluePrintDefinitions, "failed to get blueprint definitions")
66 val serviceTemplate = bluePrintDefinitions.serviceTemplate()
67 assertNotNull(serviceTemplate, "failed to get service template")
69 val customDataType = bluePrintDefinitions.otherDefinition<DataType>("datatype-custom-datatype")
70 assertNotNull(customDataType, "failed to get custom definitions")
72 val instance = bluePrintScriptsService
73 .scriptInstance<BlueprintFunctionNode<String, String>>(
75 "cba.scripts.SampleBlueprintFunctionNode", false
77 assertNotNull(instance, "failed to get compiled instance")
79 val cachedInstance = bluePrintScriptsService
80 .scriptInstance<BlueprintFunctionNode<String, String>>(
82 "cba.scripts.SampleBlueprintFunctionNode", false
84 assertNotNull(cachedInstance, "failed to get cached compile instance")