diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-06-21 16:04:47 +0800 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-06-21 16:09:47 +0800 |
commit | 6dd2ac76d046e98104f4314ea0c529961ef3e35e (patch) | |
tree | af0614aa443e26d7bdd5003296229445a7da1f0d /context/context-management/src/main | |
parent | bb89ed3ad0765d323b6b026fc5fdd3b4a57fcc31 (diff) |
Add unit test for apex pdp context schema
Unit tests added for context schema handling in the APEX PDP.
Code coverage in the schema packages now above required limit.
Issue-ID: POLICY-857
Change-Id: I66ad6eb0e758f7a80492caae514875229c28924f
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'context/context-management/src/main')
3 files changed, 17 insertions, 10 deletions
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 83d1b6ba5..8acc03501 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 @@ -24,6 +24,7 @@ import java.lang.reflect.Constructor; import org.onap.policy.apex.context.ContextRuntimeException; import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; import org.onap.policy.apex.model.utilities.Assertions; @@ -41,7 +42,7 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { private static final XLogger LOGGER = XLoggerFactory.getXLogger(AbstractSchemaHelper.class); // The key of the user of this schema helper - private AxKey userKey = null; + private AxKey userKey = AxArtifactKey.getNullKey(); // The schema of this schema helper private AxContextSchema schema = null; diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java index 7252d3772..54689e3fb 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java @@ -51,8 +51,7 @@ public class SchemaHelperFactory { * @return a lock schema that can handle translation of objects in a particular schema format * @throws ContextRuntimeException the context runtime exception */ - public SchemaHelper createSchemaHelper(final AxKey owningEntityKey, final AxArtifactKey schemaKey) - throws ContextRuntimeException { + public SchemaHelper createSchemaHelper(final AxKey owningEntityKey, final AxArtifactKey schemaKey) { LOGGER.entry("schema helper factory, owningEntityKey=" + owningEntityKey); Assertions.argumentNotNull(owningEntityKey, ContextRuntimeException.class, "Parameter \"owningEntityKey\" may not be null"); @@ -69,12 +68,6 @@ public class SchemaHelperFactory { // Get the schema class using the parameter service final SchemaParameters schemaParameters = ParameterService.getParameters(SchemaParameters.class); - if (schemaParameters == null) { - final String resultString = "context schema parameters \"" + SchemaParameters.class.getCanonicalName() - + "\" not found in parameter service"; - LOGGER.warn(resultString); - throw new ContextRuntimeException(resultString); - } // Get the class for the schema helper from the schema parameters final SchemaHelperParameters schemaHelperParameters = 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 e5d92395a..a4bfe6978 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 @@ -98,7 +98,18 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { */ @Override public Object createNewInstance(final Object incomingObject) { - if (incomingObject instanceof JsonElement) { + if (incomingObject == null) { + return null; + } + + if (getSchemaClass() == null) { + final String returnString = + getUserKey().getID() + ": could not create an instance, schema class for the schema is null"; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + if (incomingObject instanceof JsonElement) { final String elementJsonString = new Gson().toJson((JsonElement) incomingObject); return new Gson().fromJson(elementJsonString, this.getSchemaClass()); } @@ -190,6 +201,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { if (object instanceof Number) { if (getSchemaClass().isAssignableFrom(Byte.class)) { return ((Number) object).byteValue(); + } else if (getSchemaClass().isAssignableFrom(Short.class)) { + return ((Number) object).shortValue(); } else if (getSchemaClass().isAssignableFrom(Integer.class)) { return ((Number) object).intValue(); } else if (getSchemaClass().isAssignableFrom(Long.class)) { |