From adf67497761295115dc75b525500d687518fc4fd Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 10 Jul 2019 19:44:39 +0000 Subject: Add integration tests for executor properties Added integration test that sets properties in a dummy plugin and amends them in tasks in a policy. Variosu tests added to check combinations of where properties are set in plugins or in tasks or both. Implementaiton changed to: - Always pass in a Properies object, the properties object coming into the policy cannot be null because the task/TSL/SFL may wish to set it - Fix a bug where the properties were not passed from the ApexEvent to the engine event in the ApexEventUnmarshaller class Issue-ID: POLICY-1743 Change-Id: I6aa152b28d46cf3cc6fa56a1a95b76a8e55f5a49 Signed-off-by: liamfallon --- .../policy/apex/core/engine/event/EnEvent.java | 2 +- .../engine/executor/StateFinalizerExecutor.java | 4 ++- .../apex/core/engine/executor/TaskExecutor.java | 4 ++- .../core/engine/executor/TaskSelectExecutor.java | 4 ++- .../context/StateFinalizerExecutionContext.java | 36 ++++++++-------------- .../executor/context/TaskExecutionContext.java | 30 ++++++------------ .../context/TaskSelectionExecutionContext.java | 30 ++++++------------ 7 files changed, 40 insertions(+), 70 deletions(-) (limited to 'core/core-engine/src/main') diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java index 95ea6b5d2..9a5acbf3e 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java @@ -82,7 +82,7 @@ public class EnEvent extends HashMap { // Event related properties used during processing of this event @Getter @Setter - private Properties executionProperties; + private Properties executionProperties = new Properties(); // A string holding a message that indicates why processing of this event threw an exception @Getter diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutor.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutor.java index e3a64eb30..698a1d837 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutor.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutor.java @@ -26,6 +26,8 @@ import static org.onap.policy.common.utils.validation.Assertions.argumentOfClass import java.util.Map; import java.util.Properties; +import lombok.NonNull; + import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -115,7 +117,7 @@ public abstract class StateFinalizerExecutor * {@inheritDoc}. */ @Override - public final void executePre(final long executionId, final Properties executionProperties, + public final void executePre(final long executionId, @NonNull final Properties executionProperties, final Map newIncomingFields) throws StateMachineException, ContextException { LOGGER.debug("execute-pre:" + finalizerLogic.getLogicFlavour() + "," + getSubject().getId() + "," + finalizerLogic.getLogic()); diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskExecutor.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskExecutor.java index 15fee6efa..ab81a8490 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskExecutor.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskExecutor.java @@ -30,6 +30,8 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import lombok.NonNull; + import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -116,7 +118,7 @@ public abstract class TaskExecutor * {@inheritDoc}. */ @Override - public final void executePre(final long executionId, final Properties executionProperties, + public final void executePre(final long executionId, @NonNull final Properties executionProperties, final Map newIncomingFields) throws StateMachineException, ContextException { LOGGER.debug("execute-pre:" + getSubject().getTaskLogic().getLogicFlavour() + "," + getSubject().getKey().getId() + "," + getSubject().getTaskLogic().getLogic()); diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutor.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutor.java index 097bc98b5..d99d6b005 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutor.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutor.java @@ -25,6 +25,8 @@ import static org.onap.policy.common.utils.validation.Assertions.argumentNotNull import java.util.Properties; +import lombok.NonNull; + import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.ExecutorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -108,7 +110,7 @@ public abstract class TaskSelectExecutor implements Executor fields; - // A message specified in the logic - private String message; - /** * The state output that the state finalizer logic has selected for a state. The state finalizer logic sets this * field in its logic after executing and the Apex engine uses this state output for this state. @@ -95,6 +92,15 @@ public class StateFinalizerExecutionContext { // All available context albums private final Map context; + // A message specified in the logic + @Getter + @Setter + private String message; + + // Execution properties for a policy execution + @Getter + private Properties executionProperties; + /** * Instantiates a new state finalizer execution context. * @@ -179,22 +185,4 @@ public class StateFinalizerExecutionContext { public void setSelectedStateOutputName(final String selectedStateOutputName) { this.selectedStateOutputName = selectedStateOutputName; } - - /** - * Gets the user message. - * - * @return the user message - */ - public String getMessage() { - return message; - } - - /** - * Sets the user message. - * - * @param message the message - */ - public void setMessage(final String message) { - this.message = message; - } } diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java index 6fb55a3e7..b322cf402 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java @@ -27,6 +27,9 @@ import java.util.Map; import java.util.Properties; import java.util.TreeMap; +import lombok.Getter; +import lombok.Setter; + import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextRuntimeException; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -66,9 +69,6 @@ public class TaskExecutionContext { /** the execution ID for the current APEX policy execution instance. */ public final Long executionId; - /** the execution properties the current APEX policy execution instance. */ - public final Properties executionProperties; - /** * The incoming fields from the trigger event for the task. The task logic can access these fields when executing * its logic. @@ -95,8 +95,14 @@ public class TaskExecutionContext { private final List usedArtifactStack; // A message specified in the logic + @Getter + @Setter private String message; + // Execution properties for a policy execution + @Getter + private Properties executionProperties; + /** * Instantiates a new task execution context. * @@ -163,22 +169,4 @@ public class TaskExecutionContext { + "\" on task \"" + subject.getId() + "\""); } } - - /** - * Get the user message. - * - * @return the user message - */ - public String getMessage() { - return message; - } - - /** - * Sets the user message. - * - * @param message the message - */ - public void setMessage(final String message) { - this.message = message; - } } diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java index 10d21a76f..8d83e7645 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java @@ -26,6 +26,9 @@ import java.util.Map; import java.util.Properties; import java.util.TreeMap; +import lombok.Getter; +import lombok.Setter; + import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextRuntimeException; import org.onap.policy.apex.core.engine.context.ApexInternalContext; @@ -66,9 +69,6 @@ public class TaskSelectionExecutionContext { /** the execution ID for the current APEX policy execution instance. */ public final Long executionId; - /** the execution properties the current APEX policy execution instance. */ - public final Properties executionProperties; - /** * The incoming fields from the trigger event for the state. The task selection logic can access * these fields to decide what task to select for the state. @@ -94,8 +94,14 @@ public class TaskSelectionExecutionContext { private final Map context; // A message specified in the logic + @Getter + @Setter private String message; + // Execution properties for a policy execution + @Getter + private Properties executionProperties; + /** * Instantiates a new task selection execution context. * @@ -170,22 +176,4 @@ public class TaskSelectionExecutionContext { + "\" on state \"" + subject.getId() + "\""); } } - - /** - * Gets the user message. - * - * @return the user message - */ - public String getMessage() { - return message; - } - - /** - * Sets the user message. - * - * @param message the message - */ - public void setMessage(final String message) { - this.message = message; - } } -- cgit 1.2.3-korg