[jboss-svn-commits] JBL Code SVN: r6508 - in labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb: . rosetta

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Sep 30 19:22:37 EDT 2006


Author: mark.little at jboss.com
Date: 2006-09-30 19:22:35 -0400 (Sat, 30 Sep 2006)
New Revision: 6508

Added:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessageAttachmentSerializeTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessagePropertiesSerializeTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/Util.java
Log:


Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessageAttachmentSerializeTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessageAttachmentSerializeTest.java	2006-09-30 23:16:02 UTC (rev 6507)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessageAttachmentSerializeTest.java	2006-09-30 23:22:35 UTC (rev 6508)
@@ -0,0 +1,112 @@
+/*
+ * 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.rosetta;
+
+import junit.framework.TestCase;
+
+import java.io.*;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.soa.esb.message.Attachment;
+import org.w3c.dom.*;
+
+/**
+ * QA tests for the Message interface and implementations.
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ */
+public class MessageAttachmentSerializeTest extends TestCase 
+{
+
+	protected void setUp() throws Exception 
+	{
+	}
+
+	public void runTest() throws Exception 
+	{
+		testJavaSerializable();
+		testXml();
+	}
+
+	private static final File TESTFILE = new File("msgAttachment.test");
+	protected void tearDown() throws Exception 
+	{
+		TESTFILE.delete();
+	}
+	
+	private void testJavaSerializable() throws Exception
+	{
+		org.jboss.internal.soa.esb.message.format.serialized.AttachmentImpl
+		old = new  org.jboss.internal.soa.esb.message.format.serialized.AttachmentImpl();
+		populateAttachment(old);
+		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(TESTFILE));
+		out.writeObject(old);
+		out.close();
+
+		ObjectInputStream inp = new ObjectInputStream(new FileInputStream(TESTFILE));
+		org.jboss.internal.soa.esb.message.format.serialized.AttachmentImpl
+		oNew = (org.jboss.internal.soa.esb.message.format.serialized.AttachmentImpl)
+			inp.readObject();
+		inp.close();
+
+		assertEquals(old,oNew);
+	}
+
+	private void testXml() throws Exception
+	{
+		DocumentBuilder oDB = DocumentBuilderFactory.newInstance().newDocumentBuilder();	
+		Document oDoc = oDB.newDocument();
+		Element  oRoot = oDoc.createElement("root");
+		oDoc.appendChild(oRoot);
+		
+		org.jboss.internal.soa.esb.message.format.xml.AttachmentImpl
+		old = new  org.jboss.internal.soa.esb.message.format.xml.AttachmentImpl();
+		populateAttachment(old);
+		old.toXML(oRoot);
+		
+		org.jboss.internal.soa.esb.message.format.xml.AttachmentImpl
+		oNew = new org.jboss.internal.soa.esb.message.format.xml.AttachmentImpl();		
+		oNew.fromXML(oRoot);
+
+		assertEquals(old,oNew);
+		
+		Document oD2 = oDB.newDocument();
+		Element  oR2 = oD2.createElement("root");
+		oD2.appendChild(oR2);
+		oNew.toXML(oR2);
+
+		String s1 = Util.toString(oRoot);
+		String s2 = Util.toString(oR2);
+		assertEquals(s1,s2);
+
+	}
+	
+	private void populateAttachment(Attachment att)
+	{
+		att.addItem("unnamed att 1");
+		att.put("name 2","N2N2N2N2N2N2N2N2");
+		att.addItem("unn 2");
+		att.put("name 1","named att 111111111111111");
+	}
+}

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessagePropertiesSerializeTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessagePropertiesSerializeTest.java	2006-09-30 23:16:02 UTC (rev 6507)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/MessagePropertiesSerializeTest.java	2006-09-30 23:22:35 UTC (rev 6508)
@@ -0,0 +1,109 @@
+/*
+ * 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.rosetta;
+
+import junit.framework.TestCase;
+
+import java.io.*;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.*;
+
+/**
+ * QA tests for the Message interface and implementations.
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ */
+public class MessagePropertiesSerializeTest extends TestCase 
+{
+
+	protected void setUp() throws Exception 
+	{
+	}
+
+	public void runTest() throws Exception 
+	{
+		testJavaSerializable();
+		testXml();
+	}
+
+	private static final File TESTFILE = new File("msgProperties.test");
+	protected void tearDown() throws Exception 
+	{
+		TESTFILE.delete();
+	}
+	
+	private void testJavaSerializable() throws Exception
+	{
+		org.jboss.internal.soa.esb.message.format.serialized.PropertiesImpl
+		old = new  org.jboss.internal.soa.esb.message.format.serialized.PropertiesImpl();
+		populateProperties(old);
+		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(TESTFILE));
+		out.writeObject(old);
+		out.close();
+
+		ObjectInputStream inp = new ObjectInputStream(new FileInputStream(TESTFILE));
+		org.jboss.internal.soa.esb.message.format.serialized.PropertiesImpl
+		oNew = (org.jboss.internal.soa.esb.message.format.serialized.PropertiesImpl)
+			inp.readObject();
+		inp.close();
+
+		assertEquals(old,oNew);
+	}
+
+	private void testXml() throws Exception
+	{
+		DocumentBuilder oDB = DocumentBuilderFactory.newInstance().newDocumentBuilder();	
+		Document oDoc = oDB.newDocument();
+		Element  oRoot = oDoc.createElement("root");
+		oDoc.appendChild(oRoot);
+		
+		org.jboss.internal.soa.esb.message.format.xml.PropertiesImpl
+		old = new  org.jboss.internal.soa.esb.message.format.xml.PropertiesImpl();
+		populateProperties(old);
+		old.toXML(oRoot);
+		
+		org.jboss.internal.soa.esb.message.format.xml.PropertiesImpl
+		oNew = new org.jboss.internal.soa.esb.message.format.xml.PropertiesImpl();		
+		oNew.fromXML(oRoot);
+
+		assertEquals(old,oNew);
+		
+		Document oD2 = oDB.newDocument();
+		Element  oR2 = oD2.createElement("root");
+		oD2.appendChild(oR2);
+		oNew.toXML(oR2);
+
+		String s1 = Util.toString(oRoot);
+		String s2 = Util.toString(oR2);
+		assertEquals(s1,s2);
+
+	}
+	
+	private void populateProperties(org.jboss.soa.esb.message.Properties props)
+	{
+		props.setProperty("p1","VALUE OF PROP 1");
+		props.setProperty("p2","VALUE 222");
+	}
+}

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/Util.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/Util.java	2006-09-30 23:16:02 UTC (rev 6507)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/rosetta/Util.java	2006-09-30 23:22:35 UTC (rev 6508)
@@ -0,0 +1,28 @@
+package org.jboss.soa.esb.rosetta;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Element;
+
+public class Util 
+{
+	public static String toString(Element elem) throws Exception
+	{
+		DOMSource src = new DOMSource(elem.getOwnerDocument());
+
+		ByteArrayOutputStream oStrm = new ByteArrayOutputStream(5000);
+		StreamResult res = new StreamResult(oStrm);
+
+		Transformer TT = TransformerFactory.newInstance().newTransformer();
+		TT.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+		TT.setOutputProperty(OutputKeys.INDENT, "no");
+		TT.transform(src, res);
+		return (oStrm.toString());
+	} // __________________________________
+}




More information about the jboss-svn-commits mailing list