Removed redundant timeout handling for executeCommand
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / test / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / scripts / BlueprintScriptsServiceImplTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.cds.controllerblueprints.core.scripts
19
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Test
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
30
31 class BlueprintScriptsServiceImplTest {
32
33     private fun viewClassPathInfo() {
34
35         println(" *********** classpathFromClass  *********** ")
36         classpathFromClass(
37             BlueprintScriptsServiceImplTest::class.java.classLoader,
38             BlueprintScriptsServiceImplTest::class
39         )!!
40             .forEach(::println)
41
42         println(" *********** classpathFromClassloader  *********** ")
43         classpathFromClassloader(BlueprintScriptsServiceImplTest::class.java.classLoader)!!
44             .forEach(::println)
45
46         println(" *********** classpathFromClasspathProperty  *********** ")
47         classpathFromClasspathProperty()!!
48             .forEach(::println)
49     }
50
51     @Test
52     fun testCachedService() {
53         runBlocking {
54
55             val bluePrintScriptsService = BlueprintScriptsServiceImpl()
56
57             val basePath = normalizedPathName("src/test/resources/compile")
58
59             /** Load the Definitions */
60             val bluePrintDefinitions = bluePrintScriptsService
61                 .scriptInstance<BlueprintDefinitions>(
62                     basePath,
63                     "cba.scripts.ActivateBlueprintDefinitions", true
64                 )
65             assertNotNull(bluePrintDefinitions, "failed to get blueprint definitions")
66
67             val serviceTemplate = bluePrintDefinitions.serviceTemplate()
68             assertNotNull(serviceTemplate, "failed to get service template")
69
70             val customDataType = bluePrintDefinitions.otherDefinition<DataType>("datatype-custom-datatype")
71             assertNotNull(customDataType, "failed to get custom definitions")
72
73             val instance = bluePrintScriptsService
74                 .scriptInstance<BlueprintFunctionNode<String, String>>(
75                     basePath,
76                     "cba.scripts.SampleBlueprintFunctionNode", false
77                 )
78             assertNotNull(instance, "failed to get compiled instance")
79
80             val cachedInstance = bluePrintScriptsService
81                 .scriptInstance<BlueprintFunctionNode<String, String>>(
82                     basePath,
83                     "cba.scripts.SampleBlueprintFunctionNode", false
84                 )
85             assertNotNull(cachedInstance, "failed to get cached compile instance")
86         }
87     }
88 }