[jboss-svn-commits] JBL Code SVN: r6325 - in labs/jbossesb/workspace/rearchitecture/product/core/rosetta: 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/format/tests 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 12:17:54 EDT 2006


Author: mark.little at jboss.com
Date: 2006-09-20 12:17:48 -0400 (Wed, 20 Sep 2006)
New Revision: 6325

Added:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
Modified:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.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/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
Log:
Final pass at initial unit tests for EPR and Messaging.

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java	2006-09-20 15:53:06 UTC (rev 6324)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java	2006-09-20 16:17:48 UTC (rev 6325)
@@ -111,11 +111,10 @@
 				int newSize = _content.length + toAdd.length;
 				byte[] buffer = new byte[newSize];
 				
-				for (int i = 0; i < _content.length; i++)
-					buffer[i] = _content[i];
+				System.arraycopy(_content, 0, buffer, 0, _content.length);
+				System.arraycopy(toAdd, 0, buffer, _content.length, toAdd.length);
 				
-				for (int j = 0; j < toAdd.length; j++)
-					buffer[_content.length+j] = toAdd[j];
+				_content = buffer;
 			}
 		}
 	}

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 15:53:06 UTC (rev 6324)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java	2006-09-20 16:17:48 UTC (rev 6325)
@@ -185,15 +185,14 @@
 				_content = toAdd;
 			}
 			else
-			{
+			{	
 				int newSize = _content.length + toAdd.length;
 				byte[] buffer = new byte[newSize];
 				
-				for (int i = 0; i < _content.length; i++)
-					buffer[i] = _content[i];
+				System.arraycopy(_content, 0, buffer, 0, _content.length);
+				System.arraycopy(toAdd, 0, buffer, _content.length, toAdd.length);
 				
-				for (int j = 0; j < toAdd.length; j++)
-					buffer[_content.length+j] = toAdd[j];
+				_content = buffer;
 			}
 		}
 		

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java	2006-09-20 15:53:06 UTC (rev 6324)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java	2006-09-20 16:17:48 UTC (rev 6325)
@@ -91,6 +91,24 @@
 		}
 	}
 	
+	public void testNullURIConvertMessage ()
+	{
+		try
+		{
+			Message msg = MessageFactory.getInstance().getMessage(null, null);
+			
+			fail();
+		}
+		catch (InvalidParameterException ex)
+		{
+			// success
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
 	public void testPlugin ()
 	{
 		System.setProperty(MessagePlugin.MESSAGE_PLUGIN+"1", ExampleMessagePlugin.class.getName());

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java	2006-09-20 15:53:06 UTC (rev 6324)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java	2006-09-20 16:17:48 UTC (rev 6325)
@@ -26,6 +26,7 @@
 
 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.
@@ -36,7 +37,7 @@
 public class MessageUnitTest extends TestCase
 {
 	
-	public void testFields ()
+	public void testDefaultMessageFields ()
 	{
 		Message msg = MessageFactory.getInstance().getMessage();
 		
@@ -47,4 +48,26 @@
 		assertEquals((msg.getFault() != 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);
+	}
+	
+	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);
+	}
+	
 }

Added: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java	2006-09-20 15:53:06 UTC (rev 6324)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java	2006-09-20 16:17:48 UTC (rev 6325)
@@ -0,0 +1,341 @@
+/*
+ * 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.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringWriter;
+import java.security.InvalidParameterException;
+
+import javax.transaction.xa.XAResource;
+
+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 (InvalidParameterException 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 (InvalidParameterException 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 (InvalidParameterException 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());
+		}	
+	}
+	
+}

Modified: 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 15:53:06 UTC (rev 6324)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java	2006-09-20 16:17:48 UTC (rev 6325)
@@ -148,6 +148,28 @@
 		}
 	}
 
+	public void testInvalidAdd ()
+	{
+		Message msg = MessageFactory.getInstance().getMessage(
+				MessageType.JBOSS_XML);
+
+		assertEquals((msg != null), true);
+		
+		try
+		{
+			msg.getBody().add(null, null);
+			
+			fail();
+		}
+		catch (InvalidParameterException ex)
+		{
+		}
+		catch (Exception ex)
+		{
+			fail(ex.toString());
+		}
+	}
+	
 	public void testAddBytes ()
 	{
 		Message msg = MessageFactory.getInstance().getMessage(
@@ -196,6 +218,58 @@
 		}
 	}
 	
+	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(




More information about the jboss-svn-commits mailing list