2 * Copyright © 2017-2018 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.controllerblueprints.scripts
20 import org.apache.commons.io.FileUtils
23 import kotlin.script.experimental.jvm.util.classpathFromClass
24 import kotlin.script.experimental.jvm.util.classpathFromClassloader
25 import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
26 import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
28 class BlueprintScriptingHostTest {
30 private fun viewClassPathInfo() {
32 println(" *********** classpathFromClass *********** ")
33 classpathFromClass(BlueprintScriptingHostTest::class.java.classLoader,
34 BlueprintScriptingHostTest::class)!!
37 println(" *********** classpathFromClassloader *********** ")
38 classpathFromClassloader(BlueprintScriptingHostTest::class.java.classLoader)!!
41 println(" *********** classpathFromClasspathProperty *********** ")
42 classpathFromClasspathProperty()!!
47 fun `test same script two folders`() {
49 FileUtils.forceMkdir(File("target/scripts1/"))
50 FileUtils.forceMkdir(File("target/scripts2/"))
52 val scriptSource1 = BluePrintSourceCode()
53 scriptSource1.moduleName = "blueprint-test-script"
55 scriptSource1.targetJarFile = File("target/scripts1/blueprint-script-generated.jar")
56 val sources1: MutableList<String> = arrayListOf()
57 sources1.add("src/test/resources/scripts1")
58 scriptSource1.blueprintKotlinSources = sources1
60 val scriptClassName = "Simple_cba\$SampleComponentFunction"
62 val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>()
64 val scriptEvaluator = BluePrintScriptEvaluator(scriptClassName)
66 val scriptSource2 = BluePrintSourceCode()
67 scriptSource2.moduleName = "blueprint-test-script"
69 scriptSource2.targetJarFile = File("target/scripts2/blueprint-script-generated.jar")
70 val sources2: MutableList<String> = arrayListOf()
71 sources2.add("src/test/resources/scripts2")
72 scriptSource2.blueprintKotlinSources = sources2
75 val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource1, compilationConfiguration,
80 val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource2, compilationConfiguration,