summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-javascript/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-javascript/src/test')
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java24
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java29
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java16
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js2
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js2
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js2
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json2
7 files changed, 40 insertions, 37 deletions
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
index 5ccbd255f..8be79558f 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
@@ -23,7 +23,6 @@ package org.onap.policy.apex.plugins.executor.javascript;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
@@ -94,31 +93,32 @@ public class JavascriptStateFinalizerExecutorTest {
jsfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
stateFinalizerLogic.setLogic("return false");
- jsfe.prepare();
+ assertThatThrownBy(() -> {
+ jsfe.prepare();
+ }).hasMessage("logic failed to compile for NULL:0.0.0:NULL:NULL "
+ + "with message: invalid return (NULL:0.0.0:NULL:NULL#1)");
Map<String, Object> incomingParameters1 = new HashMap<>();
assertThatThrownBy(() -> {
jsfe.execute(-1, new Properties(), incomingParameters1);
- fail("test should throw an exception here");
- }).hasMessage("execute: logic failed to run for \"NULL:0.0.0:NULL:NULL\"");
+ }).hasMessage("logic failed to compile for NULL:0.0.0:NULL:NULL "
+ + "with message: invalid return (NULL:0.0.0:NULL:NULL#1)");
stateFinalizerLogic.setLogic("java.lang.String");
jsfe.prepare();
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- stateFinalizerLogic.setLogic(
- "if(executor.executionId==-1)" + "{\r\n" + "var returnValueType = Java.type(\"java.lang.Boolean\");"
- + "var returnValue = new returnValueType(false); }\n" + "else{\n"
- + "executor.setSelectedStateOutputName(\"SelectedOutputIsMe\");\n"
- + "var returnValueType = Java.type(\"java.lang.Boolean\");\n" + "\n"
- + "var returnValue = new returnValueType(true);}");
+ stateFinalizerLogic.setLogic("if(executor.executionId==-1)" + "{\r\n"
+ + "var returnValueType = java.lang.Boolean;" + "var returnValue = new returnValueType(false); }\n"
+ + "else{\n" + "executor.setSelectedStateOutputName(\"SelectedOutputIsMe\");\n"
+ + "var returnValueType = java.lang.Boolean;\n" + "\n"
+ + "var returnValue = new returnValueType(true);} true;");
assertThatThrownBy(() -> {
jsfe.prepare();
jsfe.execute(-1, new Properties(), event);
- }).hasMessage("execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" "
- + "on finalizer logic NULL:0.0.0:NULL:NULL");
+ }).hasMessage("execute-post: state finalizer logic \"NULL:0.0.0:NULL:NULL\" did not select an output state");
state.getStateOutputs().put("SelectedOutputIsMe", null);
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
index 786cebcc3..c327ebb4d 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
@@ -105,41 +105,38 @@ public class JavascriptTaskExecutorTest {
jte.prepare();
}).isInstanceOf(NullPointerException.class);
- AxTask task = new AxTask();
+ AxTask task = new AxTask(new AxArtifactKey("TestTask:0.0.1"));
final ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel());
jte.setContext(null, task, internalContext);
task.getTaskLogic().setLogic("return boolean;");
- jte.prepare();
- Map<String, Object> incomingParameters2 = new HashMap<>();
assertThatThrownBy(() -> {
- jte.execute(-1, new Properties(), incomingParameters2);
- }).hasMessage("execute: logic failed to run for \"NULL:0.0.0\"");
+ jte.prepare();
+ jte.execute(-1, new Properties(), null);
+ }).hasMessage("logic failed to compile for TestTask:0.0.1 with message: invalid return (TestTask:0.0.1#1)");
task.getTaskLogic().setLogic("var x = 5;");
- jte.prepare();
+ jte.prepare();
assertThatThrownBy(() -> {
jte.execute(-1, new Properties(), null);
}).isInstanceOf(NullPointerException.class);
+ jte.cleanUp();
- Map<String, Object> incomingParameters = new HashMap<>();
- assertThatThrownBy(() -> {
- jte.execute(-1, new Properties(), incomingParameters);
- }).hasMessage("execute: logic failed to set a return value for \"NULL:0.0.0\"");
+ task.getTaskLogic().setLogic("var returnValue = false;\nreturnValue;");
- task.getTaskLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\n"
- + "var returnValue = new returnValueType(false); ");
+ Map<String, Object> incomingParameters = new HashMap<>();
assertThatThrownBy(() -> {
jte.prepare();
jte.execute(-1, new Properties(), incomingParameters);
- }).hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0");
+ }).hasMessage("execute-post: task logic execution failure on task \"TestTask\" in model NULL:0.0.0");
- task.getTaskLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n"
- + "var returnValue = new returnValueType(true); ");
+ jte.cleanUp();
+
+ task.getTaskLogic().setLogic("var returnValue = true;\nreturnValue;");
jte.prepare();
Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
@@ -176,11 +173,13 @@ public class JavascriptTaskExecutorTest {
jte.prepare();
jte.execute(-1, new Properties(), incomingParameters);
+ jte.cleanUp();
task.getTaskLogic().setLogic(TextFileUtils.getTextFileAsString("src/test/resources/javascript/TestLogic01.js"));
jte.prepare();
Map<String, Object> outcomingParameters = jte.execute(-1, new Properties(), incomingParameters);
+ jte.cleanUp();
assertEquals("returnVal0", outcomingParameters.get("par0"));
assertEquals("returnVal1", outcomingParameters.get("par1"));
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
index abbcd19b7..3acf132dd 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
@@ -80,14 +80,17 @@ public class JavascriptTaskSelectExecutorTest {
AxState state = new AxState();
ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel());
jtse.setContext(null, state, internalContext);
- jtse.prepare();
+
+ assertThatThrownBy(() -> {
+ jtse.prepare();
+ }).hasMessage("no logic specified for NULL:0.0.0:NULL:NULL");
AxEvent axEvent1 = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event1 = new EnEvent(axEvent1);
assertThatThrownBy(() -> {
jtse.execute(-1, new Properties(), event1);
- }).hasMessage("execute: logic failed to set a return value for \"NULL:0.0.0:NULL:NULL\"");
+ }).hasMessage("no logic specified for NULL:0.0.0:NULL:NULL");
state.getTaskSelectionLogic().setLogic("java.lang.String");
jtse.prepare();
@@ -101,18 +104,17 @@ public class JavascriptTaskSelectExecutorTest {
assertThatThrownBy(() -> {
jtse.execute(-1, new Properties(), event);
- }).hasMessage("execute: logic failed to set a return value for \"NULL:0.0.0:NULL:NULL\"");
+ }).hasMessage(
+ "execute: logic for NULL:0.0.0:NULL:NULL returned a non-boolean value [JavaClass java.lang.String]");
- state.getTaskSelectionLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n"
- + "var returnValue = new returnValueType(false); ");
+ state.getTaskSelectionLogic().setLogic("var x=1;\n" + "false; ");
assertThatThrownBy(() -> {
jtse.prepare();
jtse.execute(-1, new Properties(), event);
}).hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
- state.getTaskSelectionLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n"
- + "var returnValue = new returnValueType(true); ");
+ state.getTaskSelectionLogic().setLogic("var x = 1\n" + "true; ");
jtse.prepare();
AxArtifactKey taskKey = jtse.execute(0, new Properties(), event);
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js
index a7bb81666..d5427582a 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js
@@ -32,4 +32,4 @@ executor.outFields.put("intPar", intParBy2);
executor.logger.info("outgoing value: " + executor.outFields.get("intPar").toString());
-var returnValue = executor.isTrue; \ No newline at end of file
+executor.isTrue; \ No newline at end of file
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js
index 8b3bff425..0c15249d2 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js
@@ -19,3 +19,5 @@
*/
var x = 1;
var returnValue = true;
+
+returnValue; \ No newline at end of file
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js
index 7c8a44962..83c3060bd 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js
@@ -30,4 +30,4 @@ executor.outFields.put("par1", "returnVal1");
executor.logger.info(executor.outFields.get("par0"));
executor.logger.info(executor.outFields.get("par1"));
-var returnValue = executor.isTrue;
+true;
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json
index 79f08e279..d987a0c78 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json
@@ -460,7 +460,7 @@
"taskLogic" : {
"key" : "TaskLogic",
"logicFlavour" : "JAVASCRIPT",
- "logic" : "executor.logger.debug(executor.subject.getId());\nvar gc = executor.getContextAlbum(\"BasicContextAlbum\");\nexecutor.logger.debug(gc.getName());\nexecutor.logger.debug(\"incoming value: \" + executor.inFields.get(\"intPar\").toString());\n\nvar intPar = executor.inFields.get(\"intPar\");\n\nexecutor.logger.debug(\"read value: \" + intPar.toString());\n\nvar intParBy2 = intPar * 2;\n\nexecutor.outFields.put(\"intPar\", intParBy2);\n\nexecutor.logger.debug(\"outgoing value: \" + executor.outFields.get(\"intPar\").toString());\n\nvar returnValue = executor.isTrue;"
+ "logic" : "executor.logger.debug(executor.subject.getId());\nvar gc = executor.getContextAlbum(\"BasicContextAlbum\");\nexecutor.logger.debug(gc.getName());\nexecutor.logger.debug(\"incoming value: \" + executor.inFields.get(\"intPar\").toString());\n\nvar intPar = executor.inFields.get(\"intPar\");\n\nexecutor.logger.debug(\"read value: \" + intPar.toString());\n\nvar intParBy2 = intPar * 2;\n\nexecutor.outFields.put(\"intPar\", intParBy2);\n\nexecutor.logger.debug(\"outgoing value: \" + executor.outFields.get(\"intPar\").toString());\n\ntrue;"
}
}
} ]