9d4ef69bb116364a6e17778601777cbe0b5041a0
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.core.scripts
18
19
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Test
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
23 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
24 import kotlin.script.experimental.jvm.util.classpathFromClass
25 import kotlin.script.experimental.jvm.util.classpathFromClassloader
26 import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
27 import kotlin.test.assertNotNull
28
29 class BluePrintScriptsServiceImplTest {
30
31     private fun viewClassPathInfo() {
32
33         println(" *********** classpathFromClass  *********** ")
34         classpathFromClass(BluePrintScriptsServiceImplTest::class.java.classLoader,
35                 BluePrintScriptsServiceImplTest::class)!!
36                 .forEach(::println)
37
38         println(" *********** classpathFromClassloader  *********** ")
39         classpathFromClassloader(BluePrintScriptsServiceImplTest::class.java.classLoader)!!
40                 .forEach(::println)
41
42         println(" *********** classpathFromClasspathProperty  *********** ")
43         classpathFromClasspathProperty()!!
44                 .forEach(::println)
45     }
46
47     @Test
48     fun testCachedService() {
49         runBlocking {
50
51             val bluePrintScriptsService = BluePrintScriptsServiceImpl()
52
53             val basePath = normalizedPathName("src/test/resources/compile")
54
55             val instance = bluePrintScriptsService
56                     .scriptInstance<BlueprintFunctionNode<String, String>>(basePath,
57                             "cba.scripts.SampleBlueprintFunctionNode", true)
58             assertNotNull(instance, "failed to get compiled instance")
59
60             val cachedInstance = bluePrintScriptsService
61                     .scriptInstance<BlueprintFunctionNode<String, String>>(basePath,
62                             "cba.scripts.SampleBlueprintFunctionNode", false)
63             assertNotNull(cachedInstance, "failed to get cached compile instance")
64         }
65     }
66
67 }