From 259039fa91e3038c41f4a322d81e7ea07a78b96e Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 3 Dec 2018 22:48:10 +0000 Subject: Add unit test for Java executor Code coverage in the Apex-PDP plugins is very low. JUnit coverage will be increased for the Plugins over the Dublin design timeline. Issue-ID: POLICY-1379 Change-Id: Ie70ab5a9be650818cb330ec5be2a89a5db6153c5 Signed-off-by: liamfallon --- .../executor/java/JavaStateFinalizerExecutor.java | 6 +---- .../plugins/executor/java/JavaTaskExecutor.java | 6 +---- .../executor/java/JavaTaskSelectExecutor.java | 30 ++++++++++------------ 3 files changed, 16 insertions(+), 26 deletions(-) (limited to 'plugins/plugins-executor/plugins-executor-java/src/main') diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java index 8577d18fb..ef0a8d178 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java +++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java @@ -98,11 +98,7 @@ public class JavaStateFinalizerExecutor 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-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java index 829434dc3..e9bf45305 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java +++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java @@ -97,11 +97,7 @@ public class JavaTaskExecutor extends TaskExecutor { executePost(returnValue); // Send back the return event - if (returnValue) { - return getOutgoing(); - } else { - return null; - } + return getOutgoing(); } /** diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java index e642972af..02794cdf6 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java +++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java @@ -58,8 +58,10 @@ public class JavaTaskSelectExecutor extends TaskSelectExecutor { // Create the task logic object from the byte code of the class taskSelectionLogicObject = Class.forName(getSubject().getTaskSelectionLogic().getLogic()).newInstance(); } catch (final Exception e) { - LOGGER.error("instantiation error on Java class" + taskSelectionLogicObject, e); - throw new StateMachineException("instantiation error on Java class" + taskSelectionLogicObject, e); + LOGGER.error("instantiation error on Java class \"" + getSubject().getTaskSelectionLogic().getLogic() + + "\"", e); + throw new StateMachineException("instantiation error on Java class \"" + + getSubject().getTaskSelectionLogic().getLogic() + "\"", e); } } @@ -74,7 +76,7 @@ public class JavaTaskSelectExecutor 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); @@ -84,26 +86,22 @@ public class JavaTaskSelectExecutor extends TaskSelectExecutor { // Find and call the method with the signature "public boolean getTask(final TaskSelectionExecutionContext // executor)" to invoke the task selection // logic in the Java class - final Method method = taskSelectionLogicObject.getClass().getDeclaredMethod("getTask", (Class[]) - new Class[] { TaskSelectionExecutionContext.class }); + final Method method = taskSelectionLogicObject.getClass().getDeclaredMethod("getTask", + (Class[]) new Class[] { TaskSelectionExecutionContext.class }); returnValue = (boolean) method.invoke(taskSelectionLogicObject, getExecutionContext()); } catch (final Exception e) { - LOGGER.error( - "execute: task selection logic failed to run for state \"" + getSubject().getKey().getId() + "\"", - e); + LOGGER.error("execute: task selection logic failed to run for state \"" + getSubject().getKey().getId() + + "\"", e); 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); } // Do the execution post work executePost(returnValue); // Send back the return event - if (returnValue) { - return getOutgoing(); - } else { - return null; - } + return getOutgoing(); } /** @@ -114,7 +112,7 @@ public class JavaTaskSelectExecutor 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()); } } -- cgit 1.2.3-korg