summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-context/plugins-context-schema
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-context/plugins-context-schema')
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java6
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java14
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java13
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java47
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java4
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java2
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAai.java (renamed from plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java)24
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java38
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java33
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java61
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java16
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java139
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java117
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java42
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java64
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java40
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java47
17 files changed, 520 insertions, 187 deletions
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java
index 20e701bc7..bee2f5957 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java
@@ -43,7 +43,7 @@ public class AvroBytesObjectMapper implements AvroObjectMapper {
private Type avroType;
// The Apex compatible class
- private final Class<Byte[]> schemaClass = Byte[].class;
+ private static final Class<Byte[]> schemaClass = Byte[].class;
/*
* (non-Javadoc)
@@ -142,8 +142,6 @@ public class AvroBytesObjectMapper implements AvroObjectMapper {
}
// Create a ByteBuffer object to serialize the bytes
- final ByteBuffer byteBuffer = ByteBuffer.wrap((byte[]) object);
-
- return byteBuffer;
+ return ByteBuffer.wrap((byte[]) object);
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java
index 35e811dec..ca771d957 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java
@@ -132,7 +132,7 @@ public class AvroDirectObjectMapper implements AvroObjectMapper {
// the decoded object is always returned as a null
if (!schemaClass.isAssignableFrom(avroObject.getClass())) {
final String returnString =
- userKey.getId() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass()
+ userKey.getId() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass()
+ "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\"";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -150,13 +150,11 @@ public class AvroDirectObjectMapper implements AvroObjectMapper {
@Override
public Object mapToAvro(final Object object) {
// Null values are only allowed if the schema class is null
- if (object == null) {
- if (schemaClass != null) {
- final String returnString = userKey.getId() + ": cannot encode a null object of class \""
- + schemaClass.getCanonicalName() + "\"";
- LOGGER.warn(returnString);
- throw new ContextRuntimeException(returnString);
- }
+ if (object == null && schemaClass != null) {
+ final String returnString = userKey.getId() + ": cannot encode a null object of class \""
+ + schemaClass.getCanonicalName() + "\"";
+ LOGGER.warn(returnString);
+ throw new ContextRuntimeException(returnString);
}
// For direct mappings, just work directly with the Java objects
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java
index a48ca8089..21e4d76a8 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java
@@ -75,12 +75,12 @@ public class AvroObjectMapperFactory {
if (Schema.Type.UNION.equals(schema.getType())) {
final List<Schema> types = schema.getTypes();
- // TODO: properly support UNIONS
+
// currently only support unions with 2 types, one of which is NULL
final Schema nullschema = Schema.create(Schema.Type.NULL);
if (types.size() != 2 || !types.contains(nullschema)) {
final String resultSting = userKey.getId()
- + ": Apex currently only supports UNION schemas with 2 options, one must be NULL";
+ + ": Apex currently only supports UNION schemas with 2 options, one must be NULL";
LOGGER.warn(resultSting);
throw new ContextRuntimeException(resultSting);
}
@@ -92,7 +92,8 @@ public class AvroObjectMapperFactory {
}
if (Schema.Type.NULL.equals(schema.getType())) {
final String resultSting = userKey.getId()
- + ": Apex currently only supports UNION schema2 with 2 options, only one can be NULL, and the other cannot be another UNION";
+ + ": Apex currently only supports UNION schema2 with 2 options, "
+ + "only one can be NULL, and the other cannot be another UNION";
LOGGER.warn(resultSting);
throw new ContextRuntimeException(resultSting);
}
@@ -102,8 +103,8 @@ public class AvroObjectMapperFactory {
// Check that there is a definition for the mapper for this type
if (!AVRO_OBJECT_MAPPER_MAP.containsKey(avroType) || AVRO_OBJECT_MAPPER_MAP.get(avroType) == null) {
- final String resultSting =
- userKey.getId() + ": no Avro object mapper defined for Avro type \"" + avroType + "\"";
+ final String resultSting = userKey.getId() + ": no Avro object mapper defined for Avro type \"" + avroType
+ + "\"";
LOGGER.warn(resultSting);
throw new ContextRuntimeException(resultSting);
}
@@ -118,7 +119,7 @@ public class AvroObjectMapperFactory {
} catch (final Exception e) {
final String resultSting = userKey.getId() + ": could not create an Avro object mapper of type \""
- + AVRO_OBJECT_MAPPER_MAP.get(avroType) + "\" for Avro type \"" + avroType + "\" : " + e;
+ + AVRO_OBJECT_MAPPER_MAP.get(avroType) + "\" for Avro type \"" + avroType + "\" : " + e;
LOGGER.warn(resultSting, e);
throw new ContextRuntimeException(resultSting, e);
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
index df430b683..9cdb5845b 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
@@ -20,6 +20,10 @@
package org.onap.policy.apex.plugins.context.schema.avro;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+
import java.io.ByteArrayOutputStream;
import org.apache.avro.Schema;
@@ -38,13 +42,8 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-
/**
- * This class is the implementation of the {@link org.onap.policy.apex.context.SchemaHelper}
- * interface for Avro schemas.
+ * This class is the implementation of the {@link org.onap.policy.apex.context.SchemaHelper} interface for Avro schemas.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -52,6 +51,9 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
// Get a reference to the logger
private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroSchemaHelper.class);
+ // Recurring string constants
+ private static final String OBJECT_TAG = ": object \"";
+
// The Avro schema for this context schema
private Schema avroSchema;
@@ -59,7 +61,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
private AvroObjectMapper avroObjectMapper;
@Override
- public void init(final AxKey userKey, final AxContextSchema schema) throws ContextRuntimeException {
+ public void init(final AxKey userKey, final AxContextSchema schema) {
super.init(userKey, schema);
// Configure the Avro schema
@@ -67,7 +69,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
avroSchema = new Schema.Parser().parse(schema.getSchema());
} catch (final Exception e) {
final String resultSting = userKey.getId() + ": avro context schema \"" + schema.getId()
- + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema();
+ + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema();
LOGGER.warn(resultSting);
throw new ContextRuntimeException(resultSting);
}
@@ -91,7 +93,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
@Override
public Object getSchemaObject() {
- return avroSchema;
+ return getAvroSchema();
}
@Override
@@ -119,10 +121,9 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
final String elementJsonString = gson.toJson((JsonElement) incomingObject);
return createNewInstance(elementJsonString);
- }
- else {
+ } else {
final String returnString = getUserKey().getId() + ": the object \"" + incomingObject
- + "\" is not an instance of JsonObject";
+ + "\" is not an instance of JsonObject";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
@@ -146,8 +147,8 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
final JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(avroSchema, objectString);
decodedObject = new GenericDatumReader<GenericRecord>(avroSchema).read(null, jsonDecoder);
} catch (final Exception e) {
- final String returnString = getUserKey().getId() + ": object \"" + objectString
- + "\" Avro unmarshalling failed: " + e.getMessage();
+ final String returnString = getUserKey().getId() + OBJECT_TAG + objectString
+ + "\" Avro unmarshalling failed: " + e.getMessage();
LOGGER.warn(returnString, e);
throw new ContextRuntimeException(returnString, e);
}
@@ -157,8 +158,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
}
/**
- * Check that the incoming object is a string, the incoming object must be a string containing
- * Json
+ * Check that the incoming object is a string, the incoming object must be a string containing Json.
*
* @param object incoming object
* @return object as String
@@ -185,10 +185,10 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
return (String) object;
}
} catch (final ClassCastException e) {
- final String returnString = getUserKey().getId() + ": object \"" + object + "\" of type \""
- + (object != null ? object.getClass().getCanonicalName() : "null") + "\" must be assignable to \""
- + getSchemaClass().getCanonicalName()
- + "\" or be a Json string representation of it for Avro unmarshalling";
+ final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" of type \""
+ + (object != null ? object.getClass().getCanonicalName() : "null")
+ + "\" must be assignable to \"" + getSchemaClass().getCanonicalName()
+ + "\" or be a Json string representation of it for Avro unmarshalling";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
@@ -217,8 +217,8 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
jsonEncoder.flush();
return new String(output.toByteArray());
} catch (final Exception e) {
- final String returnString =
- getUserKey().getId() + ": object \"" + object + "\" Avro marshalling failed: " + e.getMessage();
+ final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" Avro marshalling failed: "
+ + e.getMessage();
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString, e);
}
@@ -239,8 +239,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
}
/**
- * Check if we can pass this object straight through encoding or decoding, is it an object
- * native to the schema.
+ * Check if we can pass this object straight through encoding or decoding, is it an object native to the schema.
*
* @param object the object to check
* @return true if it's a straight pass through
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java
index dc3770a43..b4c8737dd 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java
@@ -20,13 +20,13 @@
package org.onap.policy.apex.plugins.context.schema.avro;
-import java.util.Map.Entry;
-
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import java.util.Map.Entry;
+
/**
* This static final class contains utility methods for Avro schemas.
*
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java
index 09d1d9f1f..a9acb1c12 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java
@@ -42,7 +42,7 @@ public class AvroStringObjectMapper implements AvroObjectMapper {
private Type avroType;
// The Apex compatible class
- private final Class<String> schemaClass = String.class;
+ private static final Class<String> schemaClass = String.class;
/*
* (non-Javadoc)
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAai.java
index 5198e82e0..bca896d2e 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAai.java
@@ -42,14 +42,21 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaAai.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
-public class TestAvroSchemaAAI {
+public class TestAvroSchemaAai {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String aaiInventoryResponseSchema;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -59,6 +66,9 @@ public class TestAvroSchemaAAI {
TextFileUtils.getTextFileAsString("src/test/resources/avsc/AAIInventoryResponseItemType.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -68,13 +78,21 @@ public class TestAvroSchemaAAI {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test AAI response policy.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
- public void testAAIResponsePolicy() throws IOException {
+ public void testAaiResponsePolicy() throws IOException {
final AxContextSchema avroSchema =
new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", aaiInventoryResponseSchema);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java
index b72b2ca10..972e0bd32 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java
@@ -40,9 +40,12 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
+// TODO: Auto-generated Javadoc
/**
+ * The Class TestAvroSchemaArray.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
public class TestAvroSchemaArray {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
@@ -50,6 +53,11 @@ public class TestAvroSchemaArray {
private String longArraySchema;
private String addressArraySchema;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -58,6 +66,9 @@ public class TestAvroSchemaArray {
addressArraySchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/ArrayExampleAddress.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -67,11 +78,19 @@ public class TestAvroSchemaArray {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test array init.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testArrayInit() throws IOException {
final AxContextSchema avroSchema =
@@ -90,6 +109,11 @@ public class TestAvroSchemaArray {
newArrayFull.get(0).toString());
}
+ /**
+ * Test long array unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testLongArrayUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
@@ -102,6 +126,11 @@ public class TestAvroSchemaArray {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleLongFull.json");
}
+ /**
+ * Test address array unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testAddressArrayUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
@@ -114,6 +143,13 @@ public class TestAvroSchemaArray {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleAddressFull.json");
}
+ /**
+ * Test unmarshal marshal.
+ *
+ * @param schemaHelper the schema helper
+ * @param fileName the file name
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final Array<?> schemaObject = (Array<?>) schemaHelper.unmarshal(inString);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java
index 47a5c969c..883f14bcb 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java
@@ -41,15 +41,23 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
+// TODO: Auto-generated Javadoc
/**
+ * The Class TestAvroSchemaEnum.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
public class TestAvroSchemaEnum {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String enumSchema;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -57,6 +65,9 @@ public class TestAvroSchemaEnum {
enumSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/EnumSchema.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -66,11 +77,19 @@ public class TestAvroSchemaEnum {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test enum init.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testEnumInit() throws IOException {
final AxContextSchema avroSchema =
@@ -86,6 +105,11 @@ public class TestAvroSchemaEnum {
assertEquals("HEARTS", newEnumFull.toString());
}
+ /**
+ * Test enum unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testEnumUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
@@ -127,6 +151,13 @@ public class TestAvroSchemaEnum {
}
}
+ /**
+ * Test unmarshal marshal.
+ *
+ * @param schemaHelper the schema helper
+ * @param fileName the file name
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final EnumSymbol decodedObject = (EnumSymbol) schemaHelper.unmarshal(inString);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java
index 6d709645f..26f4ba8af 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java
@@ -43,6 +43,8 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaFixed.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
* @version
*/
@@ -51,6 +53,11 @@ public class TestAvroSchemaFixed {
private AxContextSchemas schemas;
private String fixedSchema;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -58,24 +65,35 @@ public class TestAvroSchemaFixed {
fixedSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/FixedSchema.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
ParameterService.register(schemaParameters);
-
+
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test fixed init.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFixedInit() throws IOException {
- final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", fixedSchema);
+ final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO",
+ fixedSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -84,9 +102,9 @@ public class TestAvroSchemaFixed {
schemaHelper.createNewInstance();
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertEquals(
- "AvroTest:0.0.1: could not create an instance of class \"org.apache.avro.generic.GenericData.Fixed\" using the default constructor \"Fixed()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance "
+ + "of class \"org.apache.avro.generic.GenericData.Fixed\" "
+ + "using the default constructor \"Fixed()\"", e.getMessage());
}
final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/FixedExampleGood.json");
@@ -95,10 +113,15 @@ public class TestAvroSchemaFixed {
assertTrue(newFixedFull.toString().endsWith("53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70]"));
}
+ /**
+ * Test fixed unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFixedUnmarshalMarshal() throws IOException {
- final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", fixedSchema);
+ final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO",
+ fixedSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -110,33 +133,39 @@ public class TestAvroSchemaFixed {
fail("This test should throw an exception here");
} catch (final Exception e) {
assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL",
- e.getMessage());
+ e.getMessage());
}
try {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json");
fail("This test should throw an exception here");
} catch (final Exception e) {
assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL",
- e.getMessage());
+ e.getMessage());
}
try {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json");
fail("This test should throw an exception here");
} catch (final Exception e) {
- assertEquals(
- "AvroTest:0.0.1: object \"\"BADBAD\"\" Avro unmarshalling failed: Expected fixed length 64, but got6",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: object \"\"BADBAD\"\" "
+ + "Avro unmarshalling failed: Expected fixed length 64, but got6", e.getMessage());
}
try {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json");
fail("This test should throw an exception here");
} catch (final Exception e) {
- assertEquals(
- "AvroTest:0.0.1: object \"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" Avro unmarshalling failed: Expected fixed length 64, but got65",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: object "
+ + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" "
+ + "Avro unmarshalling failed: Expected fixed length 64, but got65", e.getMessage());
}
}
+ /**
+ * Test unmarshal marshal.
+ *
+ * @param schemaHelper the schema helper
+ * @param fileName the file name
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final Fixed decodedObject = (Fixed) schemaHelper.unmarshal(inString);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java
index 9cb027acf..cc79f9eb6 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java
@@ -37,19 +37,27 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaHelperBadSchemas.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
public class TestAvroSchemaHelperBadSchemas {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
+ /**
+ * Inits the test.
+ */
@Before
public void initTest() {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -59,11 +67,17 @@ public class TestAvroSchemaHelperBadSchemas {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Bad schema test.
+ */
@Test
public void badSchemaTest() {
final AxContextSchema avroBadSchema0 = new AxContextSchema(new AxArtifactKey("AvroBad0", "0.0.1"), "AVRO", "}");
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java
index 1f078879d..86d8426de 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java
@@ -39,6 +39,8 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaHelperMarshal.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
* @version
*/
@@ -46,48 +48,63 @@ public class TestAvroSchemaHelperMarshal {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
+ /**
+ * Inits the test.
+ */
@Before
public void initTest() {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
ParameterService.register(schemaParameters);
-
+
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test null marshal.
+ */
@Test
public void testNullMarshal() {
- final AxContextSchema avroNullSchema =
- new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO", "{\"type\": \"null\"}");
+ final AxContextSchema avroNullSchema = new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO",
+ "{\"type\": \"null\"}");
schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema);
- final SchemaHelper schemaHelper0 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey());
+ final SchemaHelper schemaHelper0 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroNullSchema.getKey());
assertEquals("null", schemaHelper0.marshal2String(null));
assertEquals("null", schemaHelper0.marshal2String(123));
assertEquals("null", schemaHelper0.marshal2String("Everything is marshalled to Null, no matter what it is"));
}
+ /**
+ * Test boolean marshal.
+ */
@Test
public void testBooleanMarshal() {
- final AxContextSchema avroBooleanSchema =
- new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO", "{\"type\": \"boolean\"}");
+ final AxContextSchema avroBooleanSchema = new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO",
+ "{\"type\": \"boolean\"}");
schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema);
- final SchemaHelper schemaHelper1 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey());
+ final SchemaHelper schemaHelper1 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroBooleanSchema.getKey());
assertEquals("true", schemaHelper1.marshal2String(true));
assertEquals("false", schemaHelper1.marshal2String(false));
@@ -96,29 +113,30 @@ public class TestAvroSchemaHelperMarshal {
fail("Test should throw an exception here");
} catch (final Exception e) {
e.printStackTrace();
- assertEquals(
- "AvroTest:0.0.1: object \"0\" Avro marshalling failed: java.lang.Integer cannot be cast to java.lang.Boolean",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: "
+ + "java.lang.Integer cannot be cast to java.lang.Boolean", e.getMessage());
}
try {
schemaHelper1.marshal2String("0");
fail("Test should throw an exception here");
} catch (final Exception e) {
e.printStackTrace();
- assertEquals(
- "AvroTest:0.0.1: object \"0\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Boolean",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: "
+ + "java.lang.String cannot be cast to java.lang.Boolean", e.getMessage());
}
}
+ /**
+ * Test int marshal.
+ */
@Test
public void testIntMarshal() {
- final AxContextSchema avroIntSchema =
- new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO", "{\"type\": \"int\"}");
+ final AxContextSchema avroIntSchema = new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO",
+ "{\"type\": \"int\"}");
schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema);
- final SchemaHelper schemaHelper2 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey());
+ final SchemaHelper schemaHelper2 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroIntSchema.getKey());
assertEquals("0", schemaHelper2.marshal2String(0));
assertEquals("1", schemaHelper2.marshal2String(1));
@@ -131,26 +149,29 @@ public class TestAvroSchemaHelperMarshal {
schemaHelper2.marshal2String("Hello");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Number"));
+ assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "java.lang.String cannot be cast to java.lang.Number"));
}
try {
schemaHelper2.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\""));
+ .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\""));
}
}
+ /**
+ * Test long marshal.
+ */
@Test
public void testLongMarshal() {
- final AxContextSchema avroLongSchema =
- new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO", "{\"type\": \"long\"}");
+ final AxContextSchema avroLongSchema = new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO",
+ "{\"type\": \"long\"}");
schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema);
- final SchemaHelper schemaHelper3 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey());
+ final SchemaHelper schemaHelper3 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroLongSchema.getKey());
assertEquals("0", schemaHelper3.marshal2String(0L));
assertEquals("1", schemaHelper3.marshal2String(1L));
@@ -161,26 +182,29 @@ public class TestAvroSchemaHelperMarshal {
schemaHelper3.marshal2String("Hello");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Long"));
+ assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "java.lang.String cannot be cast to java.lang.Long"));
}
try {
schemaHelper3.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\""));
+ .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\""));
}
}
+ /**
+ * Test float marshal.
+ */
@Test
public void testFloatMarshal() {
- final AxContextSchema avroFloatSchema =
- new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO", "{\"type\": \"float\"}");
+ final AxContextSchema avroFloatSchema = new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO",
+ "{\"type\": \"float\"}");
schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema);
- final SchemaHelper schemaHelper4 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey());
+ final SchemaHelper schemaHelper4 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroFloatSchema.getKey());
assertEquals("0.0", schemaHelper4.marshal2String(0F));
assertEquals("1.0", schemaHelper4.marshal2String(1F));
@@ -195,27 +219,29 @@ public class TestAvroSchemaHelperMarshal {
schemaHelper4.marshal2String("Hello");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Float"));
+ assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "java.lang.String cannot be cast to java.lang.Float"));
}
try {
schemaHelper4.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\""));
+ .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\""));
}
}
-
+ /**
+ * Test double marshal.
+ */
@Test
public void testDoubleMarshal() {
- final AxContextSchema avroDoubleSchema =
- new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO", "{\"type\": \"double\"}");
+ final AxContextSchema avroDoubleSchema = new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO",
+ "{\"type\": \"double\"}");
schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema);
- final SchemaHelper schemaHelper5 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey());
+ final SchemaHelper schemaHelper5 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroDoubleSchema.getKey());
assertEquals("0.0", schemaHelper5.marshal2String(0D));
assertEquals("1.0", schemaHelper5.marshal2String(1D));
@@ -230,26 +256,29 @@ public class TestAvroSchemaHelperMarshal {
schemaHelper5.marshal2String("Hello");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Double"));
+ assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "java.lang.String cannot be cast to java.lang.Double"));
}
try {
schemaHelper5.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\""));
+ .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\""));
}
}
+ /**
+ * Test string marshal.
+ */
@Test
public void testStringMarshal() {
- final AxContextSchema avroStringSchema =
- new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"string\"}");
+ final AxContextSchema avroStringSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO",
+ "{\"type\": \"string\"}");
schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema);
- final SchemaHelper schemaHelper7 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey());
+ final SchemaHelper schemaHelper7 = new SchemaHelperFactory().createSchemaHelper(testKey,
+ avroStringSchema.getKey());
assertEquals("\"0\"", schemaHelper7.marshal2String("0"));
assertEquals("\"1\"", schemaHelper7.marshal2String("1"));
@@ -266,19 +295,23 @@ public class TestAvroSchemaHelperMarshal {
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\""));
+ .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\""));
}
}
+ /**
+ * Test bytes marshal.
+ */
@Test
public void testBytesMarshal() {
- final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"bytes\"}");
+ final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO",
+ "{\"type\": \"bytes\"}");
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
- final byte[] helloBytes = {104, 101, 108, 108, 111};
+ final byte[] helloBytes =
+ { 104, 101, 108, 108, 111 };
final String helloOut = schemaHelper.marshal2String(helloBytes);
assertEquals("\"hello\"", helloOut);
@@ -287,7 +320,7 @@ public class TestAvroSchemaHelperMarshal {
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Byte[]\""));
+ .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Byte[]\""));
}
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java
index db7edd673..6dede515e 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java
@@ -40,6 +40,8 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaHelperUnmarshal.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
* @version
*/
@@ -47,12 +49,18 @@ public class TestAvroSchemaHelperUnmarshal {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
+ /**
+ * Inits the test.
+ */
@Before
public void initTest() {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -62,11 +70,17 @@ public class TestAvroSchemaHelperUnmarshal {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test null unmarshal.
+ */
@Test
public void testNullUnmarshal() {
final AxContextSchema avroNullSchema = new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO",
@@ -90,11 +104,14 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper0.unmarshal("123");
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: Expected null. Got VALUE_NUMBER_INT",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: "
+ + "Expected null. Got VALUE_NUMBER_INT", e.getMessage());
}
}
+ /**
+ * Test boolean unmarshal.
+ */
@Test
public void testBooleanUnmarshal() {
final AxContextSchema avroBooleanSchema = new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO",
@@ -108,8 +125,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper1.createNewInstance();
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" using the default constructor \"Boolean()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" "
+ + "using the default constructor \"Boolean()\"", e.getMessage());
}
assertEquals(true, schemaHelper1.createNewInstance("true"));
@@ -125,6 +142,9 @@ public class TestAvroSchemaHelperUnmarshal {
}
}
+ /**
+ * Test int unmarshal.
+ */
@Test
public void testIntUnmarshal() {
final AxContextSchema avroIntSchema = new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO",
@@ -138,8 +158,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper2.createNewInstance();
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" using the default constructor \"Integer()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" "
+ + "using the default constructor \"Integer()\"", e.getMessage());
}
assertEquals(123, schemaHelper2.createNewInstance("123"));
@@ -154,25 +174,28 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper2.unmarshal("2147483648");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: Numeric value (2147483648) out of range of int"));
+ assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: "
+ + "Numeric value (2147483648) out of range of int"));
}
try {
schemaHelper2.unmarshal("-2147483649");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: Numeric value (-2147483649) out of range of int"));
+ assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: "
+ + "Numeric value (-2147483649) out of range of int"));
}
try {
schemaHelper2.unmarshal(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!"));
}
}
+ /**
+ * Test long unmarshal.
+ */
@Test
public void testLongUnmarshal() {
final AxContextSchema avroLongSchema = new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO",
@@ -186,8 +209,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper3.createNewInstance();
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" using the default constructor \"Long()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" "
+ + "using the default constructor \"Long()\"", e.getMessage());
}
assertEquals(123456789L, schemaHelper3.createNewInstance("123456789"));
@@ -202,32 +225,37 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper3.unmarshal("9223372036854775808");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: Numeric value (9223372036854775808) out of range of long"));
+ assertTrue(e.getMessage()
+ .startsWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: "
+ + "Numeric value (9223372036854775808) out of range of long"));
}
try {
schemaHelper3.unmarshal("-9223372036854775809");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: Numeric value (-9223372036854775809) out of range of long"));
+ assertTrue(e.getMessage()
+ .startsWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: "
+ + "Numeric value (-9223372036854775809) out of range of long"));
}
try {
schemaHelper3.unmarshal("\"Hello\"");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected long. Got VALUE_STRING"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
+ + "Expected long. Got VALUE_STRING"));
}
try {
schemaHelper3.unmarshal(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!"));
}
}
+ /**
+ * Test float unmarshal.
+ */
@Test
public void testFloatUnmarshal() {
final AxContextSchema avroFloatSchema = new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO",
@@ -241,8 +269,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper4.createNewInstance();
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" using the default constructor \"Float()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" "
+ + "using the default constructor \"Float()\"", e.getMessage());
}
assertEquals(1.2345F, schemaHelper4.createNewInstance("1.2345"));
@@ -259,18 +287,21 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper4.unmarshal("\"Hello\"");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected float. Got VALUE_STRING"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
+ + "Expected float. Got VALUE_STRING"));
}
try {
schemaHelper4.unmarshal(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!"));
}
}
+ /**
+ * Test double unmarshal.
+ */
@Test
public void testDoubleUnmarshal() {
final AxContextSchema avroDoubleSchema = new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO",
@@ -284,8 +315,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper5.createNewInstance();
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" using the default constructor \"Double()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" "
+ + "using the default constructor \"Double()\"", e.getMessage());
}
assertEquals(1.2345E06, schemaHelper5.createNewInstance("1.2345E06"));
@@ -302,18 +333,21 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper5.unmarshal("\"Hello\"");
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected double. Got VALUE_STRING"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
+ + "Expected double. Got VALUE_STRING"));
}
try {
schemaHelper5.unmarshal(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!"));
}
}
+ /**
+ * Test string unmarshal.
+ */
@Test
public void testStringUnmarshal() {
final AxContextSchema avroStringSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO",
@@ -341,11 +375,14 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper7.unmarshal(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!"));
}
}
+ /**
+ * Test bytes unmarshal.
+ */
@Test
public void testBytesUnmarshal() {
final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO",
@@ -358,8 +395,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper.createNewInstance();
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Byte[]\" using the default constructor \"Byte[]()\"",
- e.getMessage());
+ assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Byte[]\" "
+ + "using the default constructor \"Byte[]()\"", e.getMessage());
}
final byte[] newBytes = (byte[]) schemaHelper.createNewInstance("\"hello\"");
assertEquals(5, newBytes.length);
@@ -373,8 +410,8 @@ public class TestAvroSchemaHelperUnmarshal {
schemaHelper.unmarshal(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().equals(
- "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!"));
+ assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!"));
}
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java
index 7bf6b0029..9bc87cf61 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java
@@ -43,8 +43,10 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaMap.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
public class TestAvroSchemaMap {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
@@ -53,6 +55,11 @@ public class TestAvroSchemaMap {
private String addressMapSchema;
private String addressMapSchemaInvalidFields;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -63,6 +70,9 @@ public class TestAvroSchemaMap {
TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddressInvalidFields.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -72,11 +82,19 @@ public class TestAvroSchemaMap {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test map init.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testMapInit() throws IOException {
final AxContextSchema avroSchema =
@@ -95,6 +113,11 @@ public class TestAvroSchemaMap {
newMapFull.get(new Utf8("address2")).toString());
}
+ /**
+ * Test long map unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testLongMapUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
@@ -107,6 +130,11 @@ public class TestAvroSchemaMap {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleLongFull.json");
}
+ /**
+ * Test address map unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testAddressMapUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
@@ -119,6 +147,11 @@ public class TestAvroSchemaMap {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressFull.json");
}
+ /**
+ * Test address map unmarshal marshal invalid fields.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testAddressMapUnmarshalMarshalInvalidFields() throws IOException {
final AxContextSchema avroSchema =
@@ -130,6 +163,13 @@ public class TestAvroSchemaMap {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressInvalidFields.json");
}
+ /**
+ * Test unmarshal marshal.
+ *
+ * @param schemaHelper the schema helper
+ * @param fileName the file name
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String originalInString = TextFileUtils.getTextFileAsString(fileName);
final HashMap<?, ?> firstDecodedMap = (HashMap<?, ?>) schemaHelper.unmarshal(originalInString);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java
index 000dcc9fd..6b1d09eb6 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java
@@ -40,29 +40,40 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
+// TODO: Auto-generated Javadoc
/**
+ * The Class TestAvroSchemaRecord.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
public class TestAvroSchemaRecord {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String recordSchema;
- private String recordSchemaVPN;
- private String recordSchemaVPNReuse;
+ private String recordSchemaVpn;
+ private String recordSchemaVpnReuse;
private String recordSchemaInvalidFields;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
recordSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExample.avsc");
- recordSchemaVPN = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPN.avsc");
- recordSchemaVPNReuse = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPNReuse.avsc");
+ recordSchemaVpn = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPN.avsc");
+ recordSchemaVpnReuse = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPNReuse.avsc");
recordSchemaInvalidFields =
TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleInvalidFields.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -72,11 +83,19 @@ public class TestAvroSchemaRecord {
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test record init.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testRecordInit() throws IOException {
final AxContextSchema avroSchema =
@@ -93,6 +112,11 @@ public class TestAvroSchemaRecord {
assertEquals("gobbledygook", newRecordFull.get("passwordHash").toString());
}
+ /**
+ * Test record unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testRecordUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
@@ -105,6 +129,11 @@ public class TestAvroSchemaRecord {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleFull.json");
}
+ /**
+ * Test record unmarshal marshal invalid.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testRecordUnmarshalMarshalInvalid() throws IOException {
final AxContextSchema avroSchema =
@@ -116,10 +145,15 @@ public class TestAvroSchemaRecord {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleInvalidFields.json");
}
+ /**
+ * Test VPN record unmarshal marshal.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
- public void testVPNRecordUnmarshalMarshal() throws IOException {
+ public void testVpnRecordUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVPN);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVpn);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -127,16 +161,28 @@ public class TestAvroSchemaRecord {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleVPNFull.json");
}
+ /**
+ * Test VPN record reuse.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
- public void testVPNRecordReuse() throws IOException {
+ public void testVpnRecordReuse() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVPNReuse);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVpnReuse);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
}
+ /**
+ * Test unmarshal marshal.
+ *
+ * @param schemaHelper the schema helper
+ * @param fileName the file name
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java
index 33cb20328..c957d8d4c 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java
@@ -42,14 +42,21 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestAvroSchemaUnion.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
+ * @version
*/
public class TestAvroSchemaUnion {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String uinionSchema;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -57,25 +64,36 @@ public class TestAvroSchemaUnion {
uinionSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/UnionExample.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
ParameterService.register(schemaParameters);
-
+
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test union all fields.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Ignore
@Test
public void testUnionAllFields() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", uinionSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", uinionSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -88,17 +106,22 @@ public class TestAvroSchemaUnion {
assertEquals("red", user.get("favourite_colour").toString());
}
+ /**
+ * Test union optional field.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Ignore
@Test
public void testUnionOptionalField() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", uinionSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", uinionSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
final String inString =
- TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleOptionalField.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleOptionalField.json");
final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString);
assertEquals("Ben", user.get("name").toString());
@@ -106,11 +129,16 @@ public class TestAvroSchemaUnion {
assertEquals("red", user.get("favourite_colour").toString());
}
+ /**
+ * Test union null field.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Ignore
@Test
public void testUnionNullField() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", uinionSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", uinionSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java
index 42764a1ca..646b8aa04 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java
@@ -44,6 +44,8 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.common.parameters.ParameterService;
/**
+ * The Class TestHealthCheckSchema.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class TestHealthCheckSchema {
@@ -51,6 +53,11 @@ public class TestHealthCheckSchema {
private AxContextSchemas schemas;
private String healthCheckSchema;
+ /**
+ * Inits the test.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Before
public void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
@@ -59,24 +66,35 @@ public class TestHealthCheckSchema {
healthCheckSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/HealthCheckBodyType.avsc");
}
+ /**
+ * Inits the context.
+ */
@Before
public void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
ParameterService.register(schemaParameters);
-
+
}
+ /**
+ * Clear context.
+ */
@After
public void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
+ /**
+ * Test health check.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testHealthCheck() throws IOException {
- final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", healthCheckSchema);
+ final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO",
+ healthCheckSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -89,15 +107,15 @@ public class TestHealthCheckSchema {
final GenericRecord inputRecord = new GenericData.Record(healthCheckRecordSchema.getField("input").schema());
final Schema inputRecordRecordSchema = inputRecord.getSchema();
- final GenericRecord actionIndentifiersRecord =
- new GenericData.Record(inputRecordRecordSchema.getField("action_DasH_identifiers").schema());
+ final GenericRecord actionIndentifiersRecord = new GenericData.Record(
+ inputRecordRecordSchema.getField("action_DasH_identifiers").schema());
- final GenericRecord commonHeaderRecord =
- new GenericData.Record(inputRecordRecordSchema.getField("common_DasH_header").schema());
+ final GenericRecord commonHeaderRecord = new GenericData.Record(
+ inputRecordRecordSchema.getField("common_DasH_header").schema());
final Schema commonHeaderRecordSchema = commonHeaderRecord.getSchema();
- final GenericRecord commonHeaderFlagsRecord =
- new GenericData.Record(commonHeaderRecordSchema.getField("flags").schema());
+ final GenericRecord commonHeaderFlagsRecord = new GenericData.Record(
+ commonHeaderRecordSchema.getField("flags").schema());
healthCheckRecord.put("input", inputRecord);
inputRecord.put("action_DasH_identifiers", actionIndentifiersRecord);
@@ -105,8 +123,8 @@ public class TestHealthCheckSchema {
commonHeaderRecord.put("flags", commonHeaderFlagsRecord);
inputRecord.put("action", "HealthCheck");
- inputRecord.put("payload",
- "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\",\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}");
+ inputRecord.put("payload", "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\","
+ + "\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}");
actionIndentifiersRecord.put("vnf_DasH_id", "49414df5-3482-4fd8-9952-c463dff2770b");
@@ -125,6 +143,13 @@ public class TestHealthCheckSchema {
assertEquals(eventString.toString().replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
}
+ /**
+ * Test unmarshal marshal.
+ *
+ * @param schemaHelper the schema helper
+ * @param fileName the file name
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString);