summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-scripts/src/test
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <bs2796@att.com>2019-01-25 20:17:35 -0500
committerMuthuramalingam, Brinda Santh <bs2796@att.com>2019-01-28 12:47:04 -0500
commit6d6ebfa4b1b2c2c3ecf54d4476118c4a7b658625 (patch)
tree2366090eda7c963256ac7a7336b5bc6afddcd6ed /ms/controllerblueprints/modules/blueprint-scripts/src/test
parentfba373ca4ab06c9aa8adf86c0b6686fad7646af9 (diff)
blueprint scripting module
Change-Id: Ibe7602bdb6708d9adbe1aecd26eb14e24872f75d Issue-ID: CCSDK-941 Signed-off-by: Muthuramalingam, Brinda Santh <bs2796@att.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-scripts/src/test')
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BlueprintScriptingHostTest.kt88
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts55
-rw-r--r--ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts55
3 files changed, 198 insertions, 0 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BlueprintScriptingHostTest.kt b/ms/controllerblueprints/modules/blueprint-scripts/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BlueprintScriptingHostTest.kt
new file mode 100644
index 000000000..4b6f2a47d
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/scripts/BlueprintScriptingHostTest.kt
@@ -0,0 +1,88 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.scripts
+
+
+import org.apache.commons.io.FileUtils
+import org.junit.Ignore
+import org.junit.Test
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import java.io.File
+import kotlin.script.experimental.jvm.util.classpathFromClass
+import kotlin.script.experimental.jvm.util.classpathFromClassloader
+import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
+import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
+
+class BlueprintScriptingHostTest {
+
+ @Test
+ @Ignore
+ fun `test classpaths`() {
+
+ println(" *********** classpathFromClass *********** ")
+ classpathFromClass(BlueprintScriptingHostTest::class.java.classLoader,
+ BlueprintScriptingHostTest::class)!!
+ .forEach(::println)
+
+ println(" *********** classpathFromClassloader *********** ")
+ classpathFromClassloader(BlueprintScriptingHostTest::class.java.classLoader)!!
+ .forEach(::println)
+
+ println(" *********** classpathFromClasspathProperty *********** ")
+ classpathFromClasspathProperty()!!
+ .forEach(::println)
+ }
+
+ @Test
+ fun `test same script two folders`() {
+
+ FileUtils.forceMkdir(File("target/scripts1/"))
+ FileUtils.forceMkdir(File("target/scripts2/"))
+
+ val scriptSource1 = BluePrintSourceCode()
+ scriptSource1.moduleName = "blueprint-test-script"
+
+ scriptSource1.targetJarFile = File("target/scripts1/blueprint-script-generated.jar")
+ val sources1: MutableList<String> = arrayListOf()
+ sources1.add("src/test/resources/scripts1")
+ scriptSource1.blueprintKotlinSources = sources1
+
+ val scriptClassName = "Simple_cba\$SampleComponentFunction"
+
+ val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>()
+
+ val scriptEvaluator = BluePrintScriptEvaluator<BlueprintFunctionNode<String, String>>(scriptClassName)
+
+ val scriptSource2 = BluePrintSourceCode()
+ scriptSource2.moduleName = "blueprint-test-script"
+
+ scriptSource2.targetJarFile = File("target/scripts2/blueprint-script-generated.jar")
+ val sources2: MutableList<String> = arrayListOf()
+ sources2.add("src/test/resources/scripts2")
+ scriptSource2.blueprintKotlinSources = sources2
+
+ for (i in 1..2) {
+ val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource1, compilationConfiguration,
+ null)
+ }
+
+ for (i in 1..2) {
+ val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource2, compilationConfiguration,
+ null)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts
new file mode 100644
index 000000000..9f61c649f
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts1/simple.cba.kts
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import org.springframework.stereotype.Service
+
+@Service
+open class SampleComponentFunction : BlueprintFunctionNode<String, String> {
+
+ override fun getName(): String {
+ println("Printing Name....." + "sample".asJsonPrimitive())
+ return "my Name"
+ }
+
+ override fun prepareRequest(executionRequest: String): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun process(executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun prepareResponse(): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun apply(t: String): String {
+ return "Script 1 response - $t"
+ }
+}
+
+val blueprintFunction = SampleComponentFunction()
+
+val serviceTemplate = ServiceTemplate()
+
+println("Simple script printing....")
diff --git a/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts
new file mode 100644
index 000000000..845172548
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-scripts/src/test/resources/scripts2/simple.cba.kts
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import org.springframework.stereotype.Service
+
+@Service
+open class SampleComponentFunction : BlueprintFunctionNode<String, String> {
+
+ override fun getName(): String {
+ println("Printing Name....." + "sample".asJsonPrimitive())
+ return "my Name"
+ }
+
+ override fun prepareRequest(executionRequest: String): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun process(executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun prepareResponse(): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun apply(t: String): String {
+ return "Script 2 response - $t"
+ }
+}
+
+val blueprintFunction = SampleComponentFunction()
+
+val serviceTemplate = ServiceTemplate()
+
+println("Simple script printing....")