4b6f2a47d14959cf704d9f9c3a94f04b45f10465
[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.apps.controllerblueprints.scripts
18
19
20 import org.apache.commons.io.FileUtils
21 import org.junit.Ignore
22 import org.junit.Test
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
24 import java.io.File
25 import kotlin.script.experimental.jvm.util.classpathFromClass
26 import kotlin.script.experimental.jvm.util.classpathFromClassloader
27 import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
28 import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
29
30 class BlueprintScriptingHostTest {
31
32     @Test
33     @Ignore
34     fun `test classpaths`() {
35
36         println(" *********** classpathFromClass  *********** ")
37         classpathFromClass(BlueprintScriptingHostTest::class.java.classLoader,
38                 BlueprintScriptingHostTest::class)!!
39                 .forEach(::println)
40
41         println(" *********** classpathFromClassloader  *********** ")
42         classpathFromClassloader(BlueprintScriptingHostTest::class.java.classLoader)!!
43                 .forEach(::println)
44
45         println(" *********** classpathFromClasspathProperty  *********** ")
46         classpathFromClasspathProperty()!!
47                 .forEach(::println)
48     }
49
50     @Test
51     fun `test same script two folders`() {
52
53         FileUtils.forceMkdir(File("target/scripts1/"))
54         FileUtils.forceMkdir(File("target/scripts2/"))
55
56         val scriptSource1 = BluePrintSourceCode()
57         scriptSource1.moduleName = "blueprint-test-script"
58
59         scriptSource1.targetJarFile = File("target/scripts1/blueprint-script-generated.jar")
60         val sources1: MutableList<String> = arrayListOf()
61         sources1.add("src/test/resources/scripts1")
62         scriptSource1.blueprintKotlinSources = sources1
63
64         val scriptClassName = "Simple_cba\$SampleComponentFunction"
65
66         val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>()
67
68         val scriptEvaluator = BluePrintScriptEvaluator<BlueprintFunctionNode<String, String>>(scriptClassName)
69
70         val scriptSource2 = BluePrintSourceCode()
71         scriptSource2.moduleName = "blueprint-test-script"
72
73         scriptSource2.targetJarFile = File("target/scripts2/blueprint-script-generated.jar")
74         val sources2: MutableList<String> = arrayListOf()
75         sources2.add("src/test/resources/scripts2")
76         scriptSource2.blueprintKotlinSources = sources2
77
78         for (i in 1..2) {
79             val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource1, compilationConfiguration,
80                     null)
81         }
82
83         for (i in 1..2) {
84             val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource2, compilationConfiguration,
85                     null)
86         }
87     }
88 }