summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-core/src/test
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2019-07-18 19:13:00 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2019-07-19 10:50:25 -0400
commitb52a648f3c77a495539d64bba1e43fcbbdaa0364 (patch)
treed482c1d2a72d10d3a52d85ae5004325186533f90 /ms/controllerblueprints/modules/blueprint-core/src/test
parent086f23e7dbe0cc7df7105002628ee3e84cf29c76 (diff)
Improve script file accessing through cache.
Change-Id: If94e837975701dc7b2235c38acb46b3b883a424b Issue-ID: CCSDK-1503 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core/src/test')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt67
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt84
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/Scripts/kotlin/SampleBlueprintFunctionNode.kt (renamed from ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts)24
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/TOSCA-Metadata/TOSCA.meta7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts1/simple.cba.kts56
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts2/simple.cba.kts56
6 files changed, 97 insertions, 197 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt
new file mode 100644
index 000000000..9d4ef69bb
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt
@@ -0,0 +1,67 @@
+/*
+ * 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.cds.controllerblueprints.core.scripts
+
+
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
+import kotlin.script.experimental.jvm.util.classpathFromClass
+import kotlin.script.experimental.jvm.util.classpathFromClassloader
+import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty
+import kotlin.test.assertNotNull
+
+class BluePrintScriptsServiceImplTest {
+
+ private fun viewClassPathInfo() {
+
+ println(" *********** classpathFromClass *********** ")
+ classpathFromClass(BluePrintScriptsServiceImplTest::class.java.classLoader,
+ BluePrintScriptsServiceImplTest::class)!!
+ .forEach(::println)
+
+ println(" *********** classpathFromClassloader *********** ")
+ classpathFromClassloader(BluePrintScriptsServiceImplTest::class.java.classLoader)!!
+ .forEach(::println)
+
+ println(" *********** classpathFromClasspathProperty *********** ")
+ classpathFromClasspathProperty()!!
+ .forEach(::println)
+ }
+
+ @Test
+ fun testCachedService() {
+ runBlocking {
+
+ val bluePrintScriptsService = BluePrintScriptsServiceImpl()
+
+ val basePath = normalizedPathName("src/test/resources/compile")
+
+ val instance = bluePrintScriptsService
+ .scriptInstance<BlueprintFunctionNode<String, String>>(basePath,
+ "cba.scripts.SampleBlueprintFunctionNode", true)
+ assertNotNull(instance, "failed to get compiled instance")
+
+ val cachedInstance = bluePrintScriptsService
+ .scriptInstance<BlueprintFunctionNode<String, String>>(basePath,
+ "cba.scripts.SampleBlueprintFunctionNode", false)
+ assertNotNull(cachedInstance, "failed to get cached compile instance")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt
deleted file mode 100644
index 2288d62c8..000000000
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.cds.controllerblueprints.core.scripts
-
-
-import org.apache.commons.io.FileUtils
-import org.junit.Test
-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 {
-
- private fun viewClassPathInfo() {
-
- 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(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-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/Scripts/kotlin/SampleBlueprintFunctionNode.kt
index 439351b05..aa77bc30b 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts/SampleBlueprintFunctionNode.kts
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/Scripts/kotlin/SampleBlueprintFunctionNode.kt
@@ -14,9 +14,11 @@
* limitations under the License.
*/
+package cba.scripts
+
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
-open class SampleBlueprintFunctionNode : BlueprintFunctionNode<String, String>{
+open class SampleBlueprintFunctionNode : BlueprintFunctionNode<String, String> {
override fun getName(): String {
return "Kotlin-Script-Function-Node"
@@ -41,4 +43,24 @@ open class SampleBlueprintFunctionNode : BlueprintFunctionNode<String, String>{
override fun apply(t: String): String {
return "$t-status"
}
+
+ override suspend fun prepareRequestNB(executionRequest: String): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override suspend fun processNB(executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: String) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override suspend fun prepareResponseNB(): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override suspend fun applyNB(t: String): String {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/TOSCA-Metadata/TOSCA.meta b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/TOSCA-Metadata/TOSCA.meta
new file mode 100644
index 000000000..b1ffabd13
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/compile/TOSCA-Metadata/TOSCA.meta
@@ -0,0 +1,7 @@
+TOSCA-Meta-File-Version: 1.0.0
+CSAR-Version: 1.0
+Created-By: Brinda Santh <brindasanth@in.ibm.com>
+Entry-Definitions: cba.scripts.ActivateBlueprintDefinitions.kt
+Template-Tags: Brinda Santh, activation-blueprint
+Template-Name: activate-blueprint
+Template-Version: 1.0.0
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts1/simple.cba.kts b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts1/simple.cba.kts
deleted file mode 100644
index 4fffda051..000000000
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts1/simple.cba.kts
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2019 IBM.
- *
- * 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.cds.controllerblueprints.core.asJsonPrimitive
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
-import org.onap.ccsdk.cds.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 suspend fun prepareRequestNB(executionRequest: String): String {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun processNB(executionRequest: String) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: String) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun prepareResponseNB(): String {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun applyNB(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-core/src/test/resources/scripts2/simple.cba.kts b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts2/simple.cba.kts
deleted file mode 100644
index 4ba56c491..000000000
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/scripts2/simple.cba.kts
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2019 IBM.
- *
- * 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.cds.controllerblueprints.core.asJsonPrimitive
-import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
-import org.onap.ccsdk.cds.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 suspend fun prepareRequestNB(executionRequest: String): String {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun processNB(executionRequest: String) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: String) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun prepareResponseNB(): String {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override suspend fun applyNB(t: String): String {
- return "Script 2 response - $t"
- }
-}
-
-val blueprintFunction = SampleComponentFunction()
-
-val serviceTemplate = ServiceTemplate()
-
-println("Simple script printing....")