summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-protocol
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-09-13 15:25:32 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-09-13 15:26:47 +0100
commit4cfa2e2d98f6877d54da304ef17f096284430908 (patch)
treec9452d2bf6bb96fae9c1e8e2d8ce8f8d01e69d22 /plugins/plugins-event/plugins-event-protocol
parent0e23f7634e1e1fb31454c516974613335fcea1a4 (diff)
Sonar/Checkstyle in service/plugins
Sonar and Checkstyle changes in plugins and services, and knock on changes Issue-ID: POLICY-1034 Change-Id: Iff7df74e54fce2c661dcc2fae75ae93d4cacfe5b Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol')
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java)32
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java)15
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParameters.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSObjectEventProtocolParameters.java)24
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JmsTextEventProtocolParameters.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSTextEventProtocolParameters.java)28
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XMLEventConverter.java)18
-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.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventProtocolParameters.java)8
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXmlEventHandler.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLEventHandler.java)50
-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.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLTaggedEventConsumer.java)244
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java (renamed from plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventGenerator.java)27
-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.java79
-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.java2
-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.java83
-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.java26
13 files changed, 396 insertions, 240 deletions
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java
index 6c21070c2..ca02709fe 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSObjectEventConverter.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java
@@ -33,24 +33,23 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The Class Apex2JMSObjectEventConverter converts {@link ApexEvent} instances into string instances of
- * object message events for JMS.
+ * The Class Apex2JMSObjectEventConverter converts {@link ApexEvent} instances into string instances of object message
+ * events for JMS.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConverter {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JMSObjectEventConverter.class);
+public final class Apex2JmsObjectEventConverter implements ApexEventProtocolConverter {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JmsObjectEventConverter.class);
// JMS event protocol parameters on the consumer (JMS->Apex) sides
- private JMSObjectEventProtocolParameters eventProtocolParameters = null;
+ private JmsObjectEventProtocolParameters eventProtocolParameters = null;
/**
* Constructor to create the Apex to JMS Object converter.
*
- * @throws ApexEventException
- * the apex event exception
+ * @throws ApexEventException the apex event exception
*/
- public Apex2JMSObjectEventConverter() throws ApexEventException {
+ public Apex2JmsObjectEventConverter() throws ApexEventException {
// Nothing specific to initiate for this plugin
}
@@ -59,13 +58,13 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv
// Check if properties have been set for JMS object event conversion as a consumer. They may not be set because
// JMS may not be in use
// on both sides of Apex
- if (!(parameters instanceof JMSObjectEventProtocolParameters)) {
+ if (!(parameters instanceof JmsObjectEventProtocolParameters)) {
final String errormessage = "specified Event Protocol Parameters properties of type \""
+ parameters.getClass().getCanonicalName() + "\" are not applicable to a "
- + Apex2JMSObjectEventConverter.class.getName() + " converter";
+ + Apex2JmsObjectEventConverter.class.getName() + " converter";
LOGGER.error(errormessage);
} else {
- this.eventProtocolParameters = (JMSObjectEventProtocolParameters) parameters;
+ this.eventProtocolParameters = (JmsObjectEventProtocolParameters) parameters;
}
}
@@ -101,7 +100,8 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv
// Check that the consumer parameters for JMS->Apex messaging have been set
if (eventProtocolParameters == null) {
- final String errorMessage = "consumer parameters for JMS events consumed by Apex are not set in the Apex configuration for this engine";
+ final String errorMessage = "consumer parameters for JMS events consumed by "
+ + "Apex are not set in the Apex configuration for this engine";
LOGGER.debug(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
@@ -114,7 +114,7 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv
jmsIncomingObject.toString().getClass().getPackage().getName(),
eventProtocolParameters.getIncomingEventSource(),
eventProtocolParameters.getIncomingEventTarget());
- // @formattter:on
+ // @formatter:on
// Set the data on the apex event as the incoming object
apexEvent.put(jmsIncomingObject.getClass().getSimpleName(), jmsIncomingObject);
@@ -128,7 +128,8 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv
/*
* (non-Javadoc)
*
- * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.apex.service.engine.event.ApexEvent)
+ * @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 {
@@ -140,7 +141,8 @@ public final class Apex2JMSObjectEventConverter implements ApexEventProtocolConv
// Check that the Apex event has a single parameter
if (apexEvent.size() != 1) {
- final String errorMessage = "event processing failed, Apex event must have one and only one parameter for JMS Object handling";
+ final String errorMessage = "event processing failed, "
+ + "Apex event must have one and only one parameter for JMS Object handling";
LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java
index e845a4a08..1c44dd111 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JMSTextEventConverter.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java
@@ -26,26 +26,19 @@ import java.util.List;
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;
-import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JSONEventConverter;
+import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
* The Class Apex2JMSTextEventConverter converts {@link ApexEvent} instances into string instances of
* text message events for JMS. It is a proxy for the built in
- * {@link org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JSONEventConverter} plugin.
+ * {@link org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter} plugin.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public final class Apex2JMSTextEventConverter extends Apex2JSONEventConverter {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JMSTextEventConverter.class);
-
- /**
- * Constructor to create the Apex to JMS Object converter.
- *
- * @throws ApexEventException the apex event exception
- */
- public Apex2JMSTextEventConverter() throws ApexEventException {}
+public final class Apex2JmsTextEventConverter extends Apex2JsonEventConverter {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2JmsTextEventConverter.class);
/*
* (non-Javadoc)
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSObjectEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParameters.java
index 83aef4e9d..3c15a7825 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSObjectEventProtocolParameters.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParameters.java
@@ -25,8 +25,7 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame
/**
* Event protocol parameters for JMS Object messages as an event protocol.
*
- * <p>
- * On reception of an a JMS {@code javax.jms.ObjectMessage}, the JMS Object plugin unmarshals the message as follows:
+ * <p>On reception of an a JMS {@code javax.jms.ObjectMessage}, the JMS Object plugin unmarshals the message as follows:
* <ol>
* <li>It extracts the Java object from the {@code javax.jms.ObjectMessage} instance.</li>
* <li>It creates an {@link org.onap.policy.apex.service.engine.event.ApexEvent} instance to hold the java object.</li>
@@ -40,11 +39,11 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame
* <li>It puts a single entry into the Apex event map with the the simple class name of the incoming Java object being
* the key of the entry and the actual incoming object as the value of the entry.</li>
* </ol>
- * <p>
- * When sending an object to JMS, the plugin expects to receive an Apex event with a single entry. The plugin marshals
- * the value of that entry to an object that can be sent by JMS as a {@code javax.jms.ObjectMessage} instance.
- * <p>
- * The parameters for this plugin are:
+ *
+ * <p>When sending an object to JMS, the plugin expects to receive an Apex event with a single entry. The plugin
+ * marshals the value of that entry to an object that can be sent by JMS as a {@code javax.jms.ObjectMessage} instance.
+ *
+ * <p>The parameters for this plugin are:
* <ol>
* <li>incomingEventSuffix: The suffix to append to the simple name of incoming Java class instances when they are
* encapsulated in Apex events. The parameter defaults to the string value {@code IncomingEvent}.</li>
@@ -58,7 +57,7 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class JMSObjectEventProtocolParameters extends EventProtocolParameters {
+public class JmsObjectEventProtocolParameters extends EventProtocolParameters {
/** The label of this event protocol. */
public static final String JMS_OBJECT_EVENT_PROTOCOL_LABEL = "JMSOBJECT";
@@ -77,16 +76,17 @@ public class JMSObjectEventProtocolParameters extends EventProtocolParameters {
//@formatter:off
/**
- * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter service.
+ * Constructor to create a JSON event protocol parameter instance and register the instance with the
+ * parameter service.
*/
- public JMSObjectEventProtocolParameters() {
- super(JMSObjectEventProtocolParameters.class.getCanonicalName());
+ public JmsObjectEventProtocolParameters() {
+ super(JmsObjectEventProtocolParameters.class.getCanonicalName());
// Set the event protocol properties for the JMS Text event protocol
this.setLabel(JMS_OBJECT_EVENT_PROTOCOL_LABEL);
// Set the event protocol plugin class
- this.setEventProtocolPluginClass(Apex2JMSObjectEventConverter.class.getCanonicalName());
+ this.setEventProtocolPluginClass(Apex2JmsObjectEventConverter.class.getCanonicalName());
}
/**
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSTextEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JmsTextEventProtocolParameters.java
index b3a9154ff..67b211a08 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JMSTextEventProtocolParameters.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/JmsTextEventProtocolParameters.java
@@ -20,23 +20,23 @@
package org.onap.policy.apex.plugins.event.protocol.jms;
-import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JSONEventProtocolParameters;
+import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
/**
* Event protocol parameters for JMS Text messages as an event protocol.
- * <p>
- * Text messages received and sent over JMS in ~Text format are assumed to be in a JSON format that Apex can understand.
- * Therefore this plugin is a subclass of the built in JSON event protocol plugin.
- * <p>
- * On reception of a JMS {@code javax.jms.TextMessage} message, the JMS Text plugin unmarshals the message the JMS text
- * message and passes it to its JSON superclass unmarshaling for processing.
- * <p>
- * When sending an Apex event, the plugin uses its underlying JSON superclass to marshal the event to a JSON string and
- * passes that string to the JSON carrier plugin for sending.
+ *
+ * <p>Text messages received and sent over JMS in ~Text format are assumed to be in a JSON format that Apex can
+ * understand. Therefore this plugin is a subclass of the built in JSON event protocol plugin.
+ *
+ * <p>On reception of a JMS {@code javax.jms.TextMessage} message, the JMS Text plugin unmarshals the message the JMS
+ * text message and passes it to its JSON superclass unmarshaling for processing.
+ *
+ * <p>When sending an Apex event, the plugin uses its underlying JSON superclass to marshal the event to a JSON string
+ * and passes that string to the JSON carrier plugin for sending.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class JMSTextEventProtocolParameters extends JSONEventProtocolParameters {
+public class JmsTextEventProtocolParameters extends JsonEventProtocolParameters {
/** The label of this event protocol. */
public static final String JMS_TEXT_EVENT_PROTOCOL_LABEL = "JMSTEXT";
@@ -44,13 +44,13 @@ public class JMSTextEventProtocolParameters extends JSONEventProtocolParameters
* Constructor to create a JSON event protocol parameter instance and register the instance with the parameter
* service.
*/
- public JMSTextEventProtocolParameters() {
- super(JMSTextEventProtocolParameters.class.getCanonicalName(), JMS_TEXT_EVENT_PROTOCOL_LABEL);
+ public JmsTextEventProtocolParameters() {
+ super(JmsTextEventProtocolParameters.class.getCanonicalName(), JMS_TEXT_EVENT_PROTOCOL_LABEL);
// Set the event protocol properties for the JMS Text event protocol
this.setLabel(JMS_TEXT_EVENT_PROTOCOL_LABEL);
// Set the event protocol plugin class
- this.setEventProtocolPluginClass(Apex2JMSTextEventConverter.class.getCanonicalName());
+ this.setEventProtocolPluginClass(Apex2JmsTextEventConverter.class.getCanonicalName());
}
}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XMLEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java
index 76bae6833..767c24fdd 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XMLEventConverter.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java
@@ -56,8 +56,8 @@ import org.xml.sax.SAXException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public final class Apex2XMLEventConverter implements ApexEventProtocolConverter {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2XMLEventConverter.class);
+public final class Apex2XmlEventConverter implements ApexEventProtocolConverter {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(Apex2XmlEventConverter.class);
private static final String MODEL_SCHEMA_NAME = "xml/apex-event.xsd";
@@ -71,11 +71,11 @@ public final class Apex2XMLEventConverter implements ApexEventProtocolConverter
*
* @throws ApexEventException the apex event exception
*/
- public Apex2XMLEventConverter() throws ApexEventException {
+ public Apex2XmlEventConverter() throws ApexEventException {
try {
- final URL schemaURL = ResourceUtils.getUrlResource(MODEL_SCHEMA_NAME);
+ final URL schemaUrl = ResourceUtils.getUrlResource(MODEL_SCHEMA_NAME);
final Schema apexEventSchema =
- SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaURL);
+ SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaUrl);
final JAXBContext jaxbContext = JAXBContext.newInstance(XMLApexEvent.class);
@@ -101,7 +101,9 @@ public final class Apex2XMLEventConverter implements ApexEventProtocolConverter
* parameters. eventprotocol.EventProtocolParameters)
*/
@Override
- public void init(final EventProtocolParameters parameters) {}
+ public void init(final EventProtocolParameters parameters) {
+ // No initialization necessary on this class
+ }
/*
* (non-Javadoc)
@@ -149,7 +151,7 @@ public final class Apex2XMLEventConverter implements ApexEventProtocolConverter
}
// Return the event in a single element
- final ArrayList<ApexEvent> eventList = new ArrayList<ApexEvent>();
+ final ArrayList<ApexEvent> eventList = new ArrayList<>();
eventList.add(apexEvent);
return eventList;
}
@@ -170,7 +172,7 @@ public final class Apex2XMLEventConverter implements ApexEventProtocolConverter
}
// Get the Apex event data
- final List<XMLApexEventData> xmlDataList = new ArrayList<XMLApexEventData>();
+ final List<XMLApexEventData> xmlDataList = new ArrayList<>();
try {
for (final Entry<String, Object> apexDataEntry : apexEvent.entrySet()) {
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 0eeb497a1..9f0ee0795 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
@@ -27,7 +27,7 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTo
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class XMLEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters {
+public class XmlEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters {
/** The label of this carrier technology. */
public static final String XML_EVENT_PROTOCOL_LABEL = "XML";
@@ -38,8 +38,8 @@ public class XMLEventProtocolParameters extends EventProtocolTextTokenDelimitedP
* Constructor to create a JSON event protocol parameter instance and register the instance with the parameter
* service.
*/
- public XMLEventProtocolParameters() {
- super(XMLEventProtocolParameters.class.getCanonicalName());
+ public XmlEventProtocolParameters() {
+ super(XmlEventProtocolParameters.class.getCanonicalName());
// Set the event protocol properties for the XML event protocol
this.setLabel(XML_EVENT_PROTOCOL_LABEL);
@@ -48,6 +48,6 @@ public class XMLEventProtocolParameters extends EventProtocolTextTokenDelimitedP
this.setStartDelimiterToken(XML_TEXT_DELIMITER_TOKEN);
// Set the event protocol plugin class
- this.setEventProtocolPluginClass(Apex2XMLEventConverter.class.getCanonicalName());
+ 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/TestXMLEventHandler.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXmlEventHandler.java
index a62cc24cf..1e42bef30 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXMLEventHandler.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/TestXmlEventHandler.java
@@ -38,8 +38,8 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class TestXMLEventHandler {
- private static final XLogger logger = XLoggerFactory.getXLogger(TestXMLEventHandler.class);
+public class TestXmlEventHandler {
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestXmlEventHandler.class);
/**
* Test XML to apex event.
@@ -47,16 +47,16 @@ public class TestXMLEventHandler {
* @throws ApexException on Apex event handling errors
*/
@Test
- public void testXMLtoApexEvent() throws ApexException {
+ public void testXmltoApexEvent() throws ApexException {
try {
- final Apex2XMLEventConverter xmlEventConverter = new Apex2XMLEventConverter();
+ final Apex2XmlEventConverter xmlEventConverter = new Apex2XmlEventConverter();
assertNotNull(xmlEventConverter);
- final String apexEventXMLStringIn = XMLEventGenerator.xmlEvent();
+ final String apexEventXmlStringIn = XmlEventGenerator.xmlEvent();
- logger.debug("input event\n" + apexEventXMLStringIn);
+ logger.debug("input event\n" + apexEventXmlStringIn);
- for (final ApexEvent apexEvent : xmlEventConverter.toApexEvent("XMLEventName", apexEventXMLStringIn)) {
+ for (final ApexEvent apexEvent : xmlEventConverter.toApexEvent("XMLEventName", apexEventXmlStringIn)) {
assertNotNull(apexEvent);
logger.debug(apexEvent.toString());
@@ -83,9 +83,9 @@ public class TestXMLEventHandler {
* @throws ApexException on Apex event handling errors
*/
@Test
- public void testApexEventToXML() throws ApexException {
+ public void testApexEventToXml() throws ApexException {
try {
- final Apex2XMLEventConverter xmlEventConverter = new Apex2XMLEventConverter();
+ final Apex2XmlEventConverter xmlEventConverter = new Apex2XmlEventConverter();
assertNotNull(xmlEventConverter);
final Date event0000StartTime = new Date();
@@ -99,16 +99,16 @@ public class TestXMLEventHandler {
new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.sample.events", "test", "apex");
apexEvent0000.putAll(event0000DataMap);
- final String apexEvent0000XMLString = xmlEventConverter.fromApexEvent(apexEvent0000);
+ final String apexEvent0000XmlString = xmlEventConverter.fromApexEvent(apexEvent0000);
- logger.debug(apexEvent0000XMLString);
+ logger.debug(apexEvent0000XmlString);
- assertTrue(apexEvent0000XMLString.contains("<name>Event0000</name>"));
- assertTrue(apexEvent0000XMLString.contains("<version>0.0.1</version>"));
- assertTrue(apexEvent0000XMLString.contains("<value>This is a test slogan</value>"));
- assertTrue(apexEvent0000XMLString.contains("<value>12345</value>"));
- assertTrue(apexEvent0000XMLString.contains("<value>" + event0000StartTime.getTime() + "</value>"));
- assertTrue(apexEvent0000XMLString.contains("<value>34.5445667</value>"));
+ assertTrue(apexEvent0000XmlString.contains("<name>Event0000</name>"));
+ assertTrue(apexEvent0000XmlString.contains("<version>0.0.1</version>"));
+ assertTrue(apexEvent0000XmlString.contains("<value>This is a test slogan</value>"));
+ assertTrue(apexEvent0000XmlString.contains("<value>12345</value>"));
+ assertTrue(apexEvent0000XmlString.contains("<value>" + event0000StartTime.getTime() + "</value>"));
+ assertTrue(apexEvent0000XmlString.contains("<value>34.5445667</value>"));
final Date event0004StartTime = new Date(1434363272000L);
final Map<String, Object> event0004DataMap = new HashMap<String, Object>();
@@ -129,16 +129,16 @@ public class TestXMLEventHandler {
new ApexEvent("Event0004", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex");
apexEvent0004.putAll(event0004DataMap);
- final String apexEvent0004XMLString = xmlEventConverter.fromApexEvent(apexEvent0004);
+ final String apexEvent0004XmlString = xmlEventConverter.fromApexEvent(apexEvent0004);
- logger.debug(apexEvent0004XMLString);
+ logger.debug(apexEvent0004XmlString);
- assertTrue(apexEvent0004XMLString.contains("<name>Event0004</name>"));
- assertTrue(apexEvent0004XMLString.contains("<version>0.0.1</version>"));
- assertTrue(apexEvent0004XMLString.contains("<value>Test slogan for External Event</value>"));
- assertTrue(apexEvent0004XMLString.contains("<value>1434370506078</value>"));
- assertTrue(apexEvent0004XMLString.contains("<value>" + event0004StartTime.getTime() + "</value>"));
- assertTrue(apexEvent0004XMLString.contains("<value>1064.43</value>"));
+ assertTrue(apexEvent0004XmlString.contains("<name>Event0004</name>"));
+ assertTrue(apexEvent0004XmlString.contains("<version>0.0.1</version>"));
+ assertTrue(apexEvent0004XmlString.contains("<value>Test slogan for External Event</value>"));
+ assertTrue(apexEvent0004XmlString.contains("<value>1434370506078</value>"));
+ assertTrue(apexEvent0004XmlString.contains("<value>" + event0004StartTime.getTime() + "</value>"));
+ assertTrue(apexEvent0004XmlString.contains("<value>1064.43</value>"));
} catch (final Exception e) {
e.printStackTrace();
throw new ApexException("Exception reading Apex event xml file", e);
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 e02c86a45..475373a7c 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
@@ -34,9 +34,15 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlock;
/**
- * @author Liam Fallon (liam.fallon@ericsson.com)
+ * The Class TestXmlTaggedEventConsumer.
*/
-public class TestXMLTaggedEventConsumer {
+public class TestXmlTaggedEventConsumer {
+
+ /**
+ * Test garbage text line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testGarbageTextLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream("hello there".getBytes());
@@ -49,10 +55,15 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test partial event line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testPartialEventLine() throws IOException {
- final InputStream xmlInputStream =
- new ByteArrayInputStream("1469781869268</TestTimestamp></MainTag>".getBytes());
+ final InputStream xmlInputStream = new ByteArrayInputStream(
+ "1469781869268</TestTimestamp></MainTag>".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -62,23 +73,33 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes());
+ "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(), "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>");
+ assertEquals("<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>", textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event garbage before line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventGarbageBeforeLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes());
+ "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -87,10 +108,16 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event garbage before after line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventGarbageBeforeAfterLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes());
+ "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish"
+ .getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -99,20 +126,30 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event garbage after line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventGarbageAfterLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes());
+ "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish");
+ assertEquals("<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test garbage text multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testGarbageTextMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream("hello\nthere".getBytes());
@@ -124,10 +161,15 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test partial event multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testPartialEventMultiLine() throws IOException {
- final InputStream xmlInputStream =
- new ByteArrayInputStream("1469781869268\n</TestTimestamp>\n</MainTag>".getBytes());
+ final InputStream xmlInputStream = new ByteArrayInputStream(
+ "1469781869268\n</TestTimestamp>\n</MainTag>".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -136,68 +178,95 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes());
+ "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event garbage before multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventGarbageBeforeMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n".getBytes());
+ "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n"
+ .getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event garbage before after multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventGarbageBeforeAfterMultiLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish\n\n"
- .getBytes());
+ String garbageString = "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>"
+ + "\n</MainTag>\nRubbish\n\n";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full event garbage after multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventGarbageAfterMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish".getBytes());
+ "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish"
+ .getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test partial events line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testPartialEventsLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "1469781869268</TestTimestamp></MainTag><?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp>"
- .getBytes());
+ String garbageString = "1469781869268</TestTimestamp></MainTag><?xml><MainTag>"
+ + "<TestTimestamp>1469781869268</TestTimestamp>";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -206,11 +275,16 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events garbage before line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsGarbageBeforeLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag><?xml><MainTag><TestTimestamp>"
- .getBytes());
+ String garbageString = "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>"
+ + "<?xml><MainTag><TestTimestamp>";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -219,11 +293,16 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events garbage before after line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsGarbageBeforeAfterLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>\nRefuse"
- .getBytes());
+ String garbageString = "Garbage<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp>"
+ + "</MainTag>Rubbish<?xml><MainTag><TestTimestamp>\nRefuse";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
@@ -232,105 +311,136 @@ public class TestXMLTaggedEventConsumer {
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events garbage after line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsGarbageAfterLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>Refuse"
- .getBytes());
+ String garbageString = "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp>"
+ + "</MainTag>Rubbish<?xml><MainTag><TestTimestamp>Refuse";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml><MainTag><TestTimestamp>1469781869268</TestTimestamp></MainTag>Rubbish<?xml><MainTag><TestTimestamp>Refuse");
+ assertEquals(textBlock.getText(), garbageString);
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test partial events multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testPartialEventsMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "1469781869268\n</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>".getBytes());
+ "1469781869268\n</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>".getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(), "<?xml>\n<MainTag>\n<TestTimestamp>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>", textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsMultiLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n"
- .getBytes());
+ String garbageString = "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n"
+ + "</MainTag>\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>",
+ textBlock.getText());
assertFalse(textBlock.isEndOfText());
textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events garbage before multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsGarbageBeforeMultiLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n"
- .getBytes());
+ String garbageString = "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n"
+ + "</MainTag>\n\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\n";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>",
+ textBlock.getText());
assertFalse(textBlock.isEndOfText());
textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events garbage before after multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsGarbageBeforeAfterMultiLine() throws IOException {
- final InputStream xmlInputStream = new ByteArrayInputStream(
- "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());
+ String garbageString = "Garbage\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n"
+ + "</MainTag>\nRubbish\n<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n"
+ + "</MainTag>\nRefuse\n";
+ final InputStream xmlInputStream = new ByteArrayInputStream(garbageString.getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish",
+ textBlock.getText());
assertFalse(textBlock.isEndOfText());
textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRefuse");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRefuse",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
+ /**
+ * Test full events garbage after multi line.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testFullEventsGarbageAfterMultiLine() throws IOException {
final InputStream xmlInputStream = new ByteArrayInputStream(
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish".getBytes());
+ "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish"
+ .getBytes());
final HeaderDelimitedTextBlockReader xmlTaggedReader = new HeaderDelimitedTextBlockReader("<?xml", null, true);
xmlTaggedReader.init(xmlInputStream);
final TextBlock textBlock = xmlTaggedReader.readTextBlock();
- assertEquals(textBlock.getText(),
- "<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish");
+ assertEquals("<?xml>\n<MainTag>\n<TestTimestamp>1469781869268</TestTimestamp>\n</MainTag>\nRubbish",
+ textBlock.getText());
assertTrue(textBlock.isEndOfText());
}
}
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventGenerator.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java
index 765f098de..f85d9119e 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XMLEventGenerator.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java
@@ -23,11 +23,17 @@ package org.onap.policy.apex.plugins.event.protocol.xml;
import java.util.Random;
/**
- * @author Liam Fallon (liam.fallon@ericsson.com)
+ * The Class XmlEventGenerator.
*/
-public class XMLEventGenerator {
+public class XmlEventGenerator {
private static int nextEventNo = 0;
+ /**
+ * Xml events.
+ *
+ * @param eventCount the event count
+ * @return the string
+ */
public static String xmlEvents(final int eventCount) {
final StringBuilder builder = new StringBuilder();
@@ -41,6 +47,11 @@ public class XMLEventGenerator {
return builder.toString();
}
+ /**
+ * Xml event.
+ *
+ * @return the string
+ */
public static String xmlEvent() {
final Random rand = new Random();
@@ -65,7 +76,7 @@ public class XMLEventGenerator {
builder.append(" </data>\n");
builder.append(" <data>\n");
builder.append(" <key>TestMatchCase</key>\n");
- builder.append(" <value>" + nextMatchCase + "</value>\n");
+ builder.append(" <value>" + nextMatchCase + "</value>\n");
builder.append(" </data>\n");
builder.append(" <data>\n");
builder.append(" <key>TestTimestamp</key>\n");
@@ -80,6 +91,11 @@ public class XMLEventGenerator {
return builder.toString();
}
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ */
public static void main(final String[] args) {
if (args.length != 1) {
System.err.println("usage EventGenerator #events");
@@ -98,6 +114,11 @@ public class XMLEventGenerator {
System.out.println(xmlEvents(eventCount));
}
+ /**
+ * Gets the next event no.
+ *
+ * @return the next event no
+ */
public static int getNextEventNo() {
return nextEventNo;
}
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
index f81c3a914..4bf10e4ae 100644
--- 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
@@ -38,9 +38,8 @@ 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;
+import org.yaml.snakeyaml.Yaml;
/**
* The Class Apex2YamlEventConverter converts {@link ApexEvent} instances to and from YAML string representations of
@@ -104,11 +103,10 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
// 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) {
+ if (yamlObject instanceof Map) {
// We already have a map so just cast the object
yamlMap = (Map<?, ?>) yamlObject;
- }
- else {
+ } else {
// Create a single entry map, new map creation and assignment is to avoid a
// type checking warning
LinkedHashMap<String, Object> newYamlMap = new LinkedHashMap<>();
@@ -173,7 +171,7 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
continue;
}
- yamlMap.put(fieldName, apexEvent.get(fieldName));
+ yamlMap.put(fieldName, apexEvent.get(fieldName));
}
// Use Snake YAML to convert the APEX event to YAML
@@ -187,11 +185,9 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
* @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
+ * @throws ApexEventException thrown on unmarshaling exceptions
*/
- private ApexEvent yamlMap2ApexEvent(final String eventName, final Map<?, ?> yamlMap)
- throws ApexEventException {
+ private ApexEvent yamlMap2ApexEvent(final String eventName, final Map<?, ?> yamlMap) throws ApexEventException {
// Process the mandatory Apex header
final ApexEvent apexEvent = processApexEventHeader(eventName, yamlMap);
@@ -236,16 +232,10 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
* @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)
+ 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
+ String name = getYamlStringField(yamlMap, ApexEvent.NAME_HEADER_FIELD, yamlPars.getNameAlias(),
+ ApexEvent.NAME_REGEXP, false);
// Check that an event name has been specified
if (name == null && eventName == null) {
@@ -256,14 +246,16 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
// 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);
+ 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
+ String version = getYamlStringField(yamlMap, ApexEvent.VERSION_HEADER_FIELD, yamlPars.getVersionAlias(),
+ ApexEvent.VERSION_REGEXP, false);
final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(name, version);
if (eventDefinition == null) {
throw new ApexEventRuntimeException("an event definition for an event named \"" + name
@@ -276,6 +268,8 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
}
// Check the name space is OK if it is defined, if not, use the name space from the model
+ String namespace = getYamlStringField(yamlMap, ApexEvent.NAMESPACE_HEADER_FIELD, yamlPars.getNameSpaceAlias(),
+ ApexEvent.NAMESPACE_REGEXP, false);
if (namespace != null) {
if (!namespace.equals(eventDefinition.getNameSpace())) {
throw new ApexEventRuntimeException("namespace \"" + namespace + "\" on event \"" + name
@@ -287,11 +281,15 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
}
// For source, use the defined source only if the source is not found on the incoming event
+ String source = getYamlStringField(yamlMap, ApexEvent.SOURCE_HEADER_FIELD, yamlPars.getSourceAlias(),
+ ApexEvent.SOURCE_REGEXP, false);
if (source == null) {
source = eventDefinition.getSource();
}
// For target, use the defined source only if the source is not found on the incoming event
+ String target = getYamlStringField(yamlMap, ApexEvent.TARGET_HEADER_FIELD, yamlPars.getTargetAlias(),
+ ApexEvent.TARGET_REGEXP, false);
if (target == null) {
target = eventDefinition.getTarget();
}
@@ -302,22 +300,16 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
/**
* 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
+ * @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 fieldRegexp 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 getYamlStringField(final Map<?, ?> yamlMap, final String fieldName, final String fieldAlias,
- final String fieldRE, final boolean mandatory) {
+ final String fieldRegexp, final boolean mandatory) {
// Get the YAML field for the string field
final Object yamlField = getYamlField(yamlMap, fieldName, fieldAlias, mandatory);
@@ -335,12 +327,12 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
final String fieldValueString = (String) yamlField;
// Is regular expression checking required
- if (fieldRE == null) {
+ if (fieldRegexp == null) {
return fieldValueString;
}
// Check the event field against its regular expression
- if (!fieldValueString.matches(fieldRE)) {
+ if (!fieldValueString.matches(fieldRegexp)) {
throw new ApexEventRuntimeException(
"field \"" + fieldName + "\" with value \"" + fieldValueString + "\" is invalid");
}
@@ -351,17 +343,12 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
/**
* 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
+ * @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
+ * @throws ApexEventRuntimeException the apex event runtime exception
*/
private Object getYamlField(final Map<?, ?> yamlMap, final String fieldName, final String fieldAlias,
final boolean mandatory) {
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
index 861e9cd8f..09a7f54aa 100644
--- 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
@@ -25,7 +25,7 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTo
/**
* Event protocol parameters for YAML as an event protocol.
*
- * The parameters for this plugin are:
+ * <p>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.
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
index c5f6cb781..1d2a1d9f7 100644
--- 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
@@ -49,7 +49,16 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlock;
import org.onap.policy.common.parameters.ParameterService;
+/**
+ * The Class TestYamlEventProtocol.
+ */
public class TestYamlEventProtocol {
+
+ /**
+ * Register test events and schemas.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@BeforeClass
public static void registerTestEventsAndSchemas() throws IOException {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -62,20 +71,20 @@ public class TestYamlEventProtocol {
"java.lang.Integer");
schemas.getSchemasMap().put(simpleIntSchema.getKey(), simpleIntSchema);
- AxContextSchema simpleDoubleSchema = new AxContextSchema(new AxArtifactKey("SimpleDoubleSchema", "0.0.1"), "JAVA",
- "java.lang.Double");
+ 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");
+ 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");
+ 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);
@@ -105,11 +114,9 @@ public class TestYamlEventProtocol {
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());
+ 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());
+ AxField te3Field1 = new AxField(new AxReferenceKey(testEvent3.getKey(), "national"), arrayListSchema.getKey());
testEvent3.getParameterMap().put("national", te3Field1);
events.getEventMap().put(testEvent3.getKey(), testEvent3);
@@ -139,24 +146,19 @@ public class TestYamlEventProtocol {
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());
+ 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());
+ 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());
+ 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());
+ 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());
+ AxField te8Field1 = new AxField(new AxReferenceKey(testEvent8.getKey(), "rbi"), arrayListSchema.getKey());
testEvent8.getParameterMap().put("rbi", te8Field1);
events.getEventMap().put(testEvent8.getKey(), testEvent8);
@@ -196,12 +198,21 @@ public class TestYamlEventProtocol {
ModelService.registerModel(AxEvents.class, events);
}
+ /**
+ * Unregister test events and schemas.
+ */
@AfterClass
public static void unregisterTestEventsAndSchemas() {
ModelService.clear();
ParameterService.clear();
}
+ /**
+ * Test yaml processing.
+ *
+ * @throws ApexEventException the apex event exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@Test
public void testYamlProcessing() throws ApexEventException, IOException {
try {
@@ -227,8 +238,18 @@ public class TestYamlEventProtocol {
testYamlDecodeEncode("TestEvent11", 1, 4, "TOSCA0");
}
- private void testYamlDecodeEncode(final String eventName, final int eventCount, final int parCount, final String fileName)
- throws ApexEventException, IOException {
+ /**
+ * Test yaml decode encode.
+ *
+ * @param eventName the event name
+ * @param eventCount the event count
+ * @param parCount the par count
+ * @param fileName the file name
+ * @throws ApexEventException the apex event exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ 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);
@@ -239,16 +260,17 @@ public class TestYamlEventProtocol {
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());
-
+ textBlock = reader.readTextBlock();
+
+ eventList.addAll(converter.toApexEvent(eventName, textBlock.getText()));
+ }
+ while (!textBlock.isEndOfText());
+
fileInputStream.close();
assertEquals(eventCount, eventList.size());
@@ -257,7 +279,8 @@ public class TestYamlEventProtocol {
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");
+ 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
index 57b4b72d6..d033de56d 100644
--- 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
@@ -17,6 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.apex.plugins.event.protocol.yaml;
import static org.junit.Assert.assertEquals;
@@ -44,9 +45,17 @@ import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.common.parameters.ParameterService;
+/**
+ * The Class TestYamlPluginStability.
+ */
public class TestYamlPluginStability {
static AxEvent testEvent;
+ /**
+ * Register test events and schemas.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
@BeforeClass
public static void registerTestEventsAndSchemas() throws IOException {
SchemaParameters schemaParameters = new SchemaParameters();
@@ -69,8 +78,6 @@ public class TestYamlPluginStability {
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());
@@ -81,17 +88,27 @@ public class TestYamlPluginStability {
AxField teField2 = new AxField(new AxReferenceKey(testEvent.getKey(), "stringValue"),
simpleStringSchema.getKey(), true);
testEvent.getParameterMap().put("stringValue", teField2);
+
+ AxEvents events = new AxEvents();
events.getEventMap().put(testEvent.getKey(), testEvent);
ModelService.registerModel(AxEvents.class, events);
}
+ /**
+ * Unregister test events and schemas.
+ */
@AfterClass
public static void unregisterTestEventsAndSchemas() {
ModelService.clear();
ParameterService.clear();
}
+ /**
+ * Test stability.
+ *
+ * @throws ApexEventException the apex event exception
+ */
@Test
public void testStability() throws ApexEventException {
Apex2YamlEventConverter converter = new Apex2YamlEventConverter();
@@ -220,7 +237,8 @@ public class TestYamlPluginStability {
e.getMessage().substring(0, 77));
}
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.onap.policy.apex.plugins.event.protocol.yaml";
+ 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());
@@ -249,7 +267,7 @@ public class TestYamlPluginStability {
}
pars.setTargetAlias(null);
- yamlInputString = "doubleValue: 123.45\n" + "intValue: ~\n"+ "stringValue: MyString";
+ yamlInputString = "doubleValue: 123.45\n" + "intValue: ~\n" + "stringValue: MyString";
try {
converter.toApexEvent("TestEvent", yamlInputString);
fail("this test should throw an exception");