aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java43
-rw-r--r--context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java84
-rw-r--r--context/context-management/src/test/java/org/onap/policy/apex/context/impl/DummyContextAlbumImpl.java280
-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
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java60
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java57
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java188
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java163
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java209
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java42
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java97
12 files changed, 1287 insertions, 24 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
index 6382992d9..221c1987a 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
@@ -47,7 +47,7 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public final class ContextAlbumImpl implements ContextAlbum {
+public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextAlbumImpl> {
// Logger for this class
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextAlbumImpl.class);
@@ -502,4 +502,45 @@ public final class ContextAlbumImpl implements ContextAlbum {
// Clear the map
albumMap.clear();
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(ContextAlbumImpl otherContextAlbumImpl) {
+ return (equals(otherContextAlbumImpl) ? 0 : 1);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + albumDefinition.hashCode();
+ result = prime * result + albumMap.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 (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof ContextAlbumImpl)) {
+ return false;
+ }
+ ContextAlbumImpl other = (ContextAlbumImpl) obj;
+ if (!albumDefinition.equals(other.albumDefinition)) {
+ return false;
+ }
+ return albumMap.equals(other.albumMap);
+ }
}
diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java
index 25928716e..cb99fc965 100644
--- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java
+++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.context.impl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -45,6 +46,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.common.parameters.ParameterService;
@@ -123,7 +125,7 @@ public class ContextAlbumImplTest {
fail("this test should throw an exception");
} catch (ApexRuntimeException e) {
assertEquals("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas "
- + "not found in model service", e.getMessage());
+ + "not found in model service", e.getMessage());
} catch (ContextException e) {
fail("this test should throw an ApexRuntimeException");
}
@@ -154,7 +156,7 @@ public class ContextAlbumImplTest {
ContextAlbum album = new ContextAlbumImpl(axContextAlbum, distributor, new LinkedHashMap<String, Object>());
AxContextAlbum axContextAlbumRo = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy",
- false, simpleStringSchema.getKey());
+ false, simpleStringSchema.getKey());
ContextAlbum albumRo = new ContextAlbumImpl(axContextAlbumRo, distributor, new LinkedHashMap<String, Object>());
assertEquals("TestContextAlbum", album.getName());
@@ -224,9 +226,8 @@ public class ContextAlbumImplTest {
albumRo.remove("AllKey0");
fail("test should throw an exception");
} catch (ContextRuntimeException e) {
- assertEquals(
- "album \"TestContextAlbum:0.0.1\" remove() not allowed on read only albums for key=\"AllKey0\"",
- e.getMessage());
+ assertEquals("album \"TestContextAlbum:0.0.1\" remove() not allowed "
+ + "on read only albums for key=\"AllKey0\"", e.getMessage());
}
try {
@@ -273,7 +274,8 @@ public class ContextAlbumImplTest {
AxArtifactKey somePolicyKey = new AxArtifactKey("MyPolicy", "0.0.1");
AxReferenceKey somePolicyState = new AxReferenceKey(somePolicyKey, "SomeState");
- AxConcept[] userArtifactStack = { somePolicyKey, somePolicyState };
+ AxConcept[] userArtifactStack =
+ { somePolicyKey, somePolicyState };
album.setUserArtifactStack(userArtifactStack);
assertEquals("MyPolicy:0.0.1", album.getUserArtifactStack()[0].getId());
assertEquals("MyPolicy:0.0.1:NULL:SomeState", album.getUserArtifactStack()[1].getId());
@@ -309,10 +311,78 @@ public class ContextAlbumImplTest {
}
assertEquals("New value of Key0", album.remove("Key0"));
-
+
album.clear();
assertTrue(album.isEmpty());
+
+ ModelService.clear();
+ }
+
+ @SuppressWarnings("unlikely-arg-type")
+ @Test
+ public void testCompareToEqualsHash() throws ContextException {
+ AxContextSchemas schemas = new AxContextSchemas();
+ AxContextSchema simpleIntSchema = new AxContextSchema(new AxArtifactKey("SimpleIntSchema", "0.0.1"), "JAVA",
+ "java.lang.Integer");
+ schemas.getSchemasMap().put(simpleIntSchema.getKey(), simpleIntSchema);
+ AxContextSchema simpleStringSchema = new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"),
+ "JAVA", "java.lang.String");
+ schemas.getSchemasMap().put(simpleStringSchema.getKey(), simpleStringSchema);
+ ModelService.registerModel(AxContextSchemas.class, schemas);
+
+ AxContextAlbum axContextAlbum = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy",
+ true, AxArtifactKey.getNullKey());
+
+ axContextAlbum.setItemSchema(simpleIntSchema.getKey());
+ Distributor distributor = new JvmLocalDistributor();
+ distributor.init(axContextAlbum.getKey());
+ ContextAlbumImpl album = new ContextAlbumImpl(axContextAlbum, distributor, new LinkedHashMap<String, Object>());
+
+ assertTrue(album.hashCode() != 0);
+
+ assertEquals(0, album.compareTo(album));
+ assertEquals(1, album.compareTo(null));
+
+ assertTrue(album.equals(album));
+ assertFalse(album.equals(new DummyContextAlbumImpl()));
+
+ ContextAlbumImpl otherAlbum = new ContextAlbumImpl(axContextAlbum, distributor,
+ new LinkedHashMap<String, Object>());
+ assertTrue(album.equals(otherAlbum));
+
+ otherAlbum.put("Key", 123);
+ assertFalse(album.equals(otherAlbum));
+
+ try {
+ otherAlbum.put("Key", "BadValue");
+ fail("test should throw an exception here");
+ } catch (ContextRuntimeException cre) {
+ assertEquals("Failed to set context value for key \"Key\" in album \"TestContextAlbum:0.0.1\": "
+ + "TestContextAlbum:0.0.1: object \"BadValue\" of class \"java.lang.String\" "
+ + "not compatible with class \"java.lang.Integer\"", cre.getMessage());
+ }
+
+ AxContextAlbum otherAxContextAlbum = new AxContextAlbum(new AxArtifactKey("OtherTestContextAlbum", "0.0.1"),
+ "Policy", true, AxArtifactKey.getNullKey());
+
+ otherAxContextAlbum.setItemSchema(simpleStringSchema.getKey());
+ otherAlbum = new ContextAlbumImpl(otherAxContextAlbum, distributor, new LinkedHashMap<String, Object>());
+ assertFalse(album.equals(otherAlbum));
+
+ try {
+ album.flush();
+ fail("test should throw an exception here");
+ } catch (ContextException ce) {
+ assertEquals("map flush failed, supplied map is null", ce.getMessage());
+ }
+
+ AxContextAlbums albums = new AxContextAlbums();
+ ModelService.registerModel(AxContextAlbums.class, albums);
+ albums.getAlbumsMap().put(axContextAlbum.getKey(), axContextAlbum);
+ distributor.createContextAlbum(album.getKey());
+ album.flush();
+
ModelService.clear();
}
}
diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/DummyContextAlbumImpl.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/DummyContextAlbumImpl.java
new file mode 100644
index 000000000..9109ec694
--- /dev/null
+++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/DummyContextAlbumImpl.java
@@ -0,0 +1,280 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.context.impl;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang3.NotImplementedException;
+import org.onap.policy.apex.context.ContextAlbum;
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.context.SchemaHelper;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+
+/**
+ * Dummy album implementation class.
+ *
+ */
+public class DummyContextAlbumImpl implements ContextAlbum {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#clear()
+ */
+ @Override
+ public void clear() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#containsKey(java.lang.Object)
+ */
+ @Override
+ public boolean containsKey(Object key) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#containsValue(java.lang.Object)
+ */
+ @Override
+ public boolean containsValue(Object value) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#entrySet()
+ */
+ @Override
+ public Set<Entry<String, Object>> entrySet() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#get(java.lang.Object)
+ */
+ @Override
+ public Object get(Object key) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#isEmpty()
+ */
+ @Override
+ public boolean isEmpty() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#keySet()
+ */
+ @Override
+ public Set<String> keySet() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public Object put(String key, Object value) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#putAll(java.util.Map)
+ */
+ @Override
+ public void putAll(Map<? extends String, ? extends Object> map) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#remove(java.lang.Object)
+ */
+ @Override
+ public Object remove(Object key) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#size()
+ */
+ @Override
+ public int size() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Map#values()
+ */
+ @Override
+ public Collection<Object> values() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#getName()
+ */
+ @Override
+ public String getName() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#getAlbumDefinition()
+ */
+ @Override
+ public AxContextAlbum getAlbumDefinition() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#getSchemaHelper()
+ */
+ @Override
+ public SchemaHelper getSchemaHelper() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#lockForReading(java.lang.String)
+ */
+ @Override
+ public void lockForReading(String key) throws ContextException {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#lockForWriting(java.lang.String)
+ */
+ @Override
+ public void lockForWriting(String key) throws ContextException {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#unlockForReading(java.lang.String)
+ */
+ @Override
+ public void unlockForReading(String key) throws ContextException {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#unlockForWriting(java.lang.String)
+ */
+ @Override
+ public void unlockForWriting(String key) throws ContextException {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#getUserArtifactStack()
+ */
+ @Override
+ public AxConcept[] getUserArtifactStack() {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.context.ContextAlbum#setUserArtifactStack(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept[])
+ */
+ @Override
+ public void setUserArtifactStack(AxConcept[] userArtifactStack) {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.context.ContextAlbum#flush()
+ */
+ @Override
+ public void flush() throws ContextException {
+ throw new NotImplementedException("Not Implemeted on dummy class");
+
+ }
+
+}
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;
+ }
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
new file mode 100644
index 000000000..1b3489790
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.common.parameters.ParameterService;
+
+/**
+ * Test the executor parameters.
+ *
+ */
+public class EngineParametersTest {
+
+ @Test
+ public void test() {
+ EngineParameters pars = new EngineParameters();
+ pars.setName("Name");
+ assertEquals("Name", pars.getName());
+
+ ContextParameters contextPars = new ContextParameters();
+
+ pars.setContextParameters(contextPars);
+ assertEquals(contextPars, pars.getContextParameters());
+
+ Map<String, ExecutorParameters> executorParameterMap = new LinkedHashMap<>();
+ executorParameterMap.put("Executor", new ExecutorParameters());
+ pars.setExecutorParameterMap(executorParameterMap);
+ assertEquals(executorParameterMap, pars.getExecutorParameterMap());
+
+ assertTrue(pars.validate().isValid());
+
+ ParameterService.register(pars);
+ ParameterService.deregister(pars);
+ }
+}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
new file mode 100644
index 000000000..88c8c852d
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
+
+/**
+ * Test the executor parameters.
+ *
+ */
+public class ExecutorParametersTest {
+
+ @Test
+ public void test() {
+ ExecutorParameters pars = new ExecutorParameters();
+ pars.setName("Name");
+ assertEquals("Name", pars.getName());
+ pars.setStateFinalizerExecutorPluginClass("some.state.finalizer.plugin.class");
+ assertEquals("some.state.finalizer.plugin.class", pars.getStateFinalizerExecutorPluginClass());
+ pars.setTaskExecutorPluginClass("some.task.executor.plugin.class");
+ assertEquals("some.task.executor.plugin.class", pars.getTaskExecutorPluginClass());
+ pars.setTaskSelectionExecutorPluginClass("some.task.selection.executor.plugin.class");
+ assertEquals("some.task.selection.executor.plugin.class", pars.getTaskSelectionExecutorPluginClass());
+
+ assertEquals("ExecutorParameters [name=Name, taskExecutorPluginClass=some.task.executor.plugin.class, "
+ + "taskSelectionExecutorPluginClass=some.task.selection.executor.plugin.class, "
+ + "stateFinalizerExecutorPluginClass=some.state.finalizer.plugin.class]", pars.toString());
+
+ assertTrue(pars.validate().isValid());
+
+
+ ParameterService.register(pars);
+ ParameterService.deregister(pars);
+ }
+}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
new file mode 100644
index 000000000..a75ad37f6
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.context.parameters.ContextParameterConstants;
+import org.onap.policy.apex.context.parameters.DistributorParameters;
+import org.onap.policy.apex.context.parameters.LockManagerParameters;
+import org.onap.policy.apex.context.parameters.PersistorParameters;
+import org.onap.policy.apex.context.parameters.SchemaParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.common.parameters.ParameterService;
+
+/**
+ * Test the Apex engine internal context class.
+ */
+public class ApexInternalContextTest {
+
+ private AxPolicyModel policyModel;
+ private AxPolicyModel newVersionPolicyModel;
+ private AxPolicyModel newPolicyModel;
+ private AxContextAlbum album;
+ private AxContextAlbum newAlbum;
+ private AxPolicyModel incompatiblePolicyModel;
+
+ /**
+ * Initialize parameters.
+ */
+ @Before
+ public void registerParameters() {
+ ParameterService.register(new SchemaParameters());
+ ParameterService.register(new DistributorParameters());
+ ParameterService.register(new LockManagerParameters());
+ ParameterService.register(new PersistorParameters());
+ }
+
+ /**
+ * Create policy model.
+ */
+ @Before
+ public void createPolicyModels() {
+ AxArtifactKey modelKey = new AxArtifactKey("PolicyModel:0.0.1");
+ policyModel = new AxPolicyModel(modelKey);
+
+ AxArtifactKey schemaKey = new AxArtifactKey("Schema:0.0.1");
+ AxContextSchema schema = new AxContextSchema(schemaKey, "Java", "java.lang.String");
+ policyModel.getSchemas().getSchemasMap().put(schemaKey, schema);
+
+ AxArtifactKey albumKey = new AxArtifactKey("Album:0.0.1");
+ album = new AxContextAlbum(albumKey, "Policy", true, schemaKey);
+
+ policyModel.getAlbums().getAlbumsMap().put(albumKey, album);
+
+ AxArtifactKey newVersionModelKey = new AxArtifactKey("PolicyModel:0.0.2");
+ newVersionPolicyModel = new AxPolicyModel(newVersionModelKey);
+
+ newVersionPolicyModel.getSchemas().getSchemasMap().put(schemaKey, schema);
+ AxContextAlbum compatibleAlbum = new AxContextAlbum(albumKey, "Global", true, schemaKey);
+ newVersionPolicyModel.getAlbums().getAlbumsMap().put(albumKey, compatibleAlbum);
+
+ AxArtifactKey anotherAlbumKey = new AxArtifactKey("AnotherAlbum:0.0.1");
+ AxContextAlbum anotherAlbum = new AxContextAlbum(anotherAlbumKey, "Policy", true, schemaKey);
+
+ newVersionPolicyModel.getAlbums().getAlbumsMap().put(anotherAlbumKey, anotherAlbum);
+
+ AxArtifactKey incompatibleModelKey = new AxArtifactKey("IncompatiblePolicyModel:0.0.2");
+ incompatiblePolicyModel = new AxPolicyModel(incompatibleModelKey);
+
+ AxArtifactKey incompatibleSchemaKey = new AxArtifactKey("IncompatibleSchema:0.0.1");
+ AxContextSchema incompatibleSchema = new AxContextSchema(incompatibleSchemaKey, "Java", "java.lang.Integer");
+ incompatiblePolicyModel.getSchemas().getSchemasMap().put(incompatibleSchemaKey, incompatibleSchema);
+
+ AxContextAlbum incompatibleAlbum = new AxContextAlbum(albumKey, "Policy", true, incompatibleSchemaKey);
+ incompatiblePolicyModel.getAlbums().getAlbumsMap().put(albumKey, incompatibleAlbum);
+
+ AxArtifactKey newModelKey = new AxArtifactKey("NewPolicyModel:0.0.1");
+ newPolicyModel = new AxPolicyModel(newModelKey);
+
+ AxArtifactKey newSchemaKey = new AxArtifactKey("NewSchema:0.0.1");
+ AxContextSchema newSchema = new AxContextSchema(newSchemaKey, "Java", "java.lang.Integer");
+ newPolicyModel.getSchemas().getSchemasMap().put(newSchemaKey, newSchema);
+
+ AxArtifactKey newAlbumKey = new AxArtifactKey("NewAlbum:0.0.1");
+ newAlbum = new AxContextAlbum(newAlbumKey, "Policy", true, newSchemaKey);
+
+ newPolicyModel.getAlbums().getAlbumsMap().put(newAlbumKey, newAlbum);
+ }
+
+ /**
+ * Deregister parameters.
+ */
+ @After
+ public void deregisterParameters() {
+ ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
+ ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
+ ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
+ ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ }
+
+ @Test
+ public void testAlbumInit() throws ContextException {
+ try {
+ new ApexInternalContext(null);
+ fail("test should throw an exception");
+ } catch (ContextException ce) {
+ assertEquals("internal context update failed, supplied model is null", ce.getMessage());
+ }
+
+ ApexInternalContext context = new ApexInternalContext(policyModel);
+
+ assertEquals(policyModel.getKey(), context.getKey());
+ assertEquals(1, context.getContextAlbums().size());
+
+ AxArtifactKey albumKey = new AxArtifactKey("Album:0.0.1");
+ assertEquals(album.getId(), context.get(albumKey).getKey().getId());
+ assertEquals(album.getId(), context.get(albumKey.getName()).getKey().getId());
+ assertEquals(album.getId(), context.get(albumKey.getName(), albumKey.getVersion()).getKey().getId());
+ assertEquals(album.getId(), context.getAll(albumKey.getName()).iterator().next().getKey().getId());
+ assertEquals(album.getId(),
+ context.getAll(albumKey.getName(), albumKey.getVersion()).iterator().next().getKey().getId());
+
+ context.clear();
+ assertEquals(1, context.getContextAlbums().size());
+
+ assertEquals("ApexInternalContext [contextAlbums={AxArtifactKey:(name=Album,version=0.0.1)",
+ context.toString().substring(0, 76));
+ }
+
+ @Test
+ public void testAlbumUpdate() throws ContextException {
+ ApexInternalContext context = new ApexInternalContext(policyModel);
+
+ try {
+ context.update(null);
+ fail("test should throw an exception");
+ } catch (ContextException ce) {
+ assertEquals("internal context update failed, supplied model is null", ce.getMessage());
+ }
+
+ assertEquals(policyModel.getKey().getId(), context.getKey().getId());
+ assertEquals(1, context.getContextAlbums().size());
+
+ try {
+ context.update(incompatiblePolicyModel);
+ fail("test should throw an exception here");
+ } catch (ContextException ce) {
+ assertEquals("internal context update failed on context album \"Album:0.0.1\" "
+ + "in model \"PolicyModel:0.0.1\", "
+ + "schema \"Schema:0.0.1\" on existing context model does not equal "
+ + "schema \"IncompatibleSchema:0.0.1\" on incoming model", ce.getMessage());
+ }
+
+ assertEquals(policyModel.getKey().getId(), context.getKey().getId());
+
+ context.update(newVersionPolicyModel);
+ assertEquals(newVersionPolicyModel.getKey().getId(), context.getKey().getId());
+
+ context.update(newPolicyModel);
+ assertEquals(newPolicyModel.getKey().getId(), context.getKey().getId());
+ }
+}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java
new file mode 100644
index 000000000..0a86c070a
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java
@@ -0,0 +1,163 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine.event;
+
+import java.util.List;
+
+import org.apache.commons.lang3.NotImplementedException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+
+/**
+ * Dummy Key Class.
+ */
+public class DummyAxKey extends AxKey {
+ private static final long serialVersionUID = 964899169013353800L;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(AxConcept concept) {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getId()
+ */
+ @Override
+ public String getId() {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getCompatibility(org.onap.policy.apex.model.basicmodel.
+ * concepts.AxKey)
+ */
+ @Override
+ public Compatibility getCompatibility(AxKey otherKey) {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxKey#isCompatible(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxKey)
+ */
+ @Override
+ public boolean isCompatible(AxKey otherKey) {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxKey getKey() {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(AxValidationResult result) {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ throw new NotImplementedException("Not implemented on dummy class");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object otherObject) {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ return "Dummy Key";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(AxConcept target) {
+ throw new NotImplementedException("Not implemented on dummy class");
+ }
+}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java
new file mode 100644
index 000000000..4fd9367ca
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java
@@ -0,0 +1,209 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.ContextRuntimeException;
+import org.onap.policy.apex.context.parameters.ContextParameterConstants;
+import org.onap.policy.apex.context.parameters.SchemaParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.service.ModelService;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.common.parameters.ParameterService;
+
+/**
+ * Test the engine event class.
+ */
+public class EnEventTest {
+ /**
+ * Set up the services.
+ */
+ @Before
+ public void setupServices() {
+ ModelService.registerModel(AxContextSchemas.class, new AxContextSchemas());
+ ModelService.registerModel(AxEvents.class, new AxEvents());
+ ParameterService.register(new SchemaParameters());
+ }
+
+ /**
+ * Tear down the services.
+ */
+ @After
+ public void teardownServices() {
+ ModelService.deregisterModel(AxContextSchema.class);
+ ModelService.deregisterModel(AxEvents.class);
+ ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ }
+
+ @Test
+ public void testEnEvent() {
+ AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1");
+ try {
+ new EnEvent(eventKey);
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("event definition is null or was not found in model service", ee.getMessage());
+ }
+
+ try {
+ new EnEvent((AxEvent) null);
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("event definition is null or was not found in model service", ee.getMessage());
+ }
+
+ AxEvent axEvent = new AxEvent(eventKey, "a.name.space", "some source", "some target");
+ ModelService.getModel(AxEvents.class).getEventMap().put(eventKey, axEvent);
+
+ EnEvent event = new EnEvent(eventKey);
+ assertEquals(eventKey, event.getKey());
+ assertEquals("Event:0.0.1", event.getId());
+ assertEquals("Event", event.getName());
+ assertEquals(axEvent, event.getAxEvent());
+ event.setExecutionId(123454321L);
+ assertEquals(123454321L, event.getExecutionId());
+ event.setExceptionMessage("Something happened");
+ assertEquals("Something happened", event.getExceptionMessage());
+ AxConcept[] usedArtifactStackArray =
+ { eventKey };
+ event.setUserArtifactStack(usedArtifactStackArray);
+ assertEquals(usedArtifactStackArray.length, event.getUserArtifactStack().length);
+ assertEquals("EnEvent [axEvent=AxEvent:(key=AxArtifactKey:(name=Event,version=0.0.1),nameSpace=a.name.space,"
+ + "source=some source,target=some target,parameter={}), "
+ + "userArtifactStack=[AxArtifactKey:(name=Event,version=0.0.1)], map={}]", event.toString());
+ try {
+ event.put(null, null);
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("null keys are illegal on method parameter \"key\"", ee.getMessage());
+ }
+
+ try {
+ event.put("NonField", null);
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("parameter with key \"NonField\" not defined on event \"Event\"", ee.getMessage());
+ }
+
+ AxReferenceKey fieldKey = new AxReferenceKey("Parent", "0.0.1", "MyParent", "MyField");
+ AxArtifactKey fieldSchemaKey = new AxArtifactKey("FieldSchema:0.0.1");
+ AxField axField = new AxField(fieldKey, fieldSchemaKey);
+
+ AxConcept[] usedArtifactStackArrayMultiple =
+ { eventKey, fieldKey, new DummyAxKey() };
+ event.setUserArtifactStack(usedArtifactStackArrayMultiple);
+
+ AxContextSchema schema = new AxContextSchema(fieldSchemaKey, "Java", "java.lang.Integer");
+ ModelService.getModel(AxContextSchemas.class).getSchemasMap().put(fieldSchemaKey, schema);
+
+ Map<String, AxField> parameterMap = new LinkedHashMap<>();
+ parameterMap.put("MyField", axField);
+ ModelService.getModel(AxEvents.class).get(eventKey).setParameterMap(parameterMap);
+
+ try {
+ event.put("MyField", null);
+ } catch (ContextRuntimeException cre) {
+ fail("test should throw an exception here");
+ }
+ assertNull(event.get("MyField"));
+
+ try {
+ event.put("MyField", "Hello");
+ fail("test should throw an exception here");
+ } catch (ContextRuntimeException cre) {
+ assertEquals("Parent:0.0.1:MyParent:MyField: object \"Hello\" of class \"java.lang.String\" "
+ + "not compatible with class \"java.lang.Integer\"", cre.getMessage());
+ }
+
+ event.put("MyField", 123);
+ assertEquals(123, event.get("MyField"));
+
+ assertTrue(event.keySet().contains("MyField"));
+ assertTrue(event.values().contains(123));
+ assertEquals("MyField", event.entrySet().iterator().next().getKey());
+
+ event.putAll(event);
+
+ try {
+ event.get(null);
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("null values are illegal on method parameter \"key\"", ee.getMessage());
+ }
+
+ try {
+ event.get("NonField");
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("parameter with key NonField not defined on this event", ee.getMessage());
+ }
+
+ try {
+ event.remove(null);
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("null keys are illegal on method parameter \"key\"", ee.getMessage());
+ }
+
+ try {
+ event.remove("NonField");
+ fail("test should throw an exception here");
+ } catch (EnException ee) {
+ assertEquals("parameter with key NonField not defined on this event", ee.getMessage());
+ }
+
+ event.remove("MyField");
+ assertNull(event.get("MyField"));
+
+ event.put("MyField", 123);
+ assertEquals(123, event.get("MyField"));
+ event.clear();
+ assertNull(event.get("MyField"));
+
+ assertTrue(event.hashCode() != 0);
+
+ assertTrue(event.equals(event));
+ assertFalse(event.equals(null));
+ Map<String, Object> hashMap = new HashMap<>();
+ assertFalse(event.equals(hashMap));
+
+ EnEvent otherEvent = new EnEvent(eventKey);
+ assertTrue(event.equals(otherEvent));
+ }
+}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java
new file mode 100644
index 000000000..ee54fd959
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine.event;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * Test the event exception class.
+ */
+public class EnExceptionTest {
+
+ @Test
+ public void testEnException() {
+ EnException ene = new EnException("Message");
+ assertEquals("Message", ene.getMessage());
+
+ ene = new EnException("Message", new IOException());
+ assertEquals("Message", ene.getMessage());
+ }
+}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java
new file mode 100644
index 000000000..6228c6834
--- /dev/null
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.core.engine.event;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.parameters.ContextParameterConstants;
+import org.onap.policy.apex.context.parameters.SchemaParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.service.ModelService;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.common.parameters.ParameterService;
+
+/**
+ * Test the EnField class.
+ */
+public class EnFieldTest {
+ /**
+ * Set up the services.
+ */
+ @Before
+ public void setupServices() {
+ AxContextSchemas schemas = new AxContextSchemas();
+ ModelService.registerModel(AxContextSchemas.class, schemas);
+ ParameterService.register(new SchemaParameters());
+ }
+
+ /**
+ * Tear down the services.
+ */
+ @After
+ public void teardownServices() {
+ ModelService.deregisterModel(AxContextSchemas.class);
+ ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ }
+
+ @Test
+ public void testEnField() {
+ AxReferenceKey fieldKey = new AxReferenceKey("Parent", "0.0.1", "MyParent", "MyField");
+ AxArtifactKey fieldSchemaKey = new AxArtifactKey("FieldSchema:0.0.1");
+ AxField axField = new AxField(fieldKey, fieldSchemaKey);
+
+ try {
+ new EnField(axField, null);
+ fail("test should throw an exception");
+ } catch (EnException ee) {
+ assertEquals("schema helper cannot be created for parameter with key \"Parent:0.0.1:MyParent:MyField\" "
+ + "with schema \"AxArtifactKey:(name=FieldSchema,version=0.0.1)\"", ee.getMessage());
+ }
+
+ AxContextSchema schema = new AxContextSchema(fieldSchemaKey, "Java", "java.lang.Integer");
+ ModelService.getModel(AxContextSchemas.class).getSchemasMap().put(fieldSchemaKey, schema);
+ EnField field = new EnField(axField, 123);
+
+ assertEquals(axField, field.getAxField());
+ assertEquals(123, field.getValue());
+ assertEquals(fieldKey, field.getKey());
+ assertEquals("MyField", field.getName());
+ assertEquals("org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelper",
+ field.getSchemaHelper().getClass().getCanonicalName());
+ assertEquals(123, field.getAssignableValue());
+ assertEquals("EnField [axField=AxField:(key=AxReferenceKey:(parentKeyName=Parent,parentKeyVersion=0.0.1,"
+ + "parentLocalName=MyParent,localName=MyField),fieldSchemaKey=AxArtifactKey:"
+ + "(name=FieldSchema,version=0.0.1),optional=false), value=123]", field.toString());
+ assertTrue(field.isAssignableValue());
+
+ field = new EnField(axField, "Hello");
+ assertFalse(field.isAssignableValue());
+ }
+}