aboutsummaryrefslogtreecommitdiffstats
path: root/context/context-management
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-10-04 07:06:41 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-10-04 16:44:57 +0100
commitb213e23edf68d36b4c0984d94d38d444f96949e2 (patch)
treebd7b60df8e8220abe93094fbbe373bc9c19791d0 /context/context-management
parent16a8f59fed2e53b1bbedaf65a33165bb4d3225f8 (diff)
Fix creation of sub Avro items
When an Avro object is created, nested sub avro objects are not created automatically. This change allows invocation of a method to create sub objects of Avro objects. Issue-ID: POLICY-954 Change-Id: Ie510867f2631ba6a8c6f5452c08aef5db67e8997 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'context/context-management')
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java8
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java9
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java1
-rw-r--r--context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperInstanceCreationTest.java8
4 files changed, 24 insertions, 2 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java
index 44ec06c6d..b6d21a20d 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java
@@ -92,6 +92,14 @@ public interface SchemaHelper {
Object createNewInstance(Object incomingObject);
/**
+ * Create an object of a sub type of this object.
+ *
+ * @param subType the sub type definition of this type
+ * @return a new object of the sub type
+ */
+ Object createNewSubInstance(String subType);
+
+ /**
* Unmarshal an object in schema format into a Java object.
*
* @param object the object as a Java object
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
index f50eb5914..6d98313ed 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
@@ -22,6 +22,7 @@ package org.onap.policy.apex.context.impl.schema;
import java.lang.reflect.Constructor;
+import org.apache.commons.lang3.NotImplementedException;
import org.onap.policy.apex.context.ContextRuntimeException;
import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -169,4 +170,12 @@ public abstract class AbstractSchemaHelper implements SchemaHelper {
throw new ContextRuntimeException(returnString);
}
}
+
+ /* (non-Javadoc)
+ * @see org.onap.policy.apex.context.SchemaHelper#createNewSubInstance(java.lang.String)
+ */
+ @Override
+ public Object createNewSubInstance(String subType) {
+ throw new NotImplementedException("sub types are not supported on this schema helper");
+ }
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
index 8b61f718a..fcc7c4d60 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
@@ -279,5 +279,4 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
return gsonBuilder.create();
}
-
}
diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperInstanceCreationTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperInstanceCreationTest.java
index 800a7011d..14d44ee8b 100644
--- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperInstanceCreationTest.java
+++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperInstanceCreationTest.java
@@ -96,7 +96,6 @@ public class JavaSchemaHelperInstanceCreationTest {
}
assertEquals(true, schemaHelper0.createNewInstance("true"));
-
try {
schemaHelper1.createNewInstance();
fail("this test should throw an exception here");
@@ -108,5 +107,12 @@ public class JavaSchemaHelperInstanceCreationTest {
assertEquals("", schemaHelper2.createNewInstance());
assertEquals("true", schemaHelper2.createNewInstance("true"));
+
+ try {
+ schemaHelper1.createNewSubInstance("SomeSubtype");
+ fail("this test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("sub types are not supported on this schema helper", e.getMessage());
+ }
}
}