[jboss-svn-commits] JBL Code SVN: r6316 - in labs/jbossesb/workspace/rearchitecture/product/core/rosetta: src/org/jboss/internal/soa/esb/addressing src/org/jboss/internal/soa/esb/message/format/serialized src/org/jboss/internal/soa/esb/message/format/xml tests/src/org/jboss/soa/esb/message/tests
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 20 10:12:36 EDT 2006
Author: mark.little at jboss.com
Date: 2006-09-20 10:12:31 -0400 (Wed, 20 Sep 2006)
New Revision: 6316
Added:
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
Modified:
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
Log:
yet more unit tests.
Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -79,6 +79,8 @@
}
catch (Exception ex)
{
+ // TODO improve error handling.
+
ex.printStackTrace();
return null;
Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -22,6 +22,7 @@
*/
import java.io.Serializable;
+import java.security.InvalidParameterException;
import org.jboss.soa.esb.message.Header;
import org.jboss.soa.esb.addressing.Call;
@@ -48,6 +49,9 @@
public void setCall (Call call)
{
+ if (call == null)
+ throw new InvalidParameterException();
+
_call = call;
}
Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -111,6 +111,8 @@
// we already checked values are Serializable when they were added.
objElement.appendChild(doc.createCDATASection(Base64.encodeObject((Serializable) value)));
+
+ bodyElement.appendChild(objElement);
}
@@ -132,7 +134,7 @@
Element child = (Element) children.item(j);
// treat bytes specially.
- CDATASection cdata = (CDATASection) child.getChildNodes().item(0).getFirstChild();
+ CDATASection cdata = (CDATASection) child.getFirstChild();
if (child.getNodeName().equals("bytes"))
{
Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -21,6 +21,8 @@
* @author mark.little at jboss.com
*/
+import java.security.InvalidParameterException;
+
import org.jboss.internal.soa.esb.addressing.CallHelper;
import org.jboss.soa.esb.message.Header;
import org.jboss.soa.esb.addressing.Call;
@@ -50,6 +52,9 @@
public void setCall (Call call)
{
+ if (call == null)
+ throw new InvalidParameterException();
+
_call = call;
}
Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -173,6 +173,8 @@
}
}
+ // TODO add equality operator(s)
+
private HeaderImpl _theHeader = new HeaderImpl();
private ContextImpl _theContext = new ContextImpl();
private BodyImpl _theBody = new BodyImpl();
Added: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -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/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2006-09-20 12:13:19 UTC (rev 6315)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2006-09-20 14:12:31 UTC (rev 6316)
@@ -0,0 +1,297 @@
+/*
+ * 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.security.InvalidParameterException;
+
+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 (InvalidParameterException 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 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