aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-jython/src/main
diff options
context:
space:
mode:
authorning.xi <ning.xi@est.tech>2019-02-28 03:01:19 +0000
committerning.xi <ning.xi@est.tech>2019-02-28 03:01:19 +0000
commit51a3553469d4d324e8cb71f2ef057d5c099c9b38 (patch)
tree05134c328212a0bdf944c9644df47fed39bc04a0 /plugins/plugins-executor/plugins-executor-jython/src/main
parent3bbf5d0d753fa4ac55c9e5a31ae450a5bcfc6a28 (diff)
Increase test coverage for plugins-executor-jython
Add junit test cases into apex-pdp/plugins/plugins-executor-jython Issue-ID: POLICY-1523 Change-Id: I2545a9cefc6b4b9a53200b98081ddd8bc8274b40 Signed-off-by: ning.xi <ning.xi@est.tech>
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-jython/src/main')
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonStateFinalizerExecutor.java15
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java37
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java39
3 files changed, 28 insertions, 63 deletions
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonStateFinalizerExecutor.java
index ecd9f7ae1..3636d811a 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonStateFinalizerExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonStateFinalizerExecutor.java
@@ -21,11 +21,11 @@
package org.onap.policy.apex.plugins.executor.jython;
import java.util.Map;
-
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;
import org.python.core.CompileMode;
+import org.python.core.CompilerFlags;
import org.python.core.Py;
import org.python.core.PyCode;
import org.python.core.PyException;
@@ -61,8 +61,9 @@ public class JythonStateFinalizerExecutor extends StateFinalizerExecutor {
super.prepare();
try {
synchronized (Py.class) {
- compiled = Py.compile_flags(getSubject().getLogic(), "<" + getSubject().getKey().toString() + ">",
- CompileMode.exec, null);
+ final String logic = getSubject().getLogic();
+ final String filename = "<" + getSubject().getKey().toString() + ">";
+ compiled = Py.compile_flags(logic, filename, CompileMode.exec, new CompilerFlags());
}
} catch (final PyException e) {
LOGGER.warn("failed to compile Jython code for state finalizer " + getSubject().getKey(), e);
@@ -98,7 +99,7 @@ public class JythonStateFinalizerExecutor extends StateFinalizerExecutor {
// Set up the Jython engine
interpreter.set("executor", getExecutionContext());
interpreter.exec(compiled);
- returnValue = (boolean) interpreter.get("returnValue", java.lang.Boolean.class);
+ returnValue = interpreter.get("returnValue", java.lang.Boolean.class);
}
/* */
} catch (final Exception e) {
@@ -111,11 +112,7 @@ public class JythonStateFinalizerExecutor extends StateFinalizerExecutor {
executePost(returnValue);
// Send back the return event
- if (returnValue) {
- return getOutgoing();
- } else {
- return null;
- }
+ return getOutgoing();
}
/**
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
index bddb63b42..1280fb85d 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
@@ -21,7 +21,6 @@
package org.onap.policy.apex.plugins.executor.jython;
import java.util.Map;
-
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;
@@ -113,40 +112,26 @@ public class JythonTaskExecutor extends TaskExecutor {
executePost(returnValue);
// Send back the return event
- if (returnValue) {
- return getOutgoing();
- } else {
- return null;
- }
+ return getOutgoing();
+
}
/**
* Handle the result returned by the interpreter.
- *
+ *
* @return true if the result was successful
* @throws StateMachineException on interpreter failures
*/
private boolean handleInterpreterResult() throws StateMachineException {
- boolean returnValue = false;
-
- try {
- final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
- 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 = interpreter.get("returnValue", java.lang.Boolean.class);
+ 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() + "\"");
}
- return returnValue;
+ return (Boolean) ret;
+
}
/**
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
index 9a2433122..d6e6dd70b 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
@@ -44,8 +44,8 @@ public class JythonTaskSelectExecutor extends TaskSelectExecutor {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(JythonTaskSelectExecutor.class);
// Recurring string constants
- private static final String TSL_FAILED_PREFIX =
- "execute: task selection logic failed to set a return value for state \"";
+ private static final String TSL_FAILED_PREFIX =
+ "execute: task selection logic failed to set a return value for state \"";
// The Jython interpreter
private final PythonInterpreter interpreter = new PythonInterpreter();
@@ -117,41 +117,24 @@ public class JythonTaskSelectExecutor extends TaskSelectExecutor {
executePost(returnValue);
// Send back the return event
- if (returnValue) {
- return getOutgoing();
- } else {
- return null;
- }
+ return getOutgoing();
+
}
/**
* Handle the result returned by the interpreter.
- *
+ *
* @return true if the result was successful
* @throws StateMachineException on interpreter errors
*/
private boolean handleInterpreterResult() throws StateMachineException {
- boolean returnValue = false;
-
- try {
- final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
- 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 = interpreter.get("returnValue", java.lang.Boolean.class);
+ if (ret == null) {
+ LOGGER.error(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"");
+ throw new StateMachineException(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\"");
}
- return returnValue;
+ return (Boolean) ret;
+
}
/**