aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/SchemaHelper.java16
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java44
-rw-r--r--model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java1
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java22
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java116
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java4
-rw-r--r--plugins/plugins-context/context-schema/pom.xml2
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java2
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java42
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml50
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java387
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java204
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/package-info.java27
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlEventProtocol.java263
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlPluginStability.java259
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection0.yaml3
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection1.yaml3
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection2.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection3.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection4.yaml3
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection5.yaml5
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty0.yaml0
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty1.yaml4
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure0.yaml10
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure1.yaml10
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure2.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure3.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure4.yaml7
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure5.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/TOSCA0.yaml180
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection0_0.yaml9
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection1_0.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection2_0.yaml13
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection3_0.yaml12
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection4_0.yaml15
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection5_0.yaml11
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Empty1_0.yaml5
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_0.yaml9
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_1.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_0.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_1.yaml8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure2_0.yaml11
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure3_0.yaml11
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure4_0.yaml11
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure5_0.yaml12
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/TOSCA0_0.yaml188
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java3
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java78
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java188
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java54
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java2
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java84
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java2
58 files changed, 2204 insertions, 260 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 aa6ea9ffe..30af48195 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
@@ -20,8 +20,6 @@
package org.onap.policy.apex.context;
-import com.google.gson.JsonElement;
-
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
@@ -86,12 +84,12 @@ public interface SchemaHelper {
Object createNewInstance(String stringValue);
/**
- * Create a new instance of the schema class from a GSON JsonElement using whatever schema technology is being used.
+ * Create a new instance of the schema class from an object using whatever schema technology is being used.
*
- * @param jsonElement the JSON element that holds the Json representation of the object
+ * @param incomingObject the incoming object that holds the raw representation of the object to be created
* @return the new instance
*/
- Object createNewInstance(JsonElement jsonElement);
+ Object createNewInstance(Object incomingObject);
/**
* Unmarshal an object in schema format into a Java object.
@@ -107,13 +105,13 @@ public interface SchemaHelper {
* @param schemaObject the object in schema format
* @return the object as a Json string
*/
- String marshal2Json(Object schemaObject);
+ String marshal2String(Object schemaObject);
/**
- * Marshal a Java object into a GSON json element.
+ * Marshal a Java object into an output object of an arbitrary type.
*
* @param schemaObject the object in schema format
- * @return the object as a GSON Json element
+ * @return the object as output object of an arbitrary type
*/
- JsonElement marshal2JsonElement(Object schemaObject);
+ Object marshal2Object(Object schemaObject);
}
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 b89efbf91..e5d92395a 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
@@ -49,7 +49,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
// This map defines the built in types in types in Java
// @formatter:off
private static final Map<String, Class<?>> BUILT_IN_MAP = new HashMap<>();
- {
+ static {
BUILT_IN_MAP.put("int", Integer .TYPE);
BUILT_IN_MAP.put("long", Long .TYPE);
BUILT_IN_MAP.put("double", Double .TYPE);
@@ -69,7 +69,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
* concepts. AxKey, org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema)
*/
@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);
final String javatype = schema.getSchema();
@@ -80,7 +80,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
} catch (final IllegalArgumentException e) {
String resultSting = userKey.getID() + ": class/type " + schema.getSchema() + " for context schema \""
- + schema.getID() + "\" not found.";
+ + schema.getID() + "\" not found.";
if (JavaSchemaHelper.BUILT_IN_MAP.get(javatype) != null) {
resultSting += " Primitive types are not supported. Use the appropriate Java boxing type instead.";
} else {
@@ -94,13 +94,25 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
/*
* (non-Javadoc)
*
- * @see org.onap.policy.apex.context.SchemaHelper#createNewInstance(com.google.gson.JsonElement)
+ * @see org.onap.policy.apex.context.SchemaHelper#createNewInstance(java.lang.Object)
*/
@Override
- public Object createNewInstance(final JsonElement jsonElement) {
- final String elementJsonString = new Gson().toJson(jsonElement);
+ public Object createNewInstance(final Object incomingObject) {
+ if (incomingObject instanceof JsonElement) {
+ final String elementJsonString = new Gson().toJson((JsonElement) incomingObject);
+ return new Gson().fromJson(elementJsonString, this.getSchemaClass());
+ }
+
+ if (getSchemaClass().isAssignableFrom(incomingObject.getClass())) {
+ return incomingObject;
+ }
- return new Gson().fromJson(elementJsonString, this.getSchemaClass());
+ final String returnString = getUserKey().getID() + ": the object \"" + incomingObject + "\" of type \""
+ + incomingObject.getClass().getCanonicalName()
+ + "\" is not an instance of JsonObject and is not assignable to \""
+ + getSchemaClass().getCanonicalName() + "\"";
+ LOGGER.warn(returnString);
+ throw new ContextRuntimeException(returnString);
}
/*
@@ -137,7 +149,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
* @see org.onap.policy.apex.context.SchemaHelper#schemaObject2Json(java.lang.Object)
*/
@Override
- public String marshal2Json(final Object schemaObject) {
+ public String marshal2String(final Object schemaObject) {
if (schemaObject == null) {
return "null";
}
@@ -148,8 +160,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
return new Gson().toJson(schemaObject);
} else {
final String returnString = getUserKey().getID() + ": object \"" + schemaObject.toString()
- + "\" of class \"" + schemaObject.getClass().getCanonicalName() + "\" not compatible with class \""
- + getSchemaClass().getCanonicalName() + "\"";
+ + "\" of class \"" + schemaObject.getClass().getCanonicalName()
+ + "\" not compatible with class \"" + getSchemaClass().getCanonicalName() + "\"";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
@@ -161,7 +173,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
* @see org.onap.policy.apex.context.SchemaHelper#marshal2JsonElement(java.lang.Object)
*/
@Override
- public JsonElement marshal2JsonElement(final Object schemaObject) {
+ public Object marshal2Object(final Object schemaObject) {
// Use Gson to marshal the schema object into a Json element to return
return new Gson().toJsonTree(schemaObject, getSchemaClass());
}
@@ -169,7 +181,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
/**
* Do a numeric conversion between numeric types.
*
- * @param object The incoming numeric object
+ * @param object
+ * The incoming numeric object
* @return The converted object
*/
private Object numericConversion(final Object object) {
@@ -195,7 +208,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
/**
* Do a string conversion to the class type.
*
- * @param object The incoming numeric object
+ * @param object
+ * The incoming numeric object
* @return The converted object
*/
private Object stringConversion(final Object object) {
@@ -205,8 +219,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
return stringConstructor.newInstance(object.toString());
} catch (final Exception e) {
final String returnString = getUserKey().getID() + ": object \"" + object.toString() + "\" of class \""
- + object.getClass().getCanonicalName() + "\" not compatible with class \""
- + getSchemaClass().getCanonicalName() + "\"";
+ + object.getClass().getCanonicalName() + "\" not compatible with class \""
+ + getSchemaClass().getCanonicalName() + "\"";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java
index e806bd7a0..b4f9d2f75 100644
--- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java
+++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java
@@ -36,7 +36,6 @@ import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
* <a href="https://github.com/KetothXupack/stackoverflow-answers/tree/master/q39401083">
* https://github.com/KetothXupack/stackoverflow-answers/tree/master/q39401083</a><br>
*/
-@SuppressWarnings("restriction")
public class ClassBuilder {
private final Class<?> clazz;
private final List<ClassBuilder> parameters = new ArrayList<>();
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
index b4cc38602..5fba274ce 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
@@ -113,11 +113,19 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
}
@Override
- public Object createNewInstance(final JsonElement jsonElement) {
- final Gson gson = new GsonBuilder().serializeNulls().create();
- final String elementJsonString = gson.toJson(jsonElement);
+ public Object createNewInstance(final Object incomingObject) {
+ if (incomingObject instanceof JsonElement) {
+ final Gson gson = new GsonBuilder().serializeNulls().create();
+ final String elementJsonString = gson.toJson((JsonElement) incomingObject);
- return createNewInstance(elementJsonString);
+ return createNewInstance(elementJsonString);
+ }
+ else {
+ final String returnString = getUserKey().getID() + ": the object \"" + incomingObject
+ + "\" is not an instance of JsonObject";
+ LOGGER.warn(returnString);
+ throw new ContextRuntimeException(returnString);
+ }
}
@Override
@@ -191,7 +199,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
}
@Override
- public String marshal2Json(final Object object) {
+ public String marshal2String(final Object object) {
// Condition the object for Avro encoding
final Object conditionedObject = avroObjectMapper.mapToAvro(object);
@@ -217,9 +225,9 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
}
@Override
- public JsonElement marshal2JsonElement(final Object schemaObject) {
+ public JsonElement marshal2Object(final Object schemaObject) {
// Get the object as a Json string
- final String schemaObjectAsString = marshal2Json(schemaObject);
+ final String schemaObjectAsString = marshal2String(schemaObject);
// Get a Gson instance to convert the Json string to an object created by Json
final Gson gson = new Gson();
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java
index dc65c108d..21fab66d9 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java
@@ -101,7 +101,7 @@ public class TestAvroSchemaArray {
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final Array<?> schemaObject = (Array<?>) schemaHelper.unmarshal(inString);
- final String outString = schemaHelper.marshal2Json(schemaObject);
+ final String outString = schemaHelper.marshal2String(schemaObject);
assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
}
}
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java
index 0302345b3..ae19cd31a 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java
@@ -114,7 +114,7 @@ public class TestAvroSchemaEnum {
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final EnumSymbol decodedObject = (EnumSymbol) schemaHelper.unmarshal(inString);
- final String outString = schemaHelper.marshal2Json(decodedObject);
+ final String outString = schemaHelper.marshal2String(decodedObject);
assertEquals(inString.replaceAll("[\\r?\\n]+", " "), outString.replaceAll("[\\r?\\n]+", " "));
}
}
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java
index f4906e5df..41f622115 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java
@@ -124,7 +124,7 @@ public class TestAvroSchemaFixed {
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final Fixed decodedObject = (Fixed) schemaHelper.unmarshal(inString);
- final String outString = schemaHelper.marshal2Json(decodedObject);
+ final String outString = schemaHelper.marshal2String(decodedObject);
assertEquals(inString.replaceAll("[\\r?\\n]+", " "), outString.replaceAll("[\\r?\\n]+", " "));
}
}
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java
index 1b35d8275..a710a2376 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java
@@ -59,9 +59,9 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper0 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey());
- assertEquals("null", schemaHelper0.marshal2Json(null));
- assertEquals("null", schemaHelper0.marshal2Json(123));
- assertEquals("null", schemaHelper0.marshal2Json("Everything is marshalled to Null, no matter what it is"));
+ 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
@@ -73,10 +73,10 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper1 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey());
- assertEquals("true", schemaHelper1.marshal2Json(true));
- assertEquals("false", schemaHelper1.marshal2Json(false));
+ assertEquals("true", schemaHelper1.marshal2String(true));
+ assertEquals("false", schemaHelper1.marshal2String(false));
try {
- schemaHelper1.marshal2Json(0);
+ schemaHelper1.marshal2String(0);
fail("Test should throw an exception here");
} catch (final Exception e) {
e.printStackTrace();
@@ -85,7 +85,7 @@ public class TestAvroSchemaHelperMarshal {
e.getMessage());
}
try {
- schemaHelper1.marshal2Json("0");
+ schemaHelper1.marshal2String("0");
fail("Test should throw an exception here");
} catch (final Exception e) {
e.printStackTrace();
@@ -104,22 +104,22 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper2 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey());
- assertEquals("0", schemaHelper2.marshal2Json(0));
- assertEquals("1", schemaHelper2.marshal2Json(1));
- assertEquals("-1", schemaHelper2.marshal2Json(-1));
- assertEquals("1", schemaHelper2.marshal2Json(1.23));
- assertEquals("-1", schemaHelper2.marshal2Json(-1.23));
- assertEquals("2147483647", schemaHelper2.marshal2Json(2147483647));
- assertEquals("-2147483648", schemaHelper2.marshal2Json(-2147483648));
+ assertEquals("0", schemaHelper2.marshal2String(0));
+ assertEquals("1", schemaHelper2.marshal2String(1));
+ assertEquals("-1", schemaHelper2.marshal2String(-1));
+ assertEquals("1", schemaHelper2.marshal2String(1.23));
+ assertEquals("-1", schemaHelper2.marshal2String(-1.23));
+ assertEquals("2147483647", schemaHelper2.marshal2String(2147483647));
+ assertEquals("-2147483648", schemaHelper2.marshal2String(-2147483648));
try {
- schemaHelper2.marshal2Json("Hello");
+ 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"));
}
try {
- schemaHelper2.marshal2Json(null);
+ schemaHelper2.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
@@ -136,20 +136,20 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper3 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey());
- assertEquals("0", schemaHelper3.marshal2Json(0L));
- assertEquals("1", schemaHelper3.marshal2Json(1L));
- assertEquals("-1", schemaHelper3.marshal2Json(-1L));
- assertEquals("9223372036854775807", schemaHelper3.marshal2Json(9223372036854775807L));
- assertEquals("-9223372036854775808", schemaHelper3.marshal2Json(-9223372036854775808L));
+ assertEquals("0", schemaHelper3.marshal2String(0L));
+ assertEquals("1", schemaHelper3.marshal2String(1L));
+ assertEquals("-1", schemaHelper3.marshal2String(-1L));
+ assertEquals("9223372036854775807", schemaHelper3.marshal2String(9223372036854775807L));
+ assertEquals("-9223372036854775808", schemaHelper3.marshal2String(-9223372036854775808L));
try {
- schemaHelper3.marshal2Json("Hello");
+ 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"));
}
try {
- schemaHelper3.marshal2Json(null);
+ schemaHelper3.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
@@ -166,24 +166,24 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper4 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey());
- assertEquals("0.0", schemaHelper4.marshal2Json(0F));
- assertEquals("1.0", schemaHelper4.marshal2Json(1F));
- assertEquals("-1.0", schemaHelper4.marshal2Json(-1F));
- assertEquals("1.23", schemaHelper4.marshal2Json(1.23F));
- assertEquals("-1.23", schemaHelper4.marshal2Json(-1.23F));
- assertEquals("9.223372E18", schemaHelper4.marshal2Json(9.223372E18F));
- assertEquals("-9.223372E18", schemaHelper4.marshal2Json(-9.223372E18F));
- assertEquals("9.223372E18", schemaHelper4.marshal2Json(9.223372E18F));
- assertEquals("-9.223372E18", schemaHelper4.marshal2Json(-9.223372E18F));
+ assertEquals("0.0", schemaHelper4.marshal2String(0F));
+ assertEquals("1.0", schemaHelper4.marshal2String(1F));
+ assertEquals("-1.0", schemaHelper4.marshal2String(-1F));
+ assertEquals("1.23", schemaHelper4.marshal2String(1.23F));
+ assertEquals("-1.23", schemaHelper4.marshal2String(-1.23F));
+ assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F));
+ assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F));
+ assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F));
+ assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F));
try {
- schemaHelper4.marshal2Json("Hello");
+ 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"));
}
try {
- schemaHelper4.marshal2Json(null);
+ schemaHelper4.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
@@ -201,24 +201,24 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper5 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey());
- assertEquals("0.0", schemaHelper5.marshal2Json(0D));
- assertEquals("1.0", schemaHelper5.marshal2Json(1D));
- assertEquals("-1.0", schemaHelper5.marshal2Json(-1D));
- assertEquals("1.23", schemaHelper5.marshal2Json(1.23));
- assertEquals("-1.23", schemaHelper5.marshal2Json(-1.23));
- assertEquals("9.223372036854776E18", schemaHelper5.marshal2Json(9.223372036854776E18));
- assertEquals("-9.223372036854776E18", schemaHelper5.marshal2Json(-9.223372036854776E18));
- assertEquals("9.223372036854776E18", schemaHelper5.marshal2Json(9.223372036854776E18));
- assertEquals("-9.223372036854776E18", schemaHelper5.marshal2Json(-9.223372036854776E18));
+ assertEquals("0.0", schemaHelper5.marshal2String(0D));
+ assertEquals("1.0", schemaHelper5.marshal2String(1D));
+ assertEquals("-1.0", schemaHelper5.marshal2String(-1D));
+ assertEquals("1.23", schemaHelper5.marshal2String(1.23));
+ assertEquals("-1.23", schemaHelper5.marshal2String(-1.23));
+ assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18));
+ assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18));
+ assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18));
+ assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18));
try {
- schemaHelper5.marshal2Json("Hello");
+ 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"));
}
try {
- schemaHelper5.marshal2Json(null);
+ schemaHelper5.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
@@ -235,18 +235,18 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper7 =
new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey());
- assertEquals("\"0\"", schemaHelper7.marshal2Json("0"));
- assertEquals("\"1\"", schemaHelper7.marshal2Json("1"));
- assertEquals("\"-1\"", schemaHelper7.marshal2Json("-1"));
- assertEquals("\"1.23\"", schemaHelper7.marshal2Json("1.23"));
- assertEquals("\"-1.23\"", schemaHelper7.marshal2Json("-1.23"));
- assertEquals("\"9223372036854775807\"", schemaHelper7.marshal2Json("9223372036854775807"));
- assertEquals("\"-9223372036854775808\"", schemaHelper7.marshal2Json("-9223372036854775808"));
- assertEquals("\"9223372036854775808\"", schemaHelper7.marshal2Json("9223372036854775808"));
- assertEquals("\"-9223372036854775809\"", schemaHelper7.marshal2Json("-9223372036854775809"));
- assertEquals("\"Hello\"", schemaHelper7.marshal2Json("Hello"));
+ assertEquals("\"0\"", schemaHelper7.marshal2String("0"));
+ assertEquals("\"1\"", schemaHelper7.marshal2String("1"));
+ assertEquals("\"-1\"", schemaHelper7.marshal2String("-1"));
+ assertEquals("\"1.23\"", schemaHelper7.marshal2String("1.23"));
+ assertEquals("\"-1.23\"", schemaHelper7.marshal2String("-1.23"));
+ assertEquals("\"9223372036854775807\"", schemaHelper7.marshal2String("9223372036854775807"));
+ assertEquals("\"-9223372036854775808\"", schemaHelper7.marshal2String("-9223372036854775808"));
+ assertEquals("\"9223372036854775808\"", schemaHelper7.marshal2String("9223372036854775808"));
+ assertEquals("\"-9223372036854775809\"", schemaHelper7.marshal2String("-9223372036854775809"));
+ assertEquals("\"Hello\"", schemaHelper7.marshal2String("Hello"));
try {
- schemaHelper7.marshal2Json(null);
+ schemaHelper7.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
@@ -263,11 +263,11 @@ public class TestAvroSchemaHelperMarshal {
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
final byte[] helloBytes = {104, 101, 108, 108, 111};
- final String helloOut = schemaHelper.marshal2Json(helloBytes);
+ final String helloOut = schemaHelper.marshal2String(helloBytes);
assertEquals("\"hello\"", helloOut);
try {
- schemaHelper.marshal2Json(null);
+ schemaHelper.marshal2String(null);
fail("Test should throw an exception here");
} catch (final Exception e) {
assertTrue(e.getMessage()
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java
index 74591bb99..33ca512b9 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java
@@ -118,7 +118,7 @@ public class TestAvroSchemaMap {
final String originalInString = TextFileUtils.getTextFileAsString(fileName);
final HashMap<?, ?> firstDecodedMap = (HashMap<?, ?>) schemaHelper.unmarshal(originalInString);
- final String outString = schemaHelper.marshal2Json(firstDecodedMap);
+ final String outString = schemaHelper.marshal2String(firstDecodedMap);
final File tempOutFile = File.createTempFile("ApexAvro", ".json");
TextFileUtils.putStringAsFile(outString, tempOutFile);
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java
index b793ef0ae..e14236064 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java
@@ -124,7 +124,7 @@ public class TestAvroSchemaRecord {
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString);
- final String outString = schemaHelper.marshal2Json(decodedObject);
+ final String outString = schemaHelper.marshal2String(decodedObject);
assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
}
}
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java
index c32d9b3d4..026125af9 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java
@@ -106,14 +106,14 @@ public class TestHealthCheckSchema {
commonHeaderFlagsRecord.put("mode", "EXCLUSIVE");
final String eventString = TextFileUtils.getTextFileAsString("src/test/resources/data/HealthCheckEvent.json");
- final String outString = schemaHelper.marshal2Json(healthCheckRecord);
+ final String outString = schemaHelper.marshal2String(healthCheckRecord);
assertEquals(eventString.toString().replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
}
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
final String inString = TextFileUtils.getTextFileAsString(fileName);
final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString);
- final String outString = schemaHelper.marshal2Json(decodedObject);
+ final String outString = schemaHelper.marshal2String(decodedObject);
assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
}
}
diff --git a/plugins/plugins-context/context-schema/pom.xml b/plugins/plugins-context/context-schema/pom.xml
index f72ec1583..d60cb5570 100644
--- a/plugins/plugins-context/context-schema/pom.xml
+++ b/plugins/plugins-context/context-schema/pom.xml
@@ -35,4 +35,4 @@
<modules>
<module>context-schema-avro</module>
</modules>
-</project> \ No newline at end of file
+</project>
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java
index e96a3f5d5..0eeb497a1 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java
@@ -45,7 +45,7 @@ public class XMLEventProtocolParameters extends EventProtocolTextTokenDelimitedP
this.setLabel(XML_EVENT_PROTOCOL_LABEL);
// Set the starting and ending delimiters for text blocks of XML events
- this.setDelimiterToken(XML_TEXT_DELIMITER_TOKEN);
+ this.setStartDelimiterToken(XML_TEXT_DELIMITER_TOKEN);
// Set the event protocol plugin class
this.setEventProtocolPluginClass(Apex2XMLEventConverter.class.getCanonicalName());
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java
index 761357a1d..e02c86a45 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java
@@ -41,7 +41,7 @@ public class TestXMLTaggedEventConsumer {
public void testGarbageTextLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream("hello there".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -54,7 +54,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream =
new ByteArrayInputStream("1469781869268</TestTimestamp></MainTag>".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -67,7 +67,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -80,7 +80,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -92,7 +92,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -104,7 +104,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -117,7 +117,7 @@ public class TestXMLTaggedEventConsumer {
public void testGarbageTextMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream("hello\nthere".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -129,7 +129,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream =
new ByteArrayInputStream("1469781869268\n</TestTimestamp>\n</MainTag>".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -141,7 +141,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -155,7 +155,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -170,7 +170,7 @@ public class TestXMLTaggedEventConsumer {
"Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish\n\n"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -184,7 +184,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -199,7 +199,7 @@ public class TestXMLTaggedEventConsumer {
"1469781869268</TestTimestamp></MainTag><?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp>"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -212,7 +212,7 @@ public class TestXMLTaggedEventConsumer {
"Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag><?xml><MainTag><TestTimestamp>"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -225,7 +225,7 @@ public class TestXMLTaggedEventConsumer {
"Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>\nRefuse"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -238,7 +238,7 @@ public class TestXMLTaggedEventConsumer {
"<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>Refuse"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -252,7 +252,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"1469781869268\n</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -266,7 +266,7 @@ public class TestXMLTaggedEventConsumer {
"<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -286,7 +286,7 @@ public class TestXMLTaggedEventConsumer {
"Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -306,7 +306,7 @@ public class TestXMLTaggedEventConsumer {
"Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRefuse\n"
.getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
TextBlock textBlock = xmlTaggedReader.readTextBlock();
@@ -325,7 +325,7 @@ public class TestXMLTaggedEventConsumer {
final InputStream xmlInputStream = new ByteArrayInputStream(
"<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish".getBytes());
- final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml");
+ final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml
new file mode 100644
index 000000000..c44b09fd6
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml
@@ -0,0 +1,50 @@
+<!--
+ ============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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId>
+ <artifactId>plugins-event-protocol</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plugins-event-protocol-yaml</artifactId>
+ <name>${project.artifactId}</name>
+ <description>[${project.parent.artifactId}] Plugins for handling events that are being transported as YAML documents</description>
+
+ <properties>
+ <apex-plugins-event-protocol-yaml-dir>${project.basedir}/src</apex-plugins-event-protocol-yaml-dir>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.21</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.context-schema</groupId>
+ <artifactId>context-schema-avro</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java
new file mode 100644
index 000000000..689b1e730
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java
@@ -0,0 +1,387 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-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.plugins.event.protocol.yaml;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onap.policy.apex.context.SchemaHelper;
+import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
+import org.onap.policy.apex.model.basicmodel.service.ModelService;
+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.apex.service.engine.event.ApexEvent;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+import org.yaml.snakeyaml.DumperOptions.FlowStyle;
+
+/**
+ * The Class Apex2YamlEventConverter converts {@link ApexEvent} instances to and from YAML string representations of
+ * Apex events.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2YamlEventConverter.class);
+
+ // The parameters for the YAML event protocol
+ private YamlEventProtocolParameters yamlPars;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter#init(org.onap.policy.
+ * apex.service.parameters.eventprotocol.EventProtocolParameters)
+ */
+ @Override
+ public void init(final EventProtocolParameters parameters) {
+ // Check and get the YAML parameters
+ if (!(parameters instanceof YamlEventProtocolParameters)) {
+ final String errorMessage = "specified consumer properties are not applicable to the YAML event protocol";
+ LOGGER.warn(errorMessage);
+ throw new ApexEventRuntimeException(errorMessage);
+ }
+
+ yamlPars = (YamlEventProtocolParameters) parameters;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String, java.lang.Object)
+ */
+ @Override
+ public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException {
+ // Check the event eventObject
+ if (eventObject == null) {
+ LOGGER.warn("event processing failed, event is null");
+ throw new ApexEventException("event processing failed, event is null");
+ }
+
+ // Cast the event to a string, if our conversion is correctly configured, this cast should
+ // always work
+ if (!(eventObject instanceof String)) {
+ final String errorMessage = "error converting event \"" + eventObject + "\" to a string";
+ LOGGER.debug(errorMessage);
+ throw new ApexEventException(errorMessage);
+ }
+
+ final String yamlEventString = (String) eventObject;
+
+ // The list of events we will return
+ final List<ApexEvent> eventList = new ArrayList<>();
+
+ // Convert the YAML document string into an object
+ Object yamlObject = new Yaml().load(yamlEventString);
+
+ // If the incoming YAML did not create a map it is a primitive type or a collection so we
+ // convert it into a map for processing
+ Map<?, ?> yamlMap;
+ if (yamlObject != null && yamlObject instanceof Map) {
+ // We already have a map so just cast the object
+ yamlMap = (Map<?, ?>) yamlObject;
+ }
+ else {
+ // Create a single entry map, new map creation and assignment is to avoid a
+ // type checking warning
+ LinkedHashMap<String, Object> newYamlMap = new LinkedHashMap<>();
+ newYamlMap.put(yamlPars.getYamlFieldName(), yamlObject);
+ yamlMap = newYamlMap;
+ }
+
+ try {
+ eventList.add(yamlMap2ApexEvent(eventName, yamlMap));
+ } catch (final Exception e) {
+ final String errorString = "Failed to unmarshal YAML event: " + e.getMessage() + ", event="
+ + yamlEventString;
+ LOGGER.warn(errorString, e);
+ throw new ApexEventException(errorString, e);
+ }
+
+ // Return the list of events we have unmarshalled
+ return eventList;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.
+ * apex.service.engine.event.ApexEvent)
+ */
+ @Override
+ public Object fromApexEvent(final ApexEvent apexEvent) throws ApexEventException {
+ // Check the Apex event
+ if (apexEvent == null) {
+ LOGGER.warn("event processing failed, Apex event is null");
+ throw new ApexEventException("event processing failed, Apex event is null");
+ }
+
+ // Get the event definition for the event from the model service
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
+ apexEvent.getVersion());
+
+ // Create a map for output of the APEX event to YAML
+ LinkedHashMap<String, Object> yamlMap = new LinkedHashMap<>();
+
+ yamlMap.put(ApexEvent.NAME_HEADER_FIELD, apexEvent.getName());
+ yamlMap.put(ApexEvent.VERSION_HEADER_FIELD, apexEvent.getVersion());
+ yamlMap.put(ApexEvent.NAMESPACE_HEADER_FIELD, apexEvent.getNameSpace());
+ yamlMap.put(ApexEvent.SOURCE_HEADER_FIELD, apexEvent.getSource());
+ yamlMap.put(ApexEvent.TARGET_HEADER_FIELD, apexEvent.getTarget());
+
+ if (apexEvent.getExceptionMessage() != null) {
+ yamlMap.put(ApexEvent.EXCEPTION_MESSAGE_HEADER_FIELD, apexEvent.getExceptionMessage());
+ }
+
+ for (final AxField eventField : eventDefinition.getFields()) {
+ final String fieldName = eventField.getKey().getLocalName();
+
+ if (!apexEvent.containsKey(fieldName)) {
+ if (!eventField.getOptional()) {
+ final String errorMessage = "error parsing " + eventDefinition.getID() + " event to Json. "
+ + "Field \"" + fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
+ LOGGER.debug(errorMessage);
+ throw new ApexEventRuntimeException(errorMessage);
+ }
+ continue;
+ }
+
+ yamlMap.put(fieldName, apexEvent.get(fieldName));
+ }
+
+ // Use Snake YAML to convert the APEX event to YAML
+ Yaml yaml = new Yaml();
+ return yaml.dumpAs(yamlMap, null, FlowStyle.BLOCK);
+ }
+
+ /**
+ * This method converts a YAML map into an Apex event.
+ *
+ * @param eventName the name of the event
+ * @param yamlMap the YAML map that holds the event
+ * @return the apex event that we have converted the JSON object into
+ * @throws ApexEventException
+ * thrown on unmarshaling exceptions
+ */
+ private ApexEvent yamlMap2ApexEvent(final String eventName, final Map<?, ?> yamlMap)
+ throws ApexEventException {
+ // Process the mandatory Apex header
+ final ApexEvent apexEvent = processApexEventHeader(eventName, yamlMap);
+
+ // Get the event definition for the event from the model service
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
+ apexEvent.getVersion());
+
+ // Iterate over the input fields in the event
+ for (final AxField eventField : eventDefinition.getFields()) {
+ final String fieldName = eventField.getKey().getLocalName();
+ if (!yamlMap.containsKey(fieldName)) {
+ if (!eventField.getOptional()) {
+ final String errorMessage = "error parsing " + eventDefinition.getID() + " event from Json. "
+ + "Field \"" + fieldName + "\" is missing, but is mandatory.";
+ LOGGER.debug(errorMessage);
+ throw new ApexEventException(errorMessage);
+ }
+ continue;
+ }
+
+ final Object fieldValue = getYamlField(yamlMap, fieldName, null, !eventField.getOptional());
+
+ if (fieldValue != null) {
+ // Get the schema helper
+ final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ eventField.getSchema());
+ apexEvent.put(fieldName, fieldSchemaHelper.createNewInstance(fieldValue));
+ } else {
+ apexEvent.put(fieldName, null);
+ }
+ }
+ return apexEvent;
+
+ }
+
+ /**
+ * This method processes the event header of an Apex event.
+ *
+ * @param eventName the name of the event
+ * @param yamlMap the YAML map that holds the event
+ * @return an apex event constructed using the header fields of the event
+ * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventException on invalid events with missing header fields
+ */
+ private ApexEvent processApexEventHeader(final String eventName, final Map<?, ?> yamlMap)
+ throws ApexEventException {
+ // Get the event header fields
+ // @formatter:off
+ String name = getYamlStringField(yamlMap, ApexEvent.NAME_HEADER_FIELD, yamlPars.getNameAlias(), ApexEvent.NAME_REGEXP, false);
+ String version = getYamlStringField(yamlMap, ApexEvent.VERSION_HEADER_FIELD, yamlPars.getVersionAlias(), ApexEvent.VERSION_REGEXP, false);
+ String namespace = getYamlStringField(yamlMap, ApexEvent.NAMESPACE_HEADER_FIELD, yamlPars.getNameSpaceAlias(), ApexEvent.NAMESPACE_REGEXP, false);
+ String source = getYamlStringField(yamlMap, ApexEvent.SOURCE_HEADER_FIELD, yamlPars.getSourceAlias(), ApexEvent.SOURCE_REGEXP, false);
+ String target = getYamlStringField(yamlMap, ApexEvent.TARGET_HEADER_FIELD, yamlPars.getTargetAlias(), ApexEvent.TARGET_REGEXP, false);
+ // @formatter:on
+
+ // Check that an event name has been specified
+ if (name == null && eventName == null) {
+ throw new ApexEventRuntimeException(
+ "event received without mandatory parameter \"name\" on configuration or on event");
+ }
+
+ // Check if an event name was specified on the event parameters
+ if (eventName != null) {
+ if (name != null && !eventName.equals(name)) {
+ LOGGER.warn("The incoming event name \"{}\" does not match the configured event name \"{}\", using configured event name",
+ name, eventName);
+ }
+ name = eventName;
+ }
+
+ // Now, find the event definition in the model service. If version is null, the newest event
+ // definition in the model service is used
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(name, version);
+ if (eventDefinition == null) {
+ throw new ApexEventRuntimeException("an event definition for an event named \"" + name
+ + "\" with version \"" + version + "\" not found in Apex model");
+ }
+
+ // Use the defined event version if no version is specified on the incoming fields
+ if (version == null) {
+ version = eventDefinition.getKey().getVersion();
+ }
+
+ // Check the name space is OK if it is defined, if not, use the name space from the model
+ if (namespace != null) {
+ if (!namespace.equals(eventDefinition.getNameSpace())) {
+ throw new ApexEventRuntimeException("namespace \"" + namespace + "\" on event \"" + name
+ + "\" does not match namespace \"" + eventDefinition.getNameSpace()
+ + "\" for that event in the Apex model");
+ }
+ } else {
+ namespace = eventDefinition.getNameSpace();
+ }
+
+ // For source, use the defined source only if the source is not found on the incoming event
+ if (source == null) {
+ source = eventDefinition.getSource();
+ }
+
+ // For target, use the defined source only if the source is not found on the incoming event
+ if (target == null) {
+ target = eventDefinition.getTarget();
+ }
+
+ return new ApexEvent(name, version, namespace, source, target);
+ }
+
+ /**
+ * This method gets an event string field from a JSON object.
+ *
+ * @param yamlMap
+ * the YAML containing the YAML representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
+ * @param fieldAlias
+ * the alias for the field to find in the event, overrides the field name if it is not null
+ * @param fieldRE
+ * the regular expression to check the field against for validity
+ * @param mandatory
+ * true if the field is mandatory
+ * @return the value of the field in the JSON object or null if the field is optional
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
+ */
+ private String getYamlStringField(final Map<?, ?> yamlMap, final String fieldName, final String fieldAlias,
+ final String fieldRE, final boolean mandatory) {
+ // Get the YAML field for the string field
+ final Object yamlField = getYamlField(yamlMap, fieldName, fieldAlias, mandatory);
+
+ // Null strings are allowed
+ if (yamlField == null) {
+ return null;
+ }
+
+ if (!(yamlField instanceof String)) {
+ // The element is not a string so throw an error
+ throw new ApexEventRuntimeException("field \"" + fieldName + "\" with type \""
+ + yamlField.getClass().getCanonicalName() + "\" is not a string value");
+ }
+
+ final String fieldValueString = (String) yamlField;
+
+ // Is regular expression checking required
+ if (fieldRE == null) {
+ return fieldValueString;
+ }
+
+ // Check the event field against its regular expression
+ if (!fieldValueString.matches(fieldRE)) {
+ throw new ApexEventRuntimeException(
+ "field \"" + fieldName + "\" with value \"" + fieldValueString + "\" is invalid");
+ }
+
+ return fieldValueString;
+ }
+
+ /**
+ * This method gets an event field from a YAML object.
+ *
+ * @param yamlMap
+ * the YAML containing the YAML representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
+ * @param fieldAlias
+ * the alias for the field to find in the event, overrides the field name if it is not null
+ * @param mandatory
+ * true if the field is mandatory
+ * @return the value of the field in the YAML object or null if the field is optional
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
+ */
+ private Object getYamlField(final Map<?, ?> yamlMap, final String fieldName, final String fieldAlias,
+ final boolean mandatory) {
+
+ // Check if we should use the alias for this field
+ String fieldToFind = fieldName;
+ if (fieldAlias != null) {
+ fieldToFind = fieldAlias;
+ }
+
+ // Get the event field
+ final Object eventElement = yamlMap.get(fieldToFind);
+ if (eventElement == null) {
+ if (!mandatory) {
+ return null;
+ } else {
+ throw new ApexEventRuntimeException("mandatory field \"" + fieldToFind + "\" is missing");
+ }
+ }
+
+ return eventElement;
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java
new file mode 100644
index 000000000..861e9cd8f
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java
@@ -0,0 +1,204 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-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.plugins.event.protocol.yaml;
+
+import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters;
+
+/**
+ * Event protocol parameters for YAML as an event protocol.
+ *
+ * The parameters for this plugin are:
+ * <ol>
+ * <li>nameAlias: The field in a YAML event to use as an alias for the event name. This parameter is
+ * optional.
+ * <li>versionAlias: The field in a YAML event to use as an alias for the event version. This
+ * parameter is optional.
+ * <li>nameSpaceAlias: The field in a YAML event to use as an alias for the event name space. This
+ * parameter is optional.
+ * <li>sourceAlias: The field in a YAML event to use as an alias for the event source. This
+ * parameter is optional.
+ * <li>targetAlias: The field in a YAML event to use as an alias for the event target. This
+ * parameter is optional.
+ * <li>yamlFieldName: The name of the field in the APEX event that will contain the unmarshaled YAML object. The
+ * parameter is optional and defaults to the value "yaml_field".
+ * </ol>
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters {
+ /** The label of this event protocol. */
+ public static final String YAML_EVENT_PROTOCOL_LABEL = "YAML";
+
+ // Constants for text block delimiters
+ private static final String YAML_START_TEXT_DELIMITER_TOKEN = "---";
+ private static final String YAML_END_TEXT_DELIMITER_TOKEN = "...";
+
+ // Default parameter values
+ private static final String DEFAULT_YAML_FIELD_NAME = "yaml_field";
+
+ // Aliases for Apex event header fields
+ // @formatter:off
+ private String nameAlias = null;
+ private String versionAlias = null;
+ private String nameSpaceAlias = null;
+ private String sourceAlias = null;
+ private String targetAlias = null;
+ private String yamlFieldName = DEFAULT_YAML_FIELD_NAME;
+ // @formatter:on
+
+ /**
+ * Constructor to create a YAML event protocol parameter instance and register the instance with
+ * the parameter service.
+ */
+ public YamlEventProtocolParameters() {
+ this(YamlEventProtocolParameters.class.getCanonicalName(), YAML_EVENT_PROTOCOL_LABEL);
+ }
+
+ /**
+ * Constructor to create an event protocol parameters instance with the name of a sub class of
+ * this class.
+ *
+ * @param parameterClassName the class name of a sub class of this class
+ * @param eventProtocolLabel the name of the event protocol for this plugin
+ */
+ public YamlEventProtocolParameters(final String parameterClassName, final String eventProtocolLabel) {
+ super(parameterClassName);
+
+ // Set the event protocol properties for the YAML event protocol
+ this.setLabel(eventProtocolLabel);
+
+ // Set the delimiter token for text blocks of YAML events
+ this.setStartDelimiterToken(YAML_START_TEXT_DELIMITER_TOKEN);
+ this.setEndDelimiterToken(YAML_END_TEXT_DELIMITER_TOKEN);
+
+ // Set the event protocol plugin class
+ this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getCanonicalName());
+ }
+
+ /**
+ * Gets the name alias.
+ *
+ * @return the name alias
+ */
+ public String getNameAlias() {
+ return nameAlias;
+ }
+
+ /**
+ * Gets the version alias.
+ *
+ * @return the version alias
+ */
+ public String getVersionAlias() {
+ return versionAlias;
+ }
+
+ /**
+ * Gets the name space alias.
+ *
+ * @return the name space alias
+ */
+ public String getNameSpaceAlias() {
+ return nameSpaceAlias;
+ }
+
+ /**
+ * Gets the source alias.
+ *
+ * @return the source alias
+ */
+ public String getSourceAlias() {
+ return sourceAlias;
+ }
+
+ /**
+ * Gets the target alias.
+ *
+ * @return the target alias
+ */
+ public String getTargetAlias() {
+ return targetAlias;
+ }
+
+ /**
+ * Gets the YAML field name.
+ *
+ * @return the YAML field name
+ */
+ public String getYamlFieldName() {
+ return yamlFieldName;
+ }
+
+ /**
+ * Sets the name alias.
+ *
+ * @param nameAlias the new name alias
+ */
+ public void setNameAlias(String nameAlias) {
+ this.nameAlias = nameAlias;
+ }
+
+ /**
+ * Sets the version alias.
+ *
+ * @param versionAlias the new version alias
+ */
+ public void setVersionAlias(String versionAlias) {
+ this.versionAlias = versionAlias;
+ }
+
+ /**
+ * Sets the name space alias.
+ *
+ * @param nameSpaceAlias the new name space alias
+ */
+ public void setNameSpaceAlias(String nameSpaceAlias) {
+ this.nameSpaceAlias = nameSpaceAlias;
+ }
+
+ /**
+ * Sets the source alias.
+ *
+ * @param sourceAlias the new source alias
+ */
+ public void setSourceAlias(String sourceAlias) {
+ this.sourceAlias = sourceAlias;
+ }
+
+ /**
+ * Sets the target alias.
+ *
+ * @param targetAlias the new target alias
+ */
+ public void setTargetAlias(String targetAlias) {
+ this.targetAlias = targetAlias;
+ }
+
+ /**
+ * Sets the encapsulating object name.
+ *
+ * @param yamlFieldName
+ * the new YAML field name
+ */
+ public void setYamlFieldName(String yamlFieldName) {
+ this.yamlFieldName = yamlFieldName;
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/package-info.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/package-info.java
new file mode 100644
index 000000000..ce11d33a3
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/package-info.java
@@ -0,0 +1,27 @@
+/*-
+ * ============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=========================================================
+ */
+
+/**
+ * Contains implementations of Apex event protocol converter plugins for events in YAML format.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+package org.onap.policy.apex.plugins.event.protocol.yaml;
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlEventProtocol.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlEventProtocol.java
new file mode 100644
index 000000000..40196eb8a
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlEventProtocol.java
@@ -0,0 +1,263 @@
+/*-
+ * ============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.plugins.event.protocol.yaml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
+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.basicmodel.service.ParameterService;
+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.apex.model.utilities.TextFileUtils;
+import org.onap.policy.apex.service.engine.event.ApexEvent;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.HeaderDelimitedTextBlockReader;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlock;
+
+public class TestYamlEventProtocol {
+ @BeforeClass
+ public static void registerTestEventsAndSchemas() throws IOException {
+ SchemaParameters schemaParameters = new SchemaParameters();
+ schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
+ ParameterService.registerParameters(SchemaParameters.class, schemaParameters);
+
+ 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 simpleDoubleSchema = new AxContextSchema(new AxArtifactKey("SimpleDoubleSchema", "0.0.1"), "JAVA",
+ "java.lang.Double");
+ schemas.getSchemasMap().put(simpleDoubleSchema.getKey(), simpleDoubleSchema);
+
+ AxContextSchema simpleStringSchema = new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"), "JAVA",
+ "java.lang.String");
+ schemas.getSchemasMap().put(simpleStringSchema.getKey(), simpleStringSchema);
+
+ AxContextSchema arrayListSchema = new AxContextSchema(new AxArtifactKey("ArrayListSchema", "0.0.1"), "JAVA",
+ "java.util.ArrayList");
+ schemas.getSchemasMap().put(arrayListSchema.getKey(), arrayListSchema);
+
+ AxContextSchema linkedHashMapSchema = new AxContextSchema(new AxArtifactKey("LinkedHashMapSchema", "0.0.1"), "JAVA",
+ "java.util.LinkedHashMap");
+ schemas.getSchemasMap().put(linkedHashMapSchema.getKey(), linkedHashMapSchema);
+
+ ModelService.registerModel(AxContextSchemas.class, schemas);
+
+ AxEvents events = new AxEvents();
+
+ AxEvent testEvent0 = new AxEvent(new AxArtifactKey("TestEvent0", "0.0.1"));
+ testEvent0.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ events.getEventMap().put(testEvent0.getKey(), testEvent0);
+
+ AxEvent testEvent1 = new AxEvent(new AxArtifactKey("TestEvent1", "0.0.1"));
+ testEvent1.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te1Field0 = new AxField(new AxReferenceKey(testEvent1.getKey(), "yaml_field"),
+ arrayListSchema.getKey());
+ testEvent1.getParameterMap().put("yaml_field", te1Field0);
+ events.getEventMap().put(testEvent1.getKey(), testEvent1);
+
+ AxEvent testEvent2 = new AxEvent(new AxArtifactKey("TestEvent2", "0.0.1"));
+ testEvent2.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te2Field0 = new AxField(new AxReferenceKey(testEvent2.getKey(), "hr"), simpleIntSchema.getKey());
+ testEvent2.getParameterMap().put("hr", te2Field0);
+ AxField te2Field1 = new AxField(new AxReferenceKey(testEvent2.getKey(), "avg"), simpleDoubleSchema.getKey());
+ testEvent2.getParameterMap().put("avg", te2Field1);
+ AxField te2Field2 = new AxField(new AxReferenceKey(testEvent2.getKey(), "rbi"), simpleIntSchema.getKey());
+ testEvent2.getParameterMap().put("rbi", te2Field2);
+ events.getEventMap().put(testEvent2.getKey(), testEvent2);
+
+ AxEvent testEvent3 = new AxEvent(new AxArtifactKey("TestEvent3", "0.0.1"));
+ testEvent3.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te3Field0 = new AxField(new AxReferenceKey(testEvent3.getKey(), "american"),
+ arrayListSchema.getKey());
+ testEvent3.getParameterMap().put("american", te3Field0);
+ AxField te3Field1 = new AxField(new AxReferenceKey(testEvent3.getKey(), "national"),
+ arrayListSchema.getKey());
+ testEvent3.getParameterMap().put("national", te3Field1);
+ events.getEventMap().put(testEvent3.getKey(), testEvent3);
+
+ AxEvent testEvent4 = new AxEvent(new AxArtifactKey("TestEvent4", "0.0.1"));
+ testEvent4.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te4Field0 = new AxField(new AxReferenceKey(testEvent4.getKey(), "yaml_field"),
+ arrayListSchema.getKey());
+ testEvent4.getParameterMap().put("yaml_field", te4Field0);
+ events.getEventMap().put(testEvent4.getKey(), testEvent4);
+
+ AxEvent testEvent5 = new AxEvent(new AxArtifactKey("TestEvent5", "0.0.1"));
+ testEvent5.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te5Field0 = new AxField(new AxReferenceKey(testEvent5.getKey(), "yaml_field"),
+ arrayListSchema.getKey());
+ testEvent5.getParameterMap().put("yaml_field", te5Field0);
+ events.getEventMap().put(testEvent5.getKey(), testEvent5);
+
+ AxEvent testEvent6 = new AxEvent(new AxArtifactKey("TestEvent6", "0.0.1"));
+ testEvent6.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te6Field0 = new AxField(new AxReferenceKey(testEvent6.getKey(), "MarkMcGwire"),
+ linkedHashMapSchema.getKey());
+ testEvent6.getParameterMap().put("Mark McGwire", te6Field0);
+ AxField te6Field1 = new AxField(new AxReferenceKey(testEvent6.getKey(), "SammySosa"),
+ linkedHashMapSchema.getKey());
+ testEvent6.getParameterMap().put("Sammy Sosa", te6Field1);
+ events.getEventMap().put(testEvent6.getKey(), testEvent6);
+
+ AxEvent testEvent7 = new AxEvent(new AxArtifactKey("TestEvent7", "0.0.1"));
+ testEvent7.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te7Field0 = new AxField(new AxReferenceKey(testEvent7.getKey(), "time"),
+ simpleIntSchema.getKey());
+ testEvent7.getParameterMap().put("time", te7Field0);
+ AxField te7Field1 = new AxField(new AxReferenceKey(testEvent7.getKey(), "player"),
+ simpleStringSchema.getKey());
+ testEvent7.getParameterMap().put("player", te7Field1);
+ AxField te7Field2 = new AxField(new AxReferenceKey(testEvent7.getKey(), "action"),
+ simpleStringSchema.getKey());
+ testEvent7.getParameterMap().put("action", te7Field2);
+ events.getEventMap().put(testEvent7.getKey(), testEvent7);
+
+ AxEvent testEvent8 = new AxEvent(new AxArtifactKey("TestEvent8", "0.0.1"));
+ testEvent8.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te8Field0 = new AxField(new AxReferenceKey(testEvent8.getKey(), "hr"),
+ arrayListSchema.getKey());
+ testEvent8.getParameterMap().put("hr", te8Field0);
+ AxField te8Field1 = new AxField(new AxReferenceKey(testEvent8.getKey(), "rbi"),
+ arrayListSchema.getKey());
+ testEvent8.getParameterMap().put("rbi", te8Field1);
+ events.getEventMap().put(testEvent8.getKey(), testEvent8);
+
+ AxEvent testEvent9 = new AxEvent(new AxArtifactKey("TestEvent9", "0.0.1"));
+ testEvent9.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te9Field0 = new AxField(new AxReferenceKey(testEvent9.getKey(), "ChicagoCubs"),
+ arrayListSchema.getKey());
+ testEvent9.getParameterMap().put("ChicagoCubs", te9Field0);
+ AxField te9Field1 = new AxField(new AxReferenceKey(testEvent9.getKey(), "AtlantaBraves"),
+ arrayListSchema.getKey());
+ testEvent9.getParameterMap().put("AtlantaBraves", te9Field1);
+ events.getEventMap().put(testEvent9.getKey(), testEvent9);
+
+ AxEvent testEvent10 = new AxEvent(new AxArtifactKey("TestEvent10", "0.0.1"));
+ testEvent10.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te10Field0 = new AxField(new AxReferenceKey(testEvent10.getKey(), "yaml_field"),
+ arrayListSchema.getKey());
+ testEvent10.getParameterMap().put("yaml_field", te10Field0);
+ events.getEventMap().put(testEvent10.getKey(), testEvent10);
+
+ AxEvent testEvent11 = new AxEvent(new AxArtifactKey("TestEvent11", "0.0.1"));
+ testEvent11.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField te11Field0 = new AxField(new AxReferenceKey(testEvent11.getKey(), "tosca_definitions_version"),
+ simpleStringSchema.getKey());
+ testEvent11.getParameterMap().put("tosca_definitions_version", te11Field0);
+ AxField te11Field1 = new AxField(new AxReferenceKey(testEvent11.getKey(), "description"),
+ simpleStringSchema.getKey(), true);
+ testEvent11.getParameterMap().put("description", te11Field1);
+ AxField te11Field2 = new AxField(new AxReferenceKey(testEvent11.getKey(), "node_types"),
+ linkedHashMapSchema.getKey(), true);
+ testEvent11.getParameterMap().put("node_types", te11Field2);
+ AxField te11Field3 = new AxField(new AxReferenceKey(testEvent11.getKey(), "topology_template"),
+ linkedHashMapSchema.getKey());
+ testEvent11.getParameterMap().put("topology_template", te11Field3);
+ events.getEventMap().put(testEvent11.getKey(), testEvent11);
+
+ ModelService.registerModel(AxEvents.class, events);
+ }
+
+ @AfterClass
+ public static void unregisterTestEventsAndSchemas() {
+ ModelService.clear();
+ }
+
+ @Test
+ public void testYamlProcessing() throws ApexEventException, IOException {
+ try {
+ testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0");
+ fail("test should fail here");
+ } catch (ApexEventException e) {
+ assertEquals("event processing failed, event is null", e.getMessage());
+ }
+
+ testYamlDecodeEncode("TestEvent0", 1, 0, "Empty1");
+ testYamlDecodeEncode("TestEvent1", 1, 1, "Collection0");
+ testYamlDecodeEncode("TestEvent2", 1, 3, "Collection1");
+ testYamlDecodeEncode("TestEvent3", 1, 2, "Collection2");
+ testYamlDecodeEncode("TestEvent4", 1, 1, "Collection3");
+ testYamlDecodeEncode("TestEvent5", 1, 1, "Collection4");
+ testYamlDecodeEncode("TestEvent6", 1, 2, "Collection5");
+ testYamlDecodeEncode("TestEvent1", 2, 1, "Structure0");
+ testYamlDecodeEncode("TestEvent7", 2, 3, "Structure1");
+ testYamlDecodeEncode("TestEvent8", 1, 2, "Structure2");
+ testYamlDecodeEncode("TestEvent8", 1, 2, "Structure3");
+ testYamlDecodeEncode("TestEvent9", 1, 2, "Structure4");
+ testYamlDecodeEncode("TestEvent10", 1, 1, "Structure5");
+ testYamlDecodeEncode("TestEvent11", 1, 4, "TOSCA0");
+ }
+
+ private void testYamlDecodeEncode(final String eventName, final int eventCount, final int parCount, final String fileName)
+ throws ApexEventException, IOException {
+ YamlEventProtocolParameters parameters = new YamlEventProtocolParameters();
+ parameters.setDelimiterAtStart(false);
+
+ Apex2YamlEventConverter converter = new Apex2YamlEventConverter();
+ converter.init(parameters);
+
+ String filePath = "src/test/resources/yaml_in/" + fileName + ".yaml";
+ FileInputStream fileInputStream = new FileInputStream(new File(filePath));
+ HeaderDelimitedTextBlockReader reader = new HeaderDelimitedTextBlockReader(parameters);
+ reader.init(fileInputStream);
+
+ List<ApexEvent> eventList = new ArrayList<>();
+
+ TextBlock textBlock;
+ do {
+ textBlock = reader.readTextBlock();
+
+ eventList.addAll(converter.toApexEvent(eventName, textBlock.getText()));
+ } while (!textBlock.isEndOfText());
+
+ fileInputStream.close();
+
+ assertEquals(eventCount, eventList.size());
+
+ for (int eventNo = 0; eventNo < eventCount; eventNo++) {
+ assertEquals(parCount, eventList.get(0).size());
+
+ String eventYaml = (String) converter.fromApexEvent(eventList.get(eventNo));
+ String expectedYaml = TextFileUtils.getTextFileAsString("src/test/resources/yaml_out/" + fileName + '_' + eventNo + ".yaml");
+ assertEquals(expectedYaml.replaceAll("\\s*", ""), eventYaml.replaceAll("\\s*", ""));
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlPluginStability.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlPluginStability.java
new file mode 100644
index 000000000..126a01df7
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/TestYamlPluginStability.java
@@ -0,0 +1,259 @@
+/*-
+ * ============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.plugins.event.protocol.yaml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
+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.basicmodel.service.ParameterService;
+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.apex.service.engine.event.ApexEvent;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+
+public class TestYamlPluginStability {
+ static AxEvent testEvent;
+
+ @BeforeClass
+ public static void registerTestEventsAndSchemas() throws IOException {
+ SchemaParameters schemaParameters = new SchemaParameters();
+ schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
+ ParameterService.registerParameters(SchemaParameters.class, schemaParameters);
+
+ 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 simpleDoubleSchema = new AxContextSchema(new AxArtifactKey("SimpleDoubleSchema", "0.0.1"),
+ "JAVA", "java.lang.Double");
+ schemas.getSchemasMap().put(simpleDoubleSchema.getKey(), simpleDoubleSchema);
+
+ 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);
+
+ AxEvents events = new AxEvents();
+
+ testEvent = new AxEvent(new AxArtifactKey("TestEvent", "0.0.1"));
+ testEvent.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ AxField teField0 = new AxField(new AxReferenceKey(testEvent.getKey(), "intValue"), simpleIntSchema.getKey());
+ testEvent.getParameterMap().put("intValue", teField0);
+ AxField teField1 = new AxField(new AxReferenceKey(testEvent.getKey(), "doubleValue"),
+ simpleDoubleSchema.getKey());
+ testEvent.getParameterMap().put("doubleValue", teField1);
+ AxField teField2 = new AxField(new AxReferenceKey(testEvent.getKey(), "stringValue"),
+ simpleStringSchema.getKey(), true);
+ testEvent.getParameterMap().put("stringValue", teField2);
+ events.getEventMap().put(testEvent.getKey(), testEvent);
+
+ ModelService.registerModel(AxEvents.class, events);
+ }
+
+ @AfterClass
+ public static void unregisterTestEventsAndSchemas() {
+ ModelService.clear();
+ }
+
+ @Test
+ public void testStability() throws ApexEventException {
+ Apex2YamlEventConverter converter = new Apex2YamlEventConverter();
+
+ try {
+ converter.init(null);
+ fail("this test should throw an exception");
+ } catch (ApexEventRuntimeException e) {
+ assertEquals("specified consumer properties are not applicable to the YAML event protocol", e.getMessage());
+ }
+
+ YamlEventProtocolParameters pars = new YamlEventProtocolParameters();
+ converter.init(pars);
+
+ try {
+ converter.toApexEvent("NonExistantEvent", "");
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("Failed to unmarshal YAML event: an event definition for an event named \"NonExistantEvent\"",
+ e.getMessage().substring(0, 89));
+ }
+
+ try {
+ converter.toApexEvent("TestEvent", null);
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("event processing failed, event is null", e.getMessage());
+ }
+
+ try {
+ converter.toApexEvent("TestEvent", 1);
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("error converting event \"1\" to a string", e.getMessage());
+ }
+
+ try {
+ converter.toApexEvent("TestEvent", "");
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertTrue(e.getMessage().contains("Field \"doubleValue\" is missing"));
+ }
+
+ try {
+ converter.fromApexEvent(null);
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("event processing failed, Apex event is null", e.getMessage());
+ }
+
+ ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(),
+ testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget());
+ apexEvent.put("doubleValue", 123.45);
+ apexEvent.put("intValue", 123);
+ apexEvent.put("stringValue", "123.45");
+
+ apexEvent.setExceptionMessage("my wonderful exception message");
+ String yamlString = (String) converter.fromApexEvent(apexEvent);
+ assertTrue(yamlString.contains("my wonderful exception message"));
+
+ apexEvent.remove("intValue");
+ try {
+ yamlString = (String) converter.fromApexEvent(apexEvent);
+ fail("this test should throw an exception");
+ } catch (ApexEventRuntimeException e) {
+ assertEquals("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing",
+ e.getMessage().substring(0, 72));
+ }
+
+ try {
+ converter.toApexEvent(null, "");
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("Failed to unmarshal YAML event: event received without mandatory parameter \"name\"",
+ e.getMessage().substring(0, 81));
+ }
+
+ pars.setNameAlias("TheNameField");
+ try {
+ converter.toApexEvent(null, "");
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("Failed to unmarshal YAML event: event received without mandatory parameter \"name\"",
+ e.getMessage().substring(0, 81));
+ }
+
+ apexEvent.put("intValue", 123);
+
+ apexEvent.remove("stringValue");
+ yamlString = (String) converter.fromApexEvent(apexEvent);
+ apexEvent.put("stringValue", "123.45");
+
+ String yamlInputString = "doubleValue: 123.45\n" + "intValue: 123";
+
+ List<ApexEvent> eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals(123.45, eventList.get(0).get("doubleValue"));
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: null";
+
+ eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals(null, eventList.get(0).get("stringValue"));
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: TestEvent";
+ pars.setNameAlias("stringValue");
+ eventList = converter.toApexEvent(null, yamlInputString);
+ assertEquals("TestEvent", eventList.get(0).get("stringValue"));
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: SomeOtherEvent";
+ eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals("SomeOtherEvent", eventList.get(0).get("stringValue"));
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: 0.0.1";
+ pars.setNameAlias(null);
+ pars.setVersionAlias("stringValue");
+ eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals("0.0.1", eventList.get(0).get("stringValue"));
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.some.other.namespace";
+ pars.setVersionAlias(null);
+ pars.setNameSpaceAlias("stringValue");
+ try {
+ converter.toApexEvent("TestEvent", yamlInputString);
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("Failed to unmarshal YAML event: namespace \"org.some.other.namespace\" on event",
+ e.getMessage().substring(0, 77));
+ }
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.onap.policy.apex.plugins.event.protocol.yaml";
+ eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals("org.onap.policy.apex.plugins.event.protocol.yaml", eventList.get(0).getNameSpace());
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MySource";
+ pars.setNameSpaceAlias(null);
+ pars.setSourceAlias("stringValue");
+ eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals("MySource", eventList.get(0).getSource());
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyTarget";
+ pars.setSourceAlias(null);
+ pars.setTargetAlias("stringValue");
+ eventList = converter.toApexEvent("TestEvent", yamlInputString);
+ assertEquals("MyTarget", eventList.get(0).getTarget());
+ pars.setTargetAlias(null);
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyString";
+ pars.setSourceAlias(null);
+ pars.setTargetAlias("intValue");
+ try {
+ converter.toApexEvent("TestEvent", yamlInputString);
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertEquals("Failed to unmarshal YAML event: field \"target\" with type \"java.lang.Integer\"",
+ e.getMessage().substring(0, 76));
+ }
+ pars.setTargetAlias(null);
+
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: ~\n"+ "stringValue: MyString";
+ try {
+ converter.toApexEvent("TestEvent", yamlInputString);
+ fail("this test should throw an exception");
+ } catch (ApexEventException e) {
+ assertTrue(e.getMessage().contains("mandatory field \"intValue\" is missing"));
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection0.yaml
new file mode 100644
index 000000000..12519fb48
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection0.yaml
@@ -0,0 +1,3 @@
+- Mark McGwire
+- Sammy Sosa
+- Ken Griffey \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection1.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection1.yaml
new file mode 100644
index 000000000..7b7ec948d
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection1.yaml
@@ -0,0 +1,3 @@
+hr: 65 # Home runs
+avg: 0.278 # Batting average
+rbi: 147 # Runs Batted In
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection2.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection2.yaml
new file mode 100644
index 000000000..656d628ec
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection2.yaml
@@ -0,0 +1,8 @@
+american:
+ - Boston Red Sox
+ - Detroit Tigers
+ - New York Yankees
+national:
+ - New York Mets
+ - Chicago Cubs
+ - Atlanta Braves
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection3.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection3.yaml
new file mode 100644
index 000000000..e60d8a9b3
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection3.yaml
@@ -0,0 +1,8 @@
+-
+ name: Mark McGwire
+ hr: 65
+ avg: 0.278
+-
+ name: Sammy Sosa
+ hr: 63
+ avg: 0.288 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection4.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection4.yaml
new file mode 100644
index 000000000..65da53d6e
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection4.yaml
@@ -0,0 +1,3 @@
+- [name , hr, avg ]
+- [Mark McGwire, "65", "0.278"]
+- [Sammy Sosa , "63", "0.288"] \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection5.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection5.yaml
new file mode 100644
index 000000000..dfc534fd2
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Collection5.yaml
@@ -0,0 +1,5 @@
+MarkMcGwire: {hr: 65, avg: 0.278}
+SammySosa: {
+ hr: 63,
+ avg: 0.288
+ } \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty0.yaml
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty0.yaml
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty1.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty1.yaml
new file mode 100644
index 000000000..8946d48ba
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Empty1.yaml
@@ -0,0 +1,4 @@
+# Comments line
+
+
+# Comment line \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure0.yaml
new file mode 100644
index 000000000..0a47b89d8
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure0.yaml
@@ -0,0 +1,10 @@
+---
+# Ranking of 1998 home runs
+- Mark McGwire
+- Sammy Sosa
+- Ken Griffey
+
+---
+# Team ranking
+- Chicago Cubs
+- St Louis Cardinals \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure1.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure1.yaml
new file mode 100644
index 000000000..05e102d8e
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure1.yaml
@@ -0,0 +1,10 @@
+---
+time: 20:03:20
+player: Sammy Sosa
+action: strike (miss)
+...
+---
+time: 20:03:47
+player: Sammy Sosa
+action: grand slam
+...
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure2.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure2.yaml
new file mode 100644
index 000000000..a3ef726c0
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure2.yaml
@@ -0,0 +1,8 @@
+---
+hr: # 1998 hr ranking
+ - Mark McGwire
+ - Sammy Sosa
+rbi:
+ # 1998 rbi ranking
+ - Sammy Sosa
+ - Ken Griffey \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure3.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure3.yaml
new file mode 100644
index 000000000..bf46f753c
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure3.yaml
@@ -0,0 +1,8 @@
+---
+hr:
+ - Mark McGwire
+ # Following node labeled SS
+ - &SS Sammy Sosa
+rbi:
+ - *SS # Subsequent occurrence
+ - Ken Griffey \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure4.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure4.yaml
new file mode 100644
index 000000000..eb3fd722c
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure4.yaml
@@ -0,0 +1,7 @@
+? ChicagoCubs
+:
+ - 2001-07-23
+
+? AtlantaBraves
+: [ 2001-07-02, 2001-08-12,
+ 2001-08-14 ] \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure5.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure5.yaml
new file mode 100644
index 000000000..8a26671ba
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/Structure5.yaml
@@ -0,0 +1,8 @@
+---
+# Products purchased
+- item : Super Hoop
+ quantity: 1
+- item : Basketball
+ quantity: 4
+- item : Big Shoes
+ quantity: 1 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/TOSCA0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/TOSCA0.yaml
new file mode 100644
index 000000000..27977f47f
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_in/TOSCA0.yaml
@@ -0,0 +1,180 @@
+# https://wiki.onap.org/display/DW/VNFD+example
+tosca_definitions_version: tosca_simple_profile_yaml_1_1
+description: the VNFD of MyVnf
+
+node_types:
+ MyCompany.MyVnf.1_0.1_0: # node type of MyVnf
+ derived_from: tosca.nodes.nfv.VNF
+ properties:
+ descriptor_id:
+ type: string
+ constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a1177 ] ]
+ default: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
+ required: true
+ provider:
+ type: string
+ constraints: [ valid_values: [ MyCompany ] ]
+ default: MyCompany
+ required: true
+ product_name:
+ type: string
+ constraints: [ valid_values: [ MyVnf ] ]
+ default: Myvnf
+ required: true
+ software_version:
+ type: string
+ constraints: [ valid_values: [ '1.0' ] ]
+ default: '1.0'
+ required: true
+ descriptor_version:
+ type: string
+ constraints: [ valid_values: [ '1.0' ] ]
+ default: '1.0'
+ required: true
+ flavour_id:
+ type: string
+ constraints: [ valid_values: [ simple ] ] #only one and only allowed one DF in this example
+ default: simple
+ required: true
+ flavour_description:
+ type: string
+ constraints: []
+ default: ""
+ required: true
+ vnfm_info:
+ type: list
+ constraints: []
+ default: ""
+ required: true
+ interfaces:
+ Nfv:
+ instantiate:
+ inputs:
+ parameter_1:
+ type: string
+ required: false
+ default: value_1
+ constraints: []
+ parameter_2:
+ type: string
+ required: false
+ default: value_2
+ constraints: []
+ terminate:
+ implementation: terminate.workbook.mistral.yaml
+
+
+topology_template:
+ substitution_mappings:
+ node_type: MyCompany.MyVnf.1_0.1_0
+ requirements:
+ - virtual_link: [ Cp_2, external_virtual_link ] # expose as external CP
+ - virtual_link: [ Cp_4, external_virtual_link ] # expose as external CP
+
+ node_templates:
+ VDU_compute_1:
+ type: tosca.nodes.nfv.Vdu.Compute
+ properties:
+ name: ..
+ description: ..
+ boot_order: ..
+ nfvi_constraints: ..
+ configurable_properties:
+ additional_vnfc_configurable_properties: {}
+ vdu_profile:
+ min_number_of_instances: 1
+ max_number_of_instances: 4
+ capabilities:
+ virtual_compute:
+ properties:
+ virtual_memory:
+ virtual_mem_size: 8096 MB
+ virtual_cpu:
+ cpu_architecture: x86
+ num_virtual_cpu: 2
+ virtual_cpu_clock: 1800 MHz
+ requirements:
+ - virtual_storage: Storage_1
+
+ Storage_1:
+ type: tosca.nodes.nfv.Vdu.VirtualStorage
+ properties:
+ type_of_storage: ..
+ size_of_storage: 100MB
+ rdma_enabled: ..
+
+ Cp_1:
+ type: tosca.nodes.nfv.VduCp
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: Internal connection point on an VL
+ requirements:
+ - virtual_binding: Vdu_1
+ - virtual_link: internalVl_1
+
+
+ internalVl_1:
+ type: tosca.nodes.nfv.VirtualLink
+ properties:
+ connectivity_type:
+ layer_protocol: ipv4
+ flow_pattern: mesh
+ test_access: []
+ description: ..
+ vl_profile:
+ qos:
+ maxBitRateRequirements:
+ minBitRateRequirements:
+
+
+ Cp_2:
+ type: tosca.nodes.nfv.VduCp
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: External connection point to access exteranlVl_1
+ requirements:
+ - external_virtual_link:
+ - virtual_binding: Vdu_1
+
+
+ VDU_compute_2:
+ type: tosca.nodes.nfv.Vdu.Compute
+ properties:
+ name: ..
+ description: ..
+ boot_order: ..
+ nfvi_constraints: ..
+ configurable_properties:
+ additional_vnfc_configurable_properties: {}
+ vdu_profile:
+ min_number_of_instances: 2
+ max_number_of_instances: 6
+ capabilities:
+ virtual_compute:
+ properties:
+ virtual_memory:
+ virtual_mem_size: 8096 MB
+ virtual_cpu:
+ cpu_architecture: x86
+ num_virtual_cpu: 4
+ virtual_cpu_clock: 1800 MHz
+ Cp_3:
+ type: tosca.nodes.nfv.VduCp
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: Internal connection point on an VL
+ requirements:
+ - virtual_binding: Vdu_2
+ - virtual_link: internalVl_1
+ Cp_4:
+ type: tosca.nodes.nfv.VduCpd
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: External connection point to access exteranlVl_2
+ requirements:
+ - external_virtual_link:
+ - virtual_binding: Vdu_2 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection0_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection0_0.yaml
new file mode 100644
index 000000000..a40e4262c
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection0_0.yaml
@@ -0,0 +1,9 @@
+name: TestEvent1
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+yaml_field:
+- Mark McGwire
+- Sammy Sosa
+- Ken Griffey \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection1_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection1_0.yaml
new file mode 100644
index 000000000..6d950321d
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection1_0.yaml
@@ -0,0 +1,8 @@
+name: TestEvent2
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+avg: 0.278
+hr: 65
+rbi: 147 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection2_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection2_0.yaml
new file mode 100644
index 000000000..b33b14ec9
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection2_0.yaml
@@ -0,0 +1,13 @@
+name: TestEvent3
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+american:
+- Boston Red Sox
+- Detroit Tigers
+- New York Yankees
+national:
+- New York Mets
+- Chicago Cubs
+- Atlanta Braves \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection3_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection3_0.yaml
new file mode 100644
index 000000000..bc99359ec
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection3_0.yaml
@@ -0,0 +1,12 @@
+name: TestEvent4
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+yaml_field:
+- name: Mark McGwire
+ hr: 65
+ avg: 0.278
+- name: Sammy Sosa
+ hr: 63
+ avg: 0.288 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection4_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection4_0.yaml
new file mode 100644
index 000000000..2d924ff1f
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection4_0.yaml
@@ -0,0 +1,15 @@
+name: TestEvent5
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+yaml_field:
+- - name
+ - hr
+ - avg
+- - Mark McGwire
+ - '65'
+ - '0.278'
+- - Sammy Sosa
+ - '63'
+ - '0.288' \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection5_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection5_0.yaml
new file mode 100644
index 000000000..e9e586acb
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Collection5_0.yaml
@@ -0,0 +1,11 @@
+name: TestEvent6
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+Mark McGwire:
+ hr: 65
+ avg: 0.278
+Sammy Sosa:
+ hr: 63
+ avg: 0.288
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Empty1_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Empty1_0.yaml
new file mode 100644
index 000000000..d2546754c
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Empty1_0.yaml
@@ -0,0 +1,5 @@
+name: TestEvent0
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: '' \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_0.yaml
new file mode 100644
index 000000000..fa98c2d8e
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_0.yaml
@@ -0,0 +1,9 @@
+name: TestEvent1
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+yaml_field:
+- Mark McGwire
+- Sammy Sosa
+- Ken Griffey
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_1.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_1.yaml
new file mode 100644
index 000000000..b8be6e580
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure0_1.yaml
@@ -0,0 +1,8 @@
+name: TestEvent1
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+yaml_field:
+- Chicago Cubs
+- St Louis Cardinals \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_0.yaml
new file mode 100644
index 000000000..e81ba58b4
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_0.yaml
@@ -0,0 +1,8 @@
+name: TestEvent7
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+action: strike (miss)
+player: Sammy Sosa
+time: 72200 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_1.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_1.yaml
new file mode 100644
index 000000000..4e0537e62
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure1_1.yaml
@@ -0,0 +1,8 @@
+name: TestEvent7
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+action: grand slam
+player: Sammy Sosa
+time: 72227 \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure2_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure2_0.yaml
new file mode 100644
index 000000000..44b797549
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure2_0.yaml
@@ -0,0 +1,11 @@
+name: TestEvent8
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+hr:
+- Mark McGwire
+- Sammy Sosa
+rbi:
+- Sammy Sosa
+- Ken Griffey \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure3_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure3_0.yaml
new file mode 100644
index 000000000..44b797549
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure3_0.yaml
@@ -0,0 +1,11 @@
+name: TestEvent8
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+hr:
+- Mark McGwire
+- Sammy Sosa
+rbi:
+- Sammy Sosa
+- Ken Griffey \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure4_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure4_0.yaml
new file mode 100644
index 000000000..084ab9941
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure4_0.yaml
@@ -0,0 +1,11 @@
+name: TestEvent9
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+AtlantaBraves:
+- 2001-07-02T00:00:00Z
+- 2001-08-12T00:00:00Z
+- 2001-08-14T00:00:00Z
+ChicagoCubs:
+- 2001-07-23T00:00:00Z \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure5_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure5_0.yaml
new file mode 100644
index 000000000..6ba5143d9
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/Structure5_0.yaml
@@ -0,0 +1,12 @@
+name: TestEvent10
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+yaml_field:
+- item: Super Hoop
+ quantity: 1
+- item: Basketball
+ quantity: 4
+- item: Big Shoes
+ quantity: 1
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/TOSCA0_0.yaml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/TOSCA0_0.yaml
new file mode 100644
index 000000000..910811f6e
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/resources/yaml_out/TOSCA0_0.yaml
@@ -0,0 +1,188 @@
+name: TestEvent11
+version: 0.0.1
+nameSpace: org.onap.policy.apex.plugins.event.protocol.yaml
+source: ''
+target: ''
+description: the VNFD of MyVnf
+node_types:
+ MyCompany.MyVnf.1_0.1_0:
+ derived_from: tosca.nodes.nfv.VNF
+ properties:
+ descriptor_id:
+ type: string
+ constraints:
+ - valid_values:
+ - b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
+ default: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
+ required: true
+ provider:
+ type: string
+ constraints:
+ - valid_values:
+ - MyCompany
+ default: MyCompany
+ required: true
+ product_name:
+ type: string
+ constraints:
+ - valid_values:
+ - MyVnf
+ default: Myvnf
+ required: true
+ software_version:
+ type: string
+ constraints:
+ - valid_values:
+ - '1.0'
+ default: '1.0'
+ required: true
+ descriptor_version:
+ type: string
+ constraints:
+ - valid_values:
+ - '1.0'
+ default: '1.0'
+ required: true
+ flavour_id:
+ type: string
+ constraints:
+ - valid_values:
+ - simple
+ default: simple
+ required: true
+ flavour_description:
+ type: string
+ constraints: []
+ default: ''
+ required: true
+ vnfm_info:
+ type: list
+ constraints: []
+ default: ''
+ required: true
+ interfaces:
+ Nfv:
+ instantiate:
+ inputs:
+ parameter_1:
+ type: string
+ required: false
+ default: value_1
+ constraints: []
+ parameter_2:
+ type: string
+ required: false
+ default: value_2
+ constraints: []
+ terminate:
+ implementation: terminate.workbook.mistral.yaml
+topology_template:
+ substitution_mappings:
+ node_type: MyCompany.MyVnf.1_0.1_0
+ requirements:
+ - virtual_link:
+ - Cp_2
+ - external_virtual_link
+ - virtual_link:
+ - Cp_4
+ - external_virtual_link
+ node_templates:
+ VDU_compute_1:
+ type: tosca.nodes.nfv.Vdu.Compute
+ properties:
+ name: ..
+ description: ..
+ boot_order: ..
+ nfvi_constraints: ..
+ configurable_properties:
+ additional_vnfc_configurable_properties: {}
+ vdu_profile:
+ min_number_of_instances: 1
+ max_number_of_instances: 4
+ capabilities:
+ virtual_compute:
+ properties:
+ virtual_memory:
+ virtual_mem_size: 8096 MB
+ virtual_cpu:
+ cpu_architecture: x86
+ num_virtual_cpu: 2
+ virtual_cpu_clock: 1800 MHz
+ requirements:
+ - virtual_storage: Storage_1
+ Storage_1:
+ type: tosca.nodes.nfv.Vdu.VirtualStorage
+ properties:
+ type_of_storage: ..
+ size_of_storage: 100MB
+ rdma_enabled: ..
+ Cp_1:
+ type: tosca.nodes.nfv.VduCp
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: Internal connection point on an VL
+ requirements:
+ - virtual_binding: Vdu_1
+ - virtual_link: internalVl_1
+ internalVl_1:
+ type: tosca.nodes.nfv.VirtualLink
+ properties:
+ connectivity_type:
+ layer_protocol: ipv4
+ flow_pattern: mesh
+ test_access: []
+ description: ..
+ vl_profile:
+ qos: null
+ maxBitRateRequirements: null
+ minBitRateRequirements: null
+ Cp_2:
+ type: tosca.nodes.nfv.VduCp
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: External connection point to access exteranlVl_1
+ requirements:
+ - external_virtual_link: null
+ - virtual_binding: Vdu_1
+ VDU_compute_2:
+ type: tosca.nodes.nfv.Vdu.Compute
+ properties:
+ name: ..
+ description: ..
+ boot_order: ..
+ nfvi_constraints: ..
+ configurable_properties:
+ additional_vnfc_configurable_properties: {}
+ vdu_profile:
+ min_number_of_instances: 2
+ max_number_of_instances: 6
+ capabilities:
+ virtual_compute:
+ properties:
+ virtual_memory:
+ virtual_mem_size: 8096 MB
+ virtual_cpu:
+ cpu_architecture: x86
+ num_virtual_cpu: 4
+ virtual_cpu_clock: 1800 MHz
+ Cp_3:
+ type: tosca.nodes.nfv.VduCp
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: Internal connection point on an VL
+ requirements:
+ - virtual_binding: Vdu_2
+ - virtual_link: internalVl_1
+ Cp_4:
+ type: tosca.nodes.nfv.VduCpd
+ properties:
+ layer_protocol: ipv4
+ role: leaf
+ description: External connection point to access exteranlVl_2
+ requirements:
+ - external_virtual_link: null
+ - virtual_binding: Vdu_2
+tosca_definitions_version: tosca_simple_profile_yaml_1_1 \ No newline at end of file
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
index 552f949a2..99728c02e 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
@@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -160,7 +161,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
* @throws ApexEventException the apex event exception
*/
private String validKey(final String key) throws ApexEventException {
- if (key.matches(NAME_REGEXP)) {
+ if (key.matches(AxReferenceKey.LOCAL_NAME_REGEXP)) {
return key;
}
else {
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java
index e40bc756c..07185c024 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java
@@ -45,8 +45,16 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
// The amount of time to wait for input on the text block reader
private static final long TEXT_BLOCK_DELAY = 250;
- // Tag for the start of a text block
+ // Tag for the start and end of text blocks
private final String blockStartToken;
+ private final String blockEndToken;
+
+ // Indicates that text block processing starts at the first block of text
+ private final boolean delimiterAtStart;
+ private boolean blockEndTokenUsed = false;
+
+ // The thread used to read the text from the stream
+ Thread textConsumputionThread;
// The input stream for text
private InputStream inputStream;
@@ -54,37 +62,49 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
// The lines of input read from the input stream
private final Queue<String> textLineQueue = new LinkedBlockingQueue<>();
- // The thread used to read text from the input stream
- private Thread textConsumputionThread;
-
// True while EOF has not been seen on input
private boolean eofOnInputStream = false;
/**
- * Constructor, initialize the text block reader.
+ * Constructor, initialize the text block reader using token delimited event protocol parameters.
*
- * @param blockStartToken the block start token for the start of a text block
+ * @param tokenDelimitedParameters
+ * the token delimited event protocol parameters
*/
- public HeaderDelimitedTextBlockReader(final String blockStartToken) {
- this.blockStartToken = blockStartToken;
+ public HeaderDelimitedTextBlockReader(final EventProtocolTextTokenDelimitedParameters tokenDelimitedParameters) {
+ this(tokenDelimitedParameters.getStartDelimiterToken(), tokenDelimitedParameters.getEndDelimiterToken(),
+ tokenDelimitedParameters.isDelimiterAtStart());
}
/**
- * Constructor, initialize the text block reader using token delimited event protocol
- * parameters.
+ * Constructor, initialize the text block reader.
*
- * @param tokenDelimitedParameters the token delimited event protocol parameters
+ * @param blockStartToken
+ * the block start token for the start of a text block
+ * @param blockEndToken
+ * the block end token for the end of a text block
+ * @param delimiterAtStart
+ * indicates that text block processing starts at the first block of text
*/
- public HeaderDelimitedTextBlockReader(final EventProtocolTextTokenDelimitedParameters tokenDelimitedParameters) {
- this.blockStartToken = tokenDelimitedParameters.getDelimiterToken();
+ public HeaderDelimitedTextBlockReader(final String blockStartToken, final String blockEndToken,
+ final boolean delimiterAtStart) {
+ this.blockStartToken = blockStartToken;
+ this.delimiterAtStart = delimiterAtStart;
+
+ if (blockEndToken == null) {
+ this.blockEndToken = blockStartToken;
+ this.blockEndTokenUsed = false;
+ } else {
+ this.blockEndToken = blockEndToken;
+ this.blockEndTokenUsed = true;
+ }
}
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader#
- * init( java.io.InputStream)
+ * @see org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader# init(
+ * java.io.InputStream)
*/
@Override
public void init(final InputStream incomingInputStream) {
@@ -99,9 +119,7 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader#
- * readTextBlock()
+ * @see org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader# readTextBlock()
*/
@Override
public TextBlock readTextBlock() throws IOException {
@@ -109,32 +127,42 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
final StringBuilder textBlockBuilder = new StringBuilder();
// Wait for the timeout period if there is no input
- if (!eofOnInputStream && textLineQueue.size() == 0) {
+ if (!eofOnInputStream && textLineQueue.isEmpty()) {
ThreadUtilities.sleep(TEXT_BLOCK_DELAY);
}
// Scan the lines in the queue
- while (textLineQueue.size() > 0) {
+ while (!textLineQueue.isEmpty()) {
// Scroll down in the available lines looking for the start of the text block
- if (textLineQueue.peek().startsWith(blockStartToken)) {
+ if (!delimiterAtStart || textLineQueue.peek().startsWith(blockStartToken)) {
// Process the input line header
textBlockBuilder.append(textLineQueue.remove());
textBlockBuilder.append('\n');
break;
} else {
- LOGGER.warn("invalid input on consumer: " + textLineQueue.remove());
+ String consumer = textLineQueue.remove();
+ LOGGER.warn("invalid input on consumer: {}", consumer);
}
}
// Get the rest of the text document
- while (textLineQueue.size() > 0 && !textLineQueue.peek().startsWith(blockStartToken)) {
+ while (!textLineQueue.isEmpty() && !textLineQueue.peek().startsWith(blockEndToken)
+ && !textLineQueue.peek().startsWith(blockStartToken)) {
+ // We just strip out block end tokens because we use block start tokens to delimit the blocks of text
+ textBlockBuilder.append(textLineQueue.remove());
+ textBlockBuilder.append('\n');
+ }
+
+ // Check if we should add the block end token to the end of the text block
+ if (!textLineQueue.isEmpty() && blockEndTokenUsed && textLineQueue.peek().startsWith(blockEndToken)) {
+ // Process the input line header
textBlockBuilder.append(textLineQueue.remove());
textBlockBuilder.append('\n');
}
// Condition the text block and return it
final String textBlock = textBlockBuilder.toString().trim();
- final boolean endOfText = (eofOnInputStream && textLineQueue.size() == 0 ? true : false);
+ final boolean endOfText = (eofOnInputStream && textLineQueue.isEmpty() ? true : false);
if (textBlock.length() > 0) {
return new TextBlock(endOfText, textBlock);
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java
index 3b21a29ca..223843631 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java
@@ -43,8 +43,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
/**
- * The Class Apex2JSONEventConverter converts {@link ApexEvent} instances to and from JSON string
- * representations of Apex events.
+ * The Class Apex2JSONEventConverter converts {@link ApexEvent} instances to and from JSON string representations of
+ * Apex events.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -57,8 +57,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter#init(org.onap.policy.
+ * @see org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter#init(org.onap.policy.
* apex.service.parameters.eventprotocol.EventProtocolParameters)
*/
@Override
@@ -76,9 +75,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String,
- * java.lang.Object)
+ * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String, java.lang.Object)
*/
@Override
public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException {
@@ -100,12 +97,12 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
}
// The list of events we will return
- final List<ApexEvent> eventList = new ArrayList<ApexEvent>();
+ final List<ApexEvent> eventList = new ArrayList<>();
try {
// We may have a single JSON object with a single event or an array of JSON objects
- final Object decodedJsonObject =
- new GsonBuilder().serializeNulls().create().fromJson(jsonEventString, Object.class);
+ final Object decodedJsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
+ Object.class);
// Check if we have a list of objects
if (decodedJsonObject instanceof List) {
@@ -121,15 +118,15 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
eventList.add(jsonObject2ApexEvent(eventName, (JsonObject) jsonListObject));
} else {
throw new ApexEventException("incoming event (" + jsonEventString
- + ") is a JSON object array containing an invalid object " + jsonListObject);
+ + ") is a JSON object array containing an invalid object " + jsonListObject);
}
}
} else {
eventList.add(jsonStringApexEvent(eventName, jsonEventString));
}
} catch (final Exception e) {
- final String errorString =
- "Failed to unmarshal JSON event: " + e.getMessage() + ", event=" + jsonEventString;
+ final String errorString = "Failed to unmarshal JSON event: " + e.getMessage() + ", event="
+ + jsonEventString;
LOGGER.warn(errorString, e);
throw new ApexEventException(errorString, e);
}
@@ -141,8 +138,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.
+ * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.
* apex.service.engine.event.ApexEvent)
*/
@Override
@@ -154,8 +150,8 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
}
// Get the event definition for the event from the model service
- final AxEvent eventDefinition =
- ModelService.getModel(AxEvents.class).get(apexEvent.getName(), apexEvent.getVersion());
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
+ apexEvent.getVersion());
// Use a GSON Json object to marshal the Apex event to JSON
final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
@@ -177,7 +173,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
if (!apexEvent.containsKey(fieldName)) {
if (!eventField.getOptional()) {
final String errorMessage = "error parsing " + eventDefinition.getID() + " event to Json. "
- + "Field \"" + fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
+ + "Field \"" + fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
LOGGER.debug(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
@@ -187,9 +183,9 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
final Object fieldValue = apexEvent.get(fieldName);
// Get the schema helper
- final SchemaHelper fieldSchemaHelper =
- new SchemaHelperFactory().createSchemaHelper(eventField.getKey(), eventField.getSchema());
- jsonObject.add(fieldName, fieldSchemaHelper.marshal2JsonElement(fieldValue));
+ final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ eventField.getSchema());
+ jsonObject.add(fieldName, (JsonElement)fieldSchemaHelper.marshal2Object(fieldValue));
}
// Output JSON string in a pretty format
@@ -199,20 +195,23 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method converts a JSON object into an Apex event.
*
- * @param eventName the name of the event
- * @param jsonEventString the JSON string that holds the event
+ * @param eventName
+ * the name of the event
+ * @param jsonEventString
+ * the JSON string that holds the event
* @return the apex event that we have converted the JSON object into
- * @throws ApexEventException thrown on unmarshaling exceptions
+ * @throws ApexEventException
+ * thrown on unmarshaling exceptions
*/
private ApexEvent jsonStringApexEvent(final String eventName, final String jsonEventString)
- throws ApexEventException {
+ throws ApexEventException {
// Use GSON to read the event string
- final JsonObject jsonObject =
- new GsonBuilder().serializeNulls().create().fromJson(jsonEventString, JsonObject.class);
+ final JsonObject jsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
+ JsonObject.class);
if (jsonObject == null || !jsonObject.isJsonObject()) {
throw new ApexEventException(
- "incoming event (" + jsonEventString + ") is not a JSON object or an JSON object array");
+ "incoming event (" + jsonEventString + ") is not a JSON object or an JSON object array");
}
return jsonObject2ApexEvent(eventName, jsonObject);
@@ -221,19 +220,22 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method converts a JSON object into an Apex event.
*
- * @param eventName the name of the event
- * @param jsonObject the JSON object that holds the event
+ * @param eventName
+ * the name of the event
+ * @param jsonObject
+ * the JSON object that holds the event
* @return the apex event that we have converted the JSON object into
- * @throws ApexEventException thrown on unmarshaling exceptions
+ * @throws ApexEventException
+ * thrown on unmarshaling exceptions
*/
private ApexEvent jsonObject2ApexEvent(final String eventName, final JsonObject jsonObject)
- throws ApexEventException {
+ throws ApexEventException {
// Process the mandatory Apex header
final ApexEvent apexEvent = processApexEventHeader(eventName, jsonObject);
// Get the event definition for the event from the model service
- final AxEvent eventDefinition =
- ModelService.getModel(AxEvents.class).get(apexEvent.getName(), apexEvent.getVersion());
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
+ apexEvent.getVersion());
// Iterate over the input fields in the event
for (final AxField eventField : eventDefinition.getFields()) {
@@ -241,7 +243,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
if (!hasJSONField(jsonObject, fieldName)) {
if (!eventField.getOptional()) {
final String errorMessage = "error parsing " + eventDefinition.getID() + " event from Json. "
- + "Field \"" + fieldName + "\" is missing, but is mandatory.";
+ + "Field \"" + fieldName + "\" is missing, but is mandatory.";
LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
@@ -252,8 +254,8 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
if (fieldValue != null && !fieldValue.isJsonNull()) {
// Get the schema helper
- final SchemaHelper fieldSchemaHelper =
- new SchemaHelperFactory().createSchemaHelper(eventField.getKey(), eventField.getSchema());
+ final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ eventField.getSchema());
apexEvent.put(fieldName, fieldSchemaHelper.createNewInstance(fieldValue));
} else {
apexEvent.put(fieldName, null);
@@ -266,48 +268,48 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method processes the event header of an Apex event.
*
- * @param eventName the name of the event
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
+ * @param eventName
+ * the name of the event
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
* @return an apex event constructed using the header fields of the event
- * @throws ApexEventRuntimeException the apex event runtime exception
- * @throws ApexEventException on invalid events with missing header fields
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
+ * @throws ApexEventException
+ * on invalid events with missing header fields
*/
private ApexEvent processApexEventHeader(final String eventName, final JsonObject jsonObject)
- throws ApexEventRuntimeException, ApexEventException {
+ throws ApexEventException {
// Get the event header fields
- // @formatter:off
- String name = getJSONStringField(jsonObject, ApexEvent.NAME_HEADER_FIELD, jsonPars.getNameAlias(), ApexEvent.NAME_REGEXP, false);
- String version = getJSONStringField(jsonObject, ApexEvent.VERSION_HEADER_FIELD, jsonPars.getVersionAlias(), ApexEvent.VERSION_REGEXP, false);
- String namespace = getJSONStringField(jsonObject, ApexEvent.NAMESPACE_HEADER_FIELD, jsonPars.getNameSpaceAlias(), ApexEvent.NAMESPACE_REGEXP, false);
- String source = getJSONStringField(jsonObject, ApexEvent.SOURCE_HEADER_FIELD, jsonPars.getSourceAlias(), ApexEvent.SOURCE_REGEXP, false);
- String target = getJSONStringField(jsonObject, ApexEvent.TARGET_HEADER_FIELD, jsonPars.getTargetAlias(), ApexEvent.TARGET_REGEXP, false);
- // @formatter:on
+ // @formatter:off
+ String name = getJSONStringField(jsonObject, ApexEvent.NAME_HEADER_FIELD, jsonPars.getNameAlias(), ApexEvent.NAME_REGEXP, false);
+ String version = getJSONStringField(jsonObject, ApexEvent.VERSION_HEADER_FIELD, jsonPars.getVersionAlias(), ApexEvent.VERSION_REGEXP, false);
+ String namespace = getJSONStringField(jsonObject, ApexEvent.NAMESPACE_HEADER_FIELD, jsonPars.getNameSpaceAlias(), ApexEvent.NAMESPACE_REGEXP, false);
+ String source = getJSONStringField(jsonObject, ApexEvent.SOURCE_HEADER_FIELD, jsonPars.getSourceAlias(), ApexEvent.SOURCE_REGEXP, false);
+ String target = getJSONStringField(jsonObject, ApexEvent.TARGET_HEADER_FIELD, jsonPars.getTargetAlias(), ApexEvent.TARGET_REGEXP, false);
+ // @formatter:on
+
+ // Check that an event name has been specified
+ if (name == null && eventName == null) {
+ throw new ApexEventRuntimeException(
+ "event received without mandatory parameter \"name\" on configuration or on event");
+ }
// Check if an event name was specified on the event parameters
if (eventName != null) {
if (name != null && !eventName.equals(name)) {
- LOGGER.warn("The incoming event name \"" + name + "\" does not match the configured event name \""
- + eventName + "\", using configured event name");
+ LOGGER.warn("The incoming event name \"{}\" does not match the configured event name \"{}\", using configured event name",
+ name, eventName);
}
name = eventName;
- } else {
- if (name == null) {
- throw new ApexEventRuntimeException(
- "event received without mandatory parameter \"name\" on configuration or on event");
- }
}
// Now, find the event definition in the model service. If version is null, the newest event
// definition in the model service is used
final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(name, version);
if (eventDefinition == null) {
- if (version == null) {
- throw new ApexEventRuntimeException(
- "an event definition for an event named \"" + name + "\" not found in Apex model");
- } else {
- throw new ApexEventRuntimeException("an event definition for an event named \"" + name
- + "\" with version \"" + version + "\" not found in Apex model");
- }
+ throw new ApexEventRuntimeException("an event definition for an event named \"" + name
+ + "\" with version \"" + version + "\" not found in Apex model");
}
// Use the defined event version if no version is specified on the incoming fields
@@ -318,9 +320,9 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
// Check the name space is OK if it is defined, if not, use the name space from the model
if (namespace != null) {
if (!namespace.equals(eventDefinition.getNameSpace())) {
- throw new ApexEventRuntimeException(
- "namespace \"" + namespace + "\" on event \"" + name + "\" does not match namespace \""
- + eventDefinition.getNameSpace() + "\" for that event in the Apex model");
+ throw new ApexEventRuntimeException("namespace \"" + namespace + "\" on event \"" + name
+ + "\" does not match namespace \"" + eventDefinition.getNameSpace()
+ + "\" for that event in the Apex model");
}
} else {
namespace = eventDefinition.getNameSpace();
@@ -342,17 +344,22 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method gets an event string field from a JSON object.
*
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
- * @param fieldName the field name to find in the event
- * @param fieldAlias the alias for the field to find in the event, overrides the field name if
- * it is not null
- * @param fieldRE the regular expression to check the field against for validity
- * @param mandatory true if the field is mandatory
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
+ * @param fieldAlias
+ * the alias for the field to find in the event, overrides the field name if it is not null
+ * @param fieldRE
+ * the regular expression to check the field against for validity
+ * @param mandatory
+ * true if the field is mandatory
* @return the value of the field in the JSON object or null if the field is optional
- * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
*/
private String getJSONStringField(final JsonObject jsonObject, final String fieldName, final String fieldAlias,
- final String fieldRE, final boolean mandatory) throws ApexEventRuntimeException {
+ final String fieldRE, final boolean mandatory) {
// Get the JSON field for the string field
final JsonElement jsonField = getJSONField(jsonObject, fieldName, fieldAlias, mandatory);
@@ -368,7 +375,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
} catch (final Exception e) {
// The element is not a string so throw an error
throw new ApexEventRuntimeException("field \"" + fieldName + "\" with type \""
- + jsonField.getClass().getCanonicalName() + "\" is not a string value");
+ + jsonField.getClass().getCanonicalName() + "\" is not a string value");
}
// Is regular expression checking required
@@ -379,7 +386,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
// Check the event field against its regular expression
if (!fieldValueString.matches(fieldRE)) {
throw new ApexEventRuntimeException(
- "field \"" + fieldName + "\" with value \"" + fieldValueString + "\" is invalid");
+ "field \"" + fieldName + "\" with value \"" + fieldValueString + "\" is invalid");
}
return fieldValueString;
@@ -388,16 +395,20 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method gets an event field from a JSON object.
*
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
- * @param fieldName the field name to find in the event
- * @param fieldAlias the alias for the field to find in the event, overrides the field name if
- * it is not null
- * @param mandatory true if the field is mandatory
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
+ * @param fieldAlias
+ * the alias for the field to find in the event, overrides the field name if it is not null
+ * @param mandatory
+ * true if the field is mandatory
* @return the value of the field in the JSON object or null if the field is optional
- * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
*/
private JsonElement getJSONField(final JsonObject jsonObject, final String fieldName, final String fieldAlias,
- final boolean mandatory) throws ApexEventRuntimeException {
+ final boolean mandatory) {
// Check if we should use the alias for this field
String fieldToFind = fieldName;
@@ -421,12 +432,15 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method if a JSON object has a named field.
*
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
- * @param fieldName the field name to find in the event
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
* @return true if the field is present
- * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
*/
- private boolean hasJSONField(final JsonObject jsonObject, final String fieldName) throws ApexEventRuntimeException {
+ private boolean hasJSONField(final JsonObject jsonObject, final String fieldName) {
// check for the field
return jsonObject.has(fieldName);
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java
index b4a4055d7..5f2b74204 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java
@@ -51,11 +51,11 @@ public class JSONEventProtocolParameters extends EventProtocolTextCharDelimitedP
// Aliases for Apex event header fields
// @formatter:off
- private final String nameAlias = null;
- private final String versionAlias = null;
- private final String nameSpaceAlias = null;
- private final String sourceAlias = null;
- private final String targetAlias = null;
+ private String nameAlias = null;
+ private String versionAlias = null;
+ private String nameSpaceAlias = null;
+ private String sourceAlias = null;
+ private String targetAlias = null;
// @formatter:on
/**
@@ -131,5 +131,49 @@ public class JSONEventProtocolParameters extends EventProtocolTextCharDelimitedP
public String getTargetAlias() {
return targetAlias;
}
+
+ /**
+ * Sets the name alias.
+ *
+ * @param nameAlias the new name alias
+ */
+ public void setNameAlias(String nameAlias) {
+ this.nameAlias = nameAlias;
+ }
+
+ /**
+ * Sets the version alias.
+ *
+ * @param versionAlias the new version alias
+ */
+ public void setVersionAlias(String versionAlias) {
+ this.versionAlias = versionAlias;
+ }
+ /**
+ * Sets the name space alias.
+ *
+ * @param nameSpaceAlias the new name space alias
+ */
+ public void setNameSpaceAlias(String nameSpaceAlias) {
+ this.nameSpaceAlias = nameSpaceAlias;
+ }
+
+ /**
+ * Sets the source alias.
+ *
+ * @param sourceAlias the new source alias
+ */
+ public void setSourceAlias(String sourceAlias) {
+ this.sourceAlias = sourceAlias;
+ }
+
+ /**
+ * Sets the target alias.
+ *
+ * @param targetAlias the new target alias
+ */
+ public void setTargetAlias(String targetAlias) {
+ this.targetAlias = targetAlias;
+ }
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
index f74c0f47b..9a9888652 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
@@ -589,7 +589,7 @@ final class EngineWorker implements EngineService {
runtimeJsonStringBuilder.append("{\"EntryName\":");
runtimeJsonStringBuilder.append(gson.toJson(contextEntry.getKey()));
runtimeJsonStringBuilder.append(",\"EntryContent\":");
- runtimeJsonStringBuilder.append(gson.toJson(schemaHelper.marshal2Json(contextEntry.getValue())));
+ runtimeJsonStringBuilder.append(gson.toJson(schemaHelper.marshal2String(contextEntry.getValue())));
// End of context entry
runtimeJsonStringBuilder.append("}");
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
index 37fbd32bf..91a6403df 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
@@ -23,56 +23,100 @@ package org.onap.policy.apex.service.parameters.eventprotocol;
import org.onap.policy.apex.service.parameters.ApexParameterValidator;
/**
- * An event protocol parameter class for token delimited textual event protocols that may be
- * specialized by event protocol plugins that require plugin specific parameters.
+ * An event protocol parameter class for token delimited textual event protocols that may be specialized by event
+ * protocol plugins that require plugin specific parameters.
*
* <p>
* The following parameters are defined:
* <ol>
- * <li>delimiterToken: the token string that delimits text blocks that contain events.
+ * <li>startDelimiterToken: the token string that delimits the start of text blocks that contain events.
+ * <li>endDelimiterToken: the token string that delimits the end of text blocks that contain events, this parameter is
+ * optional and defaults to null.
+ * <li>delimiterAtStart: indicates if the first text block should have a delimiter at the start (true), or whether
+ * processing of the first block should begin at the start of the text (false). The parameter is optional and defaults
+ * to true.
* </ol>
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public abstract class EventProtocolTextTokenDelimitedParameters extends EventProtocolParameters
- implements ApexParameterValidator {
+ implements ApexParameterValidator {
// The delimiter token for text blocks
- private String delimiterToken = null;
+ private String startDelimiterToken = null;
+ private String endDelimiterToken = null;
+ private boolean delimiterAtStart = true;
/**
- * Constructor to create an event protocol parameters instance with the name of a sub class of
- * this class.
+ * Constructor to create an event protocol parameters instance with the name of a sub class of this class.
*
- * @param parameterClassName the class name of a sub class of this class
+ * @param parameterClassName
+ * the class name of a sub class of this class
*/
public EventProtocolTextTokenDelimitedParameters(final String parameterClassName) {
super(parameterClassName);
}
/**
- * Gets the delimiter token that delimits events in the text.
+ * Gets the start delimiter token that delimits events in the text.
*
- * @return the delimiter token
+ * @return the start delimiter token
*/
- public String getDelimiterToken() {
- return delimiterToken;
+ public String getStartDelimiterToken() {
+ return startDelimiterToken;
}
+ /**
+ * Sets the start delimiter token that delimits events in the text.
+ *
+ * @param startDelimiterToken
+ * delimiterToken the delimiter token
+ */
+ public void setStartDelimiterToken(final String startDelimiterToken) {
+ this.startDelimiterToken = startDelimiterToken;
+ }
+
+ /**
+ * Gets the end delimiter token that delimits events in the text.
+ *
+ * @return the end delimiter token
+ */
+ public String getEndDelimiterToken() {
+ return endDelimiterToken;
+ }
/**
- * Sets the delimiter token that delimits events in the text.
+ * Sets the end delimiter token that delimits events in the text.
*
- * @param delimiterToken the delimiter token
+ * @param endDelimiterToken
+ * delimiterToken the delimiter token
+ */
+ public void setEndDelimiterToken(final String endDelimiterToken) {
+ this.endDelimiterToken = endDelimiterToken;
+ }
+
+ /**
+ * Does there have to be a delimiter at the start of the first text block?
+ *
+ * @return true if there must be a delimiter at the start of the text block
*/
- public void setDelimiterToken(final String delimiterToken) {
- this.delimiterToken = delimiterToken;
+ public boolean isDelimiterAtStart() {
+ return delimiterAtStart;
}
+ /**
+ * Sets if there has to be a delimiter at the start of the first text block?
+ *
+ * @param delimiterAtStart
+ * true if there must be a delimiter at the start of the text block
+ */
+ public void setDelimiterAtStart(boolean delimiterAtStart) {
+ this.delimiterAtStart = delimiterAtStart;
+ }
@Override
public String toString() {
- return "EventProtocolTextCharDelimitedParameters {" + super.toString() + "} [delimiterToken=" + delimiterToken
- + "]";
+ return "EventProtocolTextTokenDelimitedParameters [startDelimiterToken=" + startDelimiterToken
+ + ", endDelimiterToken=" + endDelimiterToken + ", delimiterAtStart=" + delimiterAtStart + "]";
}
/*
@@ -86,8 +130,8 @@ public abstract class EventProtocolTextTokenDelimitedParameters extends EventPro
errorMessageBuilder.append(super.validate());
- if (delimiterToken == null || delimiterToken.length() == 0) {
- errorMessageBuilder.append(" text delimiter token not specified or is blank\n");
+ if (startDelimiterToken == null || startDelimiterToken.length() == 0) {
+ errorMessageBuilder.append(" text start delimiter token not specified or is blank\n");
}
return errorMessageBuilder.toString();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java
index 99f938e10..bac271319 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java
@@ -46,7 +46,7 @@ public class SuperTokenDelimitedEventProtocolParameters extends EventProtocolTex
this.setLabel(SUPER_TOKEN_EVENT_PROTOCOL_LABEL);
// Set the starting and ending delimiters for text blocks of JSON events
- this.setDelimiterToken(SUPER_TOKEN_DELIMITER);
+ this.setStartDelimiterToken(SUPER_TOKEN_DELIMITER);
// Set the event protocol plugin class
this.setEventProtocolPluginClass(SuperTokenDelimitedEventConverter.class.getCanonicalName());