aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-07-10 19:44:39 +0000
committerliamfallon <liam.fallon@est.tech>2019-07-10 19:44:39 +0000
commitadf67497761295115dc75b525500d687518fc4fd (patch)
treec5c5b5e737ac08256e9f782b5dccbd3ddc08d3c3 /core
parent5c384fb2888029c2babb859c30318749e1ce828c (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'core')
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java2
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutor.java4
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskExecutor.java4
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutor.java4
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java36
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java30
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java30
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java17
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java30
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java26
10 files changed, 92 insertions, 91 deletions
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<String, Object> {
// 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<String, Object> 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<String, Object> 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<EnEvent, AxArtifact
* {@inheritDoc}.
*/
@Override
- public final void executePre(final long executionId, final Properties executionProperties,
+ public final void executePre(final long executionId, @NonNull final Properties executionProperties,
final EnEvent newIncomingEvent) throws StateMachineException {
LOGGER.debug("execute-pre:" + axState.getKey().getId() + "," + axState.getTaskSelectionLogic().getLogicFlavour()
+ "," + axState.getTaskSelectionLogic().getLogic());
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
index 5efd47e53..e27c62f9a 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
@@ -27,6 +27,9 @@ import java.util.Properties;
import java.util.Set;
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;
@@ -60,9 +63,6 @@ public class StateFinalizerExecutionContext {
/** 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 list of state outputs for this state finalizer. The purpose of a state finalizer is to select a state output
* for a state from this list of state output names.
@@ -76,9 +76,6 @@ public class StateFinalizerExecutionContext {
*/
public final Map<String, Object> 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<String, ContextAlbum> 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<AxConcept> 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<String, ContextAlbum> 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;
- }
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java
index a94fe9e80..6fb28bca8 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.Map;
+import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
@@ -117,19 +118,25 @@ public class StateFinalizerExecutorTest {
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception ex) {
assertEquals("task input fields \"[InField0]\" are missing for task \"Task0:0.0.1\"", ex.getMessage());
}
try {
executor.executePre(0, null, incomingEvent);
+ } catch (Exception ex) {
+ assertEquals("executionProperties is marked @NonNull but is null", ex.getMessage());
+ }
+
+ try {
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception e) {
fail("test should not throw an exception");
}
try {
- executor.execute(0, null, incomingEvent);
+ executor.execute(0, new Properties(), incomingEvent);
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute() not implemented on abstract StateFinalizerExecutionContext class, "
@@ -154,7 +161,7 @@ public class StateFinalizerExecutorTest {
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception ex) {
fail("test should not throw an exception");
}
@@ -168,7 +175,7 @@ public class StateFinalizerExecutorTest {
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception ex) {
fail("test should not throw an exception");
}
@@ -184,7 +191,7 @@ public class StateFinalizerExecutorTest {
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception ex) {
fail("test should not throw an exception");
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java
index a4a0f21ec..eb2d11177 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.fail;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
@@ -158,24 +159,32 @@ public class TaskExecutorTest {
Map<String, Object> incomingFields = new LinkedHashMap<>();
try {
- executor.executePre(0, null, incomingFields);
+ executor.executePre(0, new Properties(), incomingFields);
} catch (Exception ex) {
assertEquals("task input fields \"[InField0]\" are missing for task \"Task0:0.0.1\"", ex.getMessage());
}
incomingFields.put("InField0", "A Value");
try {
- executor.executePre(0, null, incomingFields);
+ executor.executePre(0, new Properties(), incomingFields);
} catch (Exception e) {
fail("test should not throw an exception");
}
try {
- executor.execute(0, null, incomingFields);
+ executor.execute(0, new Properties(), incomingFields);
+ fail("test should throw an exception");
+ } catch (Exception ex) {
+ assertEquals("execute() not implemented on abstract TaskExecutor class, only on its subclasses",
+ ex.getMessage());
+ }
+
+ try {
+ executor.execute(0, new Properties(), incomingFields);
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute() not implemented on abstract TaskExecutor class, only on its subclasses",
- ex.getMessage());
+ ex.getMessage());
}
try {
@@ -183,7 +192,7 @@ public class TaskExecutorTest {
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute-post: task logic execution failure on task \"Task0\" in model Context:0.0.1",
- ex.getMessage());
+ ex.getMessage());
}
executor.getExecutionContext().setMessage("Execution message");
@@ -192,7 +201,7 @@ public class TaskExecutorTest {
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute-post: task logic execution failure on task \"Task0\" in model Context:0.0.1, "
- + "user message: Execution message", ex.getMessage());
+ + "user message: Execution message", ex.getMessage());
}
try {
@@ -216,7 +225,7 @@ public class TaskExecutorTest {
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("task output fields \"[BadExtraField]\" are unwanted for task \"Task0:0.0.1\"",
- ex.getMessage());
+ ex.getMessage());
}
executor.getExecutionContext().outFields.remove("BadExtraField");
@@ -247,5 +256,12 @@ public class TaskExecutorTest {
} catch (Exception ex) {
fail("test should not throw an exception");
}
+
+ try {
+ executor.executePre(0, null, incomingFields);
+ fail("test should throw an exception");
+ } catch (Exception ex) {
+ assertEquals("executionProperties is marked @NonNull but is null", ex.getMessage());
+ }
}
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
index 2ee308977..8e907e12a 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.fail;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
@@ -127,19 +128,19 @@ public class TaskSelectExecutorTest {
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception ex) {
assertEquals("task input fields \"[InField0]\" are missing for task \"Task0:0.0.1\"", ex.getMessage());
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception e) {
fail("test should not throw an exception");
}
try {
- executor.execute(0, null, incomingEvent);
+ executor.execute(0, new Properties(), incomingEvent);
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute() not implemented on class", ex.getMessage());
@@ -150,7 +151,7 @@ public class TaskSelectExecutorTest {
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute-post: task selection logic failed on state \"State0Parent:0.0.1:Parent:State0\"",
- ex.getMessage());
+ ex.getMessage());
}
executor.getExecutionContext().setMessage("Execution message");
@@ -159,11 +160,11 @@ public class TaskSelectExecutorTest {
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("execute-post: task selection logic failed on state \"State0Parent:0.0.1:Parent:State0\", "
- + "user message: Execution message", ex.getMessage());
+ + "user message: Execution message", ex.getMessage());
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception e) {
fail("test should not throw an exception");
}
@@ -176,7 +177,7 @@ public class TaskSelectExecutorTest {
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception e) {
fail("test should not throw an exception");
}
@@ -187,11 +188,11 @@ public class TaskSelectExecutorTest {
fail("test should throw an exception");
} catch (Exception ex) {
assertEquals("task \"IDontExist:0.0.0\" returned by task selection logic not defined "
- + "on state \"State0Parent:0.0.1:Parent:State0\"", ex.getMessage());
+ + "on state \"State0Parent:0.0.1:Parent:State0\"", ex.getMessage());
}
try {
- executor.executePre(0, null, incomingEvent);
+ executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception e) {
fail("test should not throw an exception");
}
@@ -204,5 +205,12 @@ public class TaskSelectExecutorTest {
} catch (Exception e) {
fail("test should not throw an exception");
}
+
+ try {
+ executor.executePre(0, null, incomingEvent);
+ fail("test should throw an exception");
+ } catch (Exception ex) {
+ assertEquals("executionProperties is marked @NonNull but is null", ex.getMessage());
+ }
}
}