aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-javascript/src/main
diff options
context:
space:
mode:
authorHengye <yehui.wang@est.tech>2019-03-06 05:14:13 +0000
committerHengye <yehui.wang@est.tech>2019-03-06 05:14:13 +0000
commit9ba1a8480beefee2f6c1255b65fa9739e103738e (patch)
tree0aff0a722f7262559822a99fd8bf8fbbc0cd57b4 /plugins/plugins-executor/plugins-executor-javascript/src/main
parentf0872b20425c66adeb14487c8f9e1c79f6bd3ddf (diff)
Increase test coverage for plugins-executor-js
Add junit test cases into apex-pdp/plugins/plugins-executor-javascript Issue-ID: POLICY-1523 Change-Id: Ie8017be2f7507fdb641a4020e13152c656cadf04 Signed-off-by: Hengye <yehui.wang@est.tech>
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-javascript/src/main')
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java17
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java35
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java50
3 files changed, 32 insertions, 70 deletions
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java
index bc3062d13..2e32bb626 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java
@@ -21,13 +21,11 @@
package org.onap.policy.apex.plugins.executor.javascript;
import java.util.Map;
-
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
-
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
@@ -35,8 +33,8 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The Class JavascriptStateFinalizerExecutor is the state finalizer executor for state finalizer logic written in
- * Javascript It is unlikely that this is thread safe.
+ * The Class JavascriptStateFinalizerExecutor is the state finalizer executor for state finalizer
+ * logic written in Javascript It is unlikely that this is thread safe.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -100,17 +98,10 @@ public class JavascriptStateFinalizerExecutor extends StateFinalizerExecutor {
+ getSubject().getKey().getId() + "\"", e);
}
- returnValue = (boolean) engine.get("returnValue");
-
// Do the execution post work
- executePost(returnValue);
+ executePost((boolean) engine.get("returnValue"));
- // Send back the return event
- if (returnValue) {
- return getOutgoing();
- } else {
- return null;
- }
+ return getOutgoing();
}
/**
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java
index 14e4ba384..af6db1107 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java
@@ -21,13 +21,11 @@
package org.onap.policy.apex.plugins.executor.javascript;
import java.util.Map;
-
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
-
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.executor.TaskExecutor;
import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
@@ -35,8 +33,8 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The Class JavascriptTaskExecutor is the task executor for task logic written in Javascript It is unlikely that this
- * is thread safe.
+ * The Class JavascriptTaskExecutor is the task executor for task logic written in Javascript It is
+ * unlikely that this is thread safe.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -98,31 +96,18 @@ public class JavascriptTaskExecutor extends TaskExecutor {
"task logic failed to run for task \"" + getSubject().getKey().getId() + "\"", e);
}
- try {
- final Object ret = engine.get("returnValue");
- if (ret == null) {
- LOGGER.error("execute: task logic failed to set a return value for task \""
- + getSubject().getKey().getId() + "\"");
- throw new StateMachineException("execute: task logic failed to set a return value for task \""
- + getSubject().getKey().getId() + "\"");
- }
- returnValue = (Boolean) ret;
- } catch (NullPointerException | ClassCastException e) {
- LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
- + getSubject().getKey().getId() + "\"", e);
- throw new StateMachineException("execute: task selection logic failed to set a return value for state \""
- + getSubject().getKey().getId() + "\"", e);
+ final Object ret = engine.get("returnValue");
+ if (ret == null) {
+ LOGGER.error("execute: task logic failed to set a return value for task \"" + getSubject().getKey().getId()
+ + "\"");
+ throw new StateMachineException("execute: task logic failed to set a return value for task \""
+ + getSubject().getKey().getId() + "\"");
}
// Do the execution post work
- executePost(returnValue);
+ executePost((Boolean) ret);
- // Send back the return event
- if (returnValue) {
- return getOutgoing();
- } else {
- return null;
- }
+ return getOutgoing();
}
/**
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java
index adeb73f88..80b005f1a 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java
@@ -25,7 +25,6 @@ import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
-
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor;
@@ -35,8 +34,8 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The Class JavascriptTaskSelectExecutor is the task selection executor for task selection logic written in Javascript
- * It is unlikely that this is thread safe.
+ * The Class JavascriptTaskSelectExecutor is the task selection executor for task selection logic
+ * written in Javascript It is unlikely that this is thread safe.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -46,7 +45,7 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor {
// Recurring string constants
private static final String TSL_FAILED_PREFIX =
- "execute: task selection logic failed to set a return value for state \"";
+ "execute: task selection logic failed to set a return value for state \"";
// Javascript engine
private ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
@@ -65,9 +64,9 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor {
compiled = ((Compilable) engine).compile(getSubject().getTaskSelectionLogic().getLogic());
} catch (final ScriptException e) {
LOGGER.error("execute: task selection logic failed to compile for state \"" + getSubject().getKey().getId()
- + "\"");
- throw new StateMachineException("task selection logic failed to compile for state \""
- + getSubject().getKey().getId() + "\"", e);
+ + "\"");
+ throw new StateMachineException(
+ "task selection logic failed to compile for state \"" + getSubject().getKey().getId() + "\"", e);
}
}
@@ -83,7 +82,7 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor {
*/
@Override
public AxArtifactKey execute(final long executionId, final EnEvent incomingEvent)
- throws StateMachineException, ContextException {
+ throws StateMachineException, ContextException {
// Do execution pre work
executePre(executionId, incomingEvent);
@@ -99,35 +98,22 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor {
compiled.eval(engine.getContext());
}
} catch (final ScriptException e) {
- LOGGER.error("execute: task selection logic failed to run for state \"" + getSubject().getKey().getId()
- + "\"");
+ LOGGER.error(
+ "execute: task selection logic failed to run for state \"" + getSubject().getKey().getId() + "\"");
throw new StateMachineException(
- "task selection logic failed to run for state \"" + getSubject().getKey().getId() + "\"",
- e);
+ "task selection logic failed to run for state \"" + getSubject().getKey().getId() + "\"", e);
}
- try {
- final Object ret = engine.get("returnValue");
- if (ret == null) {
- LOGGER.error(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"");
- throw new StateMachineException(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"");
- }
- returnValue = (Boolean) ret;
- } catch (NullPointerException | ClassCastException e) {
- LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
- + getSubject().getKey().getId() + "\"", e);
- throw new StateMachineException(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"", e);
+ final Object ret = engine.get("returnValue");
+ if (ret == null) {
+ LOGGER.error(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"");
+ throw new StateMachineException(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"");
}
// Do the execution post work
- executePost(returnValue);
+ executePost((Boolean) ret);
- // Send back the return event
- if (returnValue) {
- return getOutgoing();
- } else {
- return null;
- }
+ return getOutgoing();
}
/**
@@ -138,8 +124,8 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor {
@Override
public void cleanUp() throws StateMachineException {
LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + ","
- + getSubject().getTaskSelectionLogic().getLogicFlavour() + ","
- + getSubject().getTaskSelectionLogic().getLogic());
+ + getSubject().getTaskSelectionLogic().getLogicFlavour() + ","
+ + getSubject().getTaskSelectionLogic().getLogic());
engine = null;
}
}