summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml')
-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
5 files changed, 240 insertions, 107 deletions
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;
}