aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-06-13 16:50:59 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-06-14 11:22:00 +0100
commit4fcf04234e5e1b1d4338f12d982a45edf317d795 (patch)
treea17fb2a9dd70064145312b75c9d1019086cb11c1 /plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml
parent2e1da7176952e013276ef29638a313f3a1b49c00 (diff)
Add YAML plugin and cleanup for checkstyle
Bringing in the APEX YAML plugin, allows events with YAML bodies to be consumed by APEX. Also clean up of event protocol interface to make it not specific for JSON. Also some checkstyle changes on classes impacted by event protocol interface change. Change-Id: I7c3867ac508096fd8acad2488e61db87dfa1d6bd Issue-ID: POLICY-862 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml')
-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
37 files changed, 1794 insertions, 0 deletions
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