[jboss-svn-commits] JBL Code SVN: r6351 - in labs/jbossesb/workspace/rearchitecture/product/core/rosetta: 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
Fri Sep 22 06:43:34 EDT 2006


Author: mark.little at jboss.com
Date: 2006-09-22 06:43:28 -0400 (Fri, 22 Sep 2006)
New Revision: 6351

Added:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java
Modified:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java
Log:


Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java	2006-09-22 10:00:32 UTC (rev 6350)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java	2006-09-22 10:43:28 UTC (rev 6351)
@@ -2,11 +2,8 @@
 
 import java.net.URI;
 
-import org.jboss.internal.soa.esb.thirdparty.Base64;
 import org.jboss.soa.esb.message.Fault;
 
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;

Added: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java	2006-09-22 10:00:32 UTC (rev 6350)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java	2006-09-22 10:43:28 UTC (rev 6351)
@@ -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());
+		}
+	}
+
+}




More information about the jboss-svn-commits mailing list