[jboss-svn-commits] JBL Code SVN: r6506 - labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Sep 30 19:15:48 EDT 2006
Author: mark.little at jboss.com
Date: 2006-09-30 19:15:44 -0400 (Sat, 30 Sep 2006)
New Revision: 6506
Added:
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
Log:
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,207 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringWriter;
+import java.lang.IllegalArgumentException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.w3c.dom.Document;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class AttachmentUnitTest extends TestCase
+{
+
+ public void testSerializeAttachment()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ Attachment at = msg.getAttachment();
+
+ assertEquals((msg != null), true);
+
+ at.addItem(new ExampleObject(0)); // un-named
+ at.addItemAt(0, new ExampleObject(0)); // un-named;
+
+ try
+ {
+ at.addItem(new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(at.getUnnamedCount(), 2);
+
+ assertEquals(at.get("foo"), null);
+
+ at.put("foobar", new ExampleObject(1));
+
+ assertEquals(at.getNamedCount(), 1);
+
+ at.addItem(new ExampleObject(1));
+ at.addItem(new ExampleObject(2));
+
+ assertEquals((at.getNames() != null), true);
+
+ assertEquals((at.removeItemAt(0) != null), true);
+
+ at.replaceItemAt(0, new ExampleObject(2));
+
+ int count = at.getUnnamedCount();
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ assertEquals(nImpl.getAttachment().getUnnamedCount(), count);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testXMLAttachment()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ Attachment at = msg.getAttachment();
+
+ assertEquals((msg != null), true);
+
+ at.addItem(new ExampleObject(0)); // un-named
+ at.addItemAt(0, new ExampleObject(0)); // un-named;
+
+ try
+ {
+ at.addItem(new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(at.getUnnamedCount(), 2);
+
+ assertEquals(at.get("foo"), null);
+
+ at.put("foobar", new ExampleObject(1));
+
+ assertEquals(at.getNamedCount(), 1);
+
+ at.addItem(new ExampleObject(1));
+ at.addItem(new ExampleObject(2));
+
+ assertEquals((at.getNames() != null), true);
+
+ assertEquals((at.removeItemAt(0) != null), true);
+
+ at.replaceItemAt(0, new ExampleObject(2));
+
+ int count = at.getUnnamedCount();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl theImpl = (org.jboss.internal.soa.esb.message.format.xml.MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ System.err.println("Message looks like: " + documentAsString);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl nImpl = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+
+ nImpl.fromXML(doc);
+
+ assertEquals(nImpl.getAttachment().getUnnamedCount(), count);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.Serializable;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class ExampleObject implements Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public ExampleObject (long val)
+ {
+ value = val;
+ }
+
+ public long getValue ()
+ {
+ return value;
+ }
+
+ private long value;
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringWriter;
+import java.lang.IllegalArgumentException;
+import java.net.URI;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.w3c.dom.Document;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class FaultUnitTest extends TestCase
+{
+
+ public void testSerializeFault ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ URI code = new URI("urn:code");
+
+ msg.getFault().setCode(code);
+ msg.getFault().setReason("because");
+
+ assertEquals(msg.getFault().getCode(), code);
+ assertEquals(msg.getFault().getReason(), "because");
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ assertEquals(nImpl.getFault().getReason(), "because");
+
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testXMLFault ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ URI code = new URI("urn:code");
+
+ msg.getFault().setCode(code);
+ msg.getFault().setReason("because");
+
+ assertEquals(msg.getFault().getCode(), code);
+ assertEquals(msg.getFault().getReason(), "because");
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl theImpl = (org.jboss.internal.soa.esb.message.format.xml.MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ System.err.println("Message looks like: " + documentAsString);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl nImpl = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+
+ nImpl.fromXML(doc);
+
+ assertEquals(nImpl.getFault().getReason(), "because");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class MessageUnitTest extends TestCase
+{
+
+ public void testDefaultMessageFields ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+
+ assertEquals((msg.getBody() != null), true);
+ assertEquals((msg.getHeader() != null), true);
+ assertEquals((msg.getContext() != null), true);
+ assertEquals((msg.getAttachment() != null), true);
+ assertEquals((msg.getFault() != null), true);
+ assertEquals((msg.getProperties() != null), true);
+ }
+
+ public void testXMLMessageFields ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ assertEquals((msg.getBody() != null), true);
+ assertEquals((msg.getHeader() != null), true);
+ assertEquals((msg.getContext() != null), true);
+ assertEquals((msg.getAttachment() != null), true);
+ assertEquals((msg.getFault() != null), true);
+ assertEquals((msg.getProperties() != null), true);
+ }
+
+ public void testSerializedMessageFields ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg.getBody() != null), true);
+ assertEquals((msg.getHeader() != null), true);
+ assertEquals((msg.getContext() != null), true);
+ assertEquals((msg.getAttachment() != null), true);
+ assertEquals((msg.getFault() != null), true);
+ assertEquals((msg.getProperties() != null), true);
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.IllegalArgumentException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.w3c.dom.Document;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class PropertiesUnitTest extends TestCase
+{
+
+ public void testSerializeProperties()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ msg.getProperties().setProperty("foo", "bar");
+
+ assertEquals(msg.getProperties().getProperty("foo"), "bar");
+ assertEquals((msg.getProperties().getProperty("foobar") == null), true);
+
+ assertEquals(msg.getProperties().getProperty("foobar", "barfoo"),
+ "barfoo");
+
+ try
+ {
+ msg.getProperties().setProperty("1234", new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ msg.getProperties().getNames();
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ assertEquals(nImpl.getProperties().getProperty("foo"), "bar");
+
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(msg.getProperties().remove("foo"), "bar");
+ }
+
+ public void testXMLProperties()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ msg.getProperties().setProperty("foo", "bar");
+
+ assertEquals(msg.getProperties().getProperty("foo"), "bar");
+ assertEquals((msg.getProperties().getProperty("foobar") == null), true);
+
+ assertEquals(msg.getProperties().getProperty("foobar", "barfoo"),
+ "barfoo");
+
+ try
+ {
+ msg.getProperties().setProperty("1234", new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ msg.getProperties().getNames();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl theImpl = (org.jboss.internal.soa.esb.message.format.xml.MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl nImpl = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+
+ nImpl.fromXML(doc);
+
+ assertEquals(nImpl.getProperties().getProperty("foo"), "bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(msg.getProperties().remove("foo"), "bar");
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,337 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.IllegalArgumentException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class SerializedMessageUnitTest extends TestCase
+{
+
+ public void testSerialize()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ }
+
+ public void testDeserialize()
+ {
+ // get XML message
+
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testHeader ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ Call call = new Call();
+
+ msg.getHeader().setCall(call);
+
+ call = msg.getHeader().getCall();
+
+ assertEquals((call != null), true);
+
+ try
+ {
+ msg.getHeader().setCall(null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testInvalidAdd ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ msg.getBody().add(null, null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testAddBytes ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ String testString = "test";
+
+ msg.getBody().setContents(testString.getBytes());
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ String val = new String(nImpl.getBody().getContents());
+
+ assertEquals(val, testString);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testReplace ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().replace(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar.equals("bar"), true);
+ }
+
+ public void testMerge ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().merge(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar, "foobar");
+ }
+
+ public void testAddObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("foo", value);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("foo");
+
+ assertEquals((foo.getValue() == value.getValue()), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testAddInvalidObject ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ msg.getBody().add("foo", new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testRemoveObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("bar", value);
+
+ msg.getBody().remove("bar");
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("bar");
+
+ assertEquals((foo == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2006-09-30 23:15:22 UTC (rev 6505)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
@@ -0,0 +1,371 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.StringWriter;
+import java.lang.IllegalArgumentException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+import org.jboss.internal.soa.esb.message.format.xml.MessageImpl;
+
+import org.w3c.dom.Document;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class XMLMessageUnitTest extends TestCase
+{
+
+ public void testToXML()
+ {
+ // get XML message
+
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ System.err.println("Message looks like: " + documentAsString);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testFromXML()
+ {
+ // get XML message
+
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ MessageImpl nImpl = new MessageImpl();
+
+ nImpl.fromXML(doc);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testHeader ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ Call call = new Call();
+
+ msg.getHeader().setCall(call);
+
+ call = msg.getHeader().getCall();
+
+ assertEquals((call != null), true);
+
+ try
+ {
+ msg.getHeader().setCall(null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testInvalidAdd ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ msg.getBody().add(null, null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testAddBytes ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ String testString = "test";
+
+ msg.getBody().setContents(testString.getBytes());
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ MessageImpl nImpl = new MessageImpl();
+
+ System.err.println("Document is "+documentAsString);
+
+ nImpl.fromXML(doc);
+
+ String val = new String(nImpl.getBody().getContents());
+
+ assertEquals(val, testString);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testReplace ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().replace(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar.equals("bar"), true);
+ }
+
+ public void testMerge ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().merge(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar, "foobar");
+ }
+
+ public void testAddObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("foo", value);
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ MessageImpl nImpl = new MessageImpl();
+
+ System.err.println("Document is "+documentAsString);
+
+ nImpl.fromXML(doc);
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("foo");
+
+ assertEquals((foo.getValue() == value.getValue()), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testRemoveObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("bar", value);
+
+ msg.getBody().remove("bar");
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ MessageImpl nImpl = new MessageImpl();
+
+ System.err.println("Document is "+documentAsString);
+
+ nImpl.fromXML(doc);
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("bar");
+
+ assertEquals((foo == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
More information about the jboss-svn-commits
mailing list