[jboss-svn-commits] JBL Code SVN: r6359 - labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Sep 22 10:47:50 EDT 2006
Author: estebanschifman
Date: 2006-09-22 10:47:48 -0400 (Fri, 22 Sep 2006)
New Revision: 6359
Added:
labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/MessagePropertiesSerializeTest.java
labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/Util.java
Log:
Testcase for message Properties class
Added: labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/MessagePropertiesSerializeTest.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/MessagePropertiesSerializeTest.java 2006-09-22 14:47:44 UTC (rev 6358)
+++ labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/MessagePropertiesSerializeTest.java 2006-09-22 14:47:48 UTC (rev 6359)
@@ -0,0 +1,110 @@
+/*
+ * 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.qa;
+
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+
+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("serialize.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/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/Util.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/Util.java 2006-09-22 14:47:44 UTC (rev 6358)
+++ labs/jbossesb/workspace/rearchitecture/qa/junit/src/org/jboss/soa/esb/rosetta/qa/Util.java 2006-09-22 14:47:48 UTC (rev 6359)
@@ -0,0 +1,28 @@
+package org.jboss.soa.esb.rosetta.qa;
+
+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