aboutsummaryrefslogtreecommitdiffstats
path: root/core/core-engine/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-10-03 15:22:53 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-10-03 15:23:07 +0100
commit16a8f59fed2e53b1bbedaf65a33165bb4d3225f8 (patch)
tree1b6088a4e93ba0ab7fee719c43e57add32afb358 /core/core-engine/src/main
parentb4a5e9eaeed3b76db48e01875013d694014814bb (diff)
Add unit test for core events and context
This code is covered by feature testing but does not show up in Sonar. These unit tests give coverage on engine modules. Issue-ID: POLICY-1034 Change-Id: Ib7a288bcb9729ec88346cc8047e38f3a58f9a97c Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'core/core-engine/src/main')
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java38
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java50
2 files changed, 72 insertions, 16 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java
index 8bbb333b5..f73281ada 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/context/ApexInternalContext.java
@@ -53,7 +53,7 @@ import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
*/
public final class ApexInternalContext implements AxConceptGetter<ContextAlbum> {
// The key of the currently running Apex model
- private final AxArtifactKey key;
+ private AxArtifactKey key;
// The context albums being used in this engine
private final NavigableMap<AxArtifactKey, ContextAlbum> contextAlbums =
@@ -72,6 +72,9 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum>
* @throws ContextException On errors on context setting
*/
public ApexInternalContext(final AxPolicyModel apexPolicyModel) throws ContextException {
+ if (apexPolicyModel == null) {
+ throw new ContextException("internal context update failed, supplied model is null");
+ }
apexPolicyModel.register();
// The context distributor used to distribute context across policy engine instances
@@ -121,20 +124,6 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum>
final KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextDifference =
new ContextComparer().compare(ModelService.getModel(AxContextAlbums.class), newPolicyModel.getAlbums());
- // Remove maps that are no longer used
- for (final Entry<AxArtifactKey, AxContextAlbum> removedContextAlbumEntry : contextDifference.getLeftOnly()
- .entrySet()) {
- contextDistributor.removeContextAlbum(removedContextAlbumEntry.getValue());
- contextAlbums.remove(removedContextAlbumEntry.getKey());
- }
-
- // We switch over to the new Apex model
- newPolicyModel.register();
-
- // Set up the new context albums
- for (final AxArtifactKey contextAlbumKey : contextDifference.getRightOnly().keySet()) {
- contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey));
- }
// Handle the updated maps
for (final Entry<AxArtifactKey, List<AxContextAlbum>> contextAlbumEntry : contextDifference.getDifferentValues()
@@ -144,7 +133,7 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum>
final AxContextAlbum newContextAlbum = contextAlbumEntry.getValue().get(1);
// Check that the schemas are the same on the old and new context albums
- if (currentContextAlbum.getItemSchema().equals(newContextAlbum.getItemSchema())) {
+ if (!currentContextAlbum.getItemSchema().equals(newContextAlbum.getItemSchema())) {
// The schema is different, throw an exception because the schema should not change if the key of the
// album has not changed
throw new ContextException("internal context update failed on context album \""
@@ -154,7 +143,24 @@ public final class ApexInternalContext implements AxConceptGetter<ContextAlbum>
+ newContextAlbum.getItemSchema().getId() + "\" on incoming model");
}
}
+
+ // Remove maps that are no longer used
+ for (final Entry<AxArtifactKey, AxContextAlbum> removedContextAlbumEntry : contextDifference.getLeftOnly()
+ .entrySet()) {
+ contextDistributor.removeContextAlbum(removedContextAlbumEntry.getValue());
+ contextAlbums.remove(removedContextAlbumEntry.getKey());
+ }
+ // We switch over to the new Apex model
+ newPolicyModel.register();
+
+ // Set up the new context albums
+ for (final AxArtifactKey contextAlbumKey : contextDifference.getRightOnly().keySet()) {
+ contextAlbums.put(contextAlbumKey, contextDistributor.createContextAlbum(contextAlbumKey));
+ }
+
+ // Record the key of the current model
+ key = newPolicyModel.getKey();
}
/**
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 58bee8238..c510763cc 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
@@ -89,6 +89,10 @@ public class EnEvent extends HashMap<String, Object> {
*/
public EnEvent(final AxEvent axEvent) {
super();
+
+ if (axEvent == null) {
+ throw new EnException("event definition is null or was not found in model service");
+ }
// Save the event definition from the Apex model
this.axEvent = axEvent;
}
@@ -173,6 +177,16 @@ public class EnEvent extends HashMap<String, Object> {
this.exceptionMessage = exceptionMessage;
}
+
+ /**
+ * Get the user artifact stack of the event.
+ *
+ * @return the event user artifact stack
+ */
+ public AxConcept[] getUserArtifactStack() {
+ return userArtifactStack;
+ }
+
/**
* Store the user artifact stack of the event.
*
@@ -345,4 +359,40 @@ public class EnEvent extends HashMap<String, Object> {
return "EnEvent [axEvent=" + axEvent + ", userArtifactStack=" + Arrays.toString(userArtifactStack) + ", map="
+ super.toString() + "]";
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + axEvent.hashCode();
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof EnEvent)) {
+ return false;
+ }
+ EnEvent other = (EnEvent) obj;
+ if (axEvent == null) {
+ if (other.axEvent != null) {
+ return false;
+ }
+ } else if (!axEvent.equals(other.axEvent)) {
+ return false;
+ }
+ return true;
+ }
}