[jboss-svn-commits] JBL Code SVN: r6507 - labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Sep 30 19:16:05 EDT 2006
Author: mark.little at jboss.com
Date: 2006-09-30 19:16:02 -0400 (Sat, 30 Sep 2006)
New Revision: 6507
Added:
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java
Log:
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java 2006-09-30 23:15:44 UTC (rev 6506)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java 2006-09-30 23:16:02 UTC (rev 6507)
@@ -0,0 +1,117 @@
+package org.jboss.soa.esb.message.format.tests;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Fault;
+import org.jboss.soa.esb.message.Header;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically. Each plugin is responsible for
+ * returning a message implementation that knows how to serialize its state in a
+ * specific manner, e.g., XML or ASN.1.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class ExampleMessageImpl implements Message
+{
+
+ /**
+ * @return get the header component of the message.
+ */
+
+ public Header getHeader ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get the context component of the message.
+ */
+
+ public Context getContext ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get the body component of the message.
+ */
+
+ public Body getBody ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get any faults associated with the message. These should not
+ * be application level faults, but comms level.
+ */
+
+ public Fault getFault ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get any message attachments.
+ */
+
+ public Attachment getAttachment ()
+ {
+ return null;
+ }
+ /**
+ * @return get any message properties
+ */
+ public Properties getProperties()
+ {
+ return null;
+ }
+
+ /**
+ * @return the type of this message.
+ */
+
+ public URI getType ()
+ {
+ try
+ {
+ return new URI(ExampleMessagePlugin.URN);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java 2006-09-30 23:15:44 UTC (rev 6506)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java 2006-09-30 23:16:02 UTC (rev 6507)
@@ -0,0 +1,69 @@
+package org.jboss.soa.esb.message.format.tests;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+
+import java.net.URI;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically. Each plugin is responsible for
+ * returning a message implementation that knows how to serialize its state in a
+ * specific manner, e.g., XML or ASN.1.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class ExampleMessagePlugin implements MessagePlugin
+{
+
+ public static final String URN = "foobar";
+
+ /**
+ * @return the message instance.
+ */
+
+ public Message getMessage ()
+ {
+ return new ExampleMessageImpl();
+ }
+
+ /**
+ * @return the unique identifier for this message plugin.
+ */
+
+ public URI getType ()
+ {
+ try
+ {
+ return new URI(URN);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java 2006-09-30 23:15:44 UTC (rev 6506)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java 2006-09-30 23:16:02 UTC (rev 6507)
@@ -0,0 +1,130 @@
+/*
+ * 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.format.tests;
+
+import java.net.URI;
+import java.lang.IllegalArgumentException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class MessageFactoryUnitTest extends TestCase
+{
+ public void testDefaultMessage ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+
+ assertEquals((msg != null), true);
+ }
+
+ public void testURIMessage ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(MessageType.DEFAULT_TYPE);
+ Message msg2 = MessageFactory.getInstance().getMessage();
+
+ assertEquals(msg1.getType().equals(msg2.getType()), true);
+
+ Message msg3 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ assertEquals(msg1.getType().equals(msg3.getType()), false);
+ }
+
+ public void testInvalidURIMessage ()
+ {
+ try
+ {
+ Message msg = MessageFactory.getInstance().getMessage(new URI("urn:foo"));
+
+ assertEquals((msg == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testNullURIMessage ()
+ {
+ try
+ {
+ Message msg = MessageFactory.getInstance().getMessage(null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ // success
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testNullURIConvertMessage ()
+ {
+ try
+ {
+ Message msg = MessageFactory.getInstance().getMessage(null, null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ // success
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testPlugin ()
+ {
+ System.setProperty(MessagePlugin.MESSAGE_PLUGIN+"1", ExampleMessagePlugin.class.getName());
+
+ MessageFactory.getInstance().reset();
+
+ try
+ {
+ URI uri = new URI(ExampleMessagePlugin.URN);
+ Message msg = MessageFactory.getInstance().getMessage(uri);
+
+ assertEquals(msg.getType().equals(uri), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list