[jboss-svn-commits] JBL Code SVN: r26715 - in labs/jbossesb/workspace/dbevenius/jbossas5/product: rosetta/tests/src/org/jboss/soa/esb/actions/routing and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon May 25 03:59:42 EDT 2009
Author: beve
Date: 2009-05-25 03:59:42 -0400 (Mon, 25 May 2009)
New Revision: 26715
Modified:
labs/jbossesb/workspace/dbevenius/jbossas5/product/install/esb-deployers-jboss-beans.xml
labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbDeployerUnitTest.java
Log:
Updated JmsRouterIntegrationTest to use mockejb. Might want to merge this into JmsRouterUnit test later.
Modified: labs/jbossesb/workspace/dbevenius/jbossas5/product/install/esb-deployers-jboss-beans.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/jbossas5/product/install/esb-deployers-jboss-beans.xml 2009-05-24 23:26:09 UTC (rev 26714)
+++ labs/jbossesb/workspace/dbevenius/jbossas5/product/install/esb-deployers-jboss-beans.xml 2009-05-25 07:59:42 UTC (rev 26715)
@@ -5,23 +5,23 @@
<deployment xmlns="urn:jboss:bean-deployer:2.0">
<bean name="EsbConfigParser" class="org.jboss.soa.esb.listeners.deployers.mc.EsbConfigParser">
- <property name="esbDeploymentPrefix">jboss.esb:deployment=</property>
- <property name="warDeploymentPrefix">jboss.web.deployment:war=</property>
- <property name="actionArtifactsFile">/actionArtifactMap.properties</property>
- </bean>
-
+ <property name="esbDeploymentPrefix">jboss.esb:deployment=</property>
+ <property name="warDeploymentPrefix">jboss.web.deployment:war=</property>
+ <property name="actionArtifactsFile">/actionArtifactMap.properties</property>
+ </bean>
+
<bean name="EsbWebServiceDeployer" class="org.jboss.soa.esb.listeners.deployers.mc.EsbWebServiceDeployer"/>
-
+
<bean name="EsbWsdlDeployer" class="org.jboss.soa.esb.listeners.deployers.mc.EsbWsdlDeployer"/>
- <bean name="EsbDeployer" class="org.jboss.soa.esb.listeners.deployers.mc.EsbDeployer">
- <property name="esbBeanPrefix">jboss.esb</property>
- <property name="defaultDependencies">
- <list elementClass="java.lang.String">
- <value>jboss.esb:service=ESBRegistry</value>
- <value>jboss.esb:service=JuddiRMI</value>
- </list>
- </property>
- </bean>
+ <bean name="EsbDeployer" class="org.jboss.soa.esb.listeners.deployers.mc.EsbDeployer">
+ <property name="esbBeanPrefix">jboss.esb</property>
+ <property name="defaultDependencies">
+ <list elementClass="java.lang.String">
+ <value>jboss.esb:service=ESBRegistry</value>
+ <value>jboss.esb:service=JuddiRMI</value>
+ </list>
+ </property>
+ </bean>
</deployment>
Modified: labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2009-05-24 23:26:09 UTC (rev 26714)
+++ labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2009-05-25 07:59:42 UTC (rev 26715)
@@ -28,12 +28,19 @@
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import javax.jms.Destination;
+import javax.jms.ExceptionListener;
import javax.jms.JMSException;
-import javax.jms.Queue;
+import javax.jms.MessageProducer;
+import javax.jms.QueueConnection;
+import javax.jms.QueueSession;
+import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -46,17 +53,22 @@
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.NamingContextException;
+import org.jboss.soa.esb.helpers.NamingContextPool;
import org.jboss.soa.esb.listeners.gateway.DefaultESBPropertiesSetter;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
import org.jboss.soa.esb.testutils.SerializableMockQueue;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockejb.jms.MockQueue;
import org.mockejb.jms.ObjectMessageImpl;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
import org.mockejb.jms.TextMessageImpl;
import org.mockejb.jndi.MockContextFactory;
@@ -64,318 +76,545 @@
* Integration test for {@link JMSRouter}
* <p/>
* @author John Doe
- * @author <a href="daniel.bevenius at redhat.com">Daniel Bevenius</a>
+ * @author <a href="daniel.bevenius at redhat.com">Daniel Bevenius</a>
*
*/
public class JmsRouterIntegrationTest
{
- @SuppressWarnings ( "unused")
- private Logger log = Logger.getLogger( JmsRouterIntegrationTest.class );
+ @SuppressWarnings ( "unused")
+ private Logger log = Logger.getLogger( JmsRouterIntegrationTest.class );
- private final String messageID = "1234-junittest";
- private final String bodyContent = "hello";
- private Message msg;
- private ConfigTree tree;
- private static final String PROPERTY_SETTER_TEST_NAME = "MockJMSPropertiesSetter" ;
+ private final String messageID = "1234-junittest";
+ private final String bodyContent = "hello";
+ private Message msg;
+ private ConfigTree tree;
+ private static final String PROPERTY_SETTER_TEST_NAME = "MockJMSPropertiesSetter" ;
+
+ private static final String CONNECTION_FACTORY = "ConnectionFactory" ;
+ private static final String QUEUE_NAME = "jmsRouterQueue" ;
+
+ @BeforeClass
+ public static void setUp() throws Exception
+ {
+ MockContextFactory.setAsInitial();
+
+ final Context ctx = NamingContextPool.getNamingContext(null);
+ try
+ {
+ ctx.rebind(CONNECTION_FACTORY, new MockQueueConnectionFactory());
+ ctx.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+ }
+ finally
+ {
+ NamingContextPool.releaseNamingContext(ctx) ;
+ }
+ System.setProperty(Environment.JNDI_SERVER_CONTEXT_FACTORY, System.getProperty(Context.INITIAL_CONTEXT_FACTORY)) ;
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception
+ {
+ MockContextFactory.revertSetAsInitial();
+ }
- @Test
- public void processWithUnwrapFalse() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
- {
- MockJMSRouter router = new MockJMSRouter(tree);
- router.route( msg );
+ @Test
+ public void processWithUnwrapFalse() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ MockJMSRouter router = new MockJMSRouter(tree);
+ router.route( msg );
- assertProcessContract( messageID, msg, router );
- }
+ assertProcessContract( messageID, msg, router );
+ }
- @Test
- public void processWithUnwrapTrue() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
- {
- tree.setAttribute( "unwrap", "true" );
- MockJMSRouter router = new MockJMSRouter( tree );
+ @Test
+ public void processWithUnwrapTrue() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( "unwrap", "true" );
+ MockJMSRouter router = new MockJMSRouter( tree );
- router.route( msg );
+ router.route( msg );
- assertProcessContract( messageID, msg, router );
- final javax.jms.Message jmsMessage = ((MockJMSRouter) router).getJmsMessage();
+ assertProcessContract( messageID, msg, router );
+ final javax.jms.Message jmsMessage = ((MockJMSRouter) router).getJmsMessage();
- assertTrue ( jmsMessage instanceof TextMessage );
- final javax.jms.TextMessage textMessage = (TextMessage) jmsMessage;
+ assertTrue ( jmsMessage instanceof TextMessage );
+ final javax.jms.TextMessage textMessage = (TextMessage) jmsMessage;
- assertEquals ( textMessage.getJMSCorrelationID(), messageID );
- assertEquals ( textMessage.getText(), bodyContent );
- }
-
- @Test
- public void constructorWithSecurity() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
- {
- final String principal = "guest";
- final String credential = "guest";
- tree.setAttribute( "unwrap", "true" );
- tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, principal );
- tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, credential );
- MockJMSRouter router = new MockJMSRouter( tree );
-
- assertEquals ( principal, router.getSecurityPrincipal() );
- assertEquals ( credential, router.getSecurityCredential() );
- }
-
- @Test ( expected = ConfigurationException.class )
- public void shouldThrowIfPrincipalIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
- {
- tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, "testpassword" );
- new MockJMSRouter( tree );
- }
-
- @Test ( expected = ConfigurationException.class )
- public void shouldThrowIfCredentialIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
- {
- tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, "testuser" );
- new MockJMSRouter( tree );
- }
+ assertEquals ( textMessage.getJMSCorrelationID(), messageID );
+ assertEquals ( textMessage.getText(), bodyContent );
+ }
+
+ @Test
+ public void constructorWithSecurity() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ final String principal = "guest";
+ final String credential = "guest";
+ tree.setAttribute( "unwrap", "true" );
+ tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, principal );
+ tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, credential );
+ MockJMSRouter router = new MockJMSRouter( tree );
+
+ assertEquals ( principal, router.getSecurityPrincipal() );
+ assertEquals ( credential, router.getSecurityCredential() );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfPrincipalIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, "testpassword" );
+ new MockJMSRouter( tree );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfCredentialIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, "testuser" );
+ new MockJMSRouter( tree );
+ }
- @Test ( expected = ActionProcessingException.class )
- public void shouldThrowIfObjectIsNotAMessageObject() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
- {
- ConfigTree tree = createConfigTree();
- JMSRouter router = new MockJMSRouter(tree);
- router.route( "test" );
- }
+ @Test ( expected = ActionProcessingException.class )
+ public void shouldThrowIfObjectIsNotAMessageObject() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
+ {
+ ConfigTree tree = createConfigTree();
+ JMSRouter router = new MockJMSRouter(tree);
+ router.route( "test" );
+ }
- @Test
- public void setJMSReplyToQueue() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException, NamingContextException
- {
- try
- {
- MockContextFactory.setAsInitial();
- Context context = new InitialContext();
- MockContextFactory.setDelegateContext( context );
-
- final String destName = "/queue/A";
- final MockQueue queue = new SerializableMockQueue( destName );
-
- context.rebind( destName, queue );
+ @Test
+ public void setJMSReplyToQueue() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException, NamingContextException
+ {
+ try
+ {
+ MockContextFactory.setAsInitial();
+ Context context = new InitialContext();
+ MockContextFactory.setDelegateContext( context );
+
+ final MockQueue queue = new SerializableMockQueue( QUEUE_NAME );
+
+ context.rebind( QUEUE_NAME, queue );
- // inbound is to simulate a jms message arriving at a gateway endpoint.
- TextMessageImpl inBoundJmsMessage = new TextMessageImpl();
- inBoundJmsMessage.setJMSReplyTo( queue );
- new DefaultESBPropertiesSetter().setPropertiesFromJMSMessage( inBoundJmsMessage, msg );
-
- JMSRouter router = new JMSRouter( createConfigTree() );
-
- // outbound is to simulate a new jms message that is about to leave the ESB.
- TextMessageImpl outBoundJmsMessage = new TextMessageImpl();
- router.setJMSReplyTo( outBoundJmsMessage, msg );
- }
- finally
- {
- MockContextFactory.revertSetAsInitial();
- }
- }
-
- @Test
- public void constructWithDefaultPersitentAttribute() throws ConfigurationException, NamingException, JMSException
- {
- ConfigTree config = createConfigTree();
- JMSRouter router = new JMSRouter( config );
- assertTrue( router.isDeliveryModePersistent() );
- }
+ // inbound is to simulate a jms message arriving at a gateway endpoint.
+ TextMessageImpl inBoundJmsMessage = new TextMessageImpl();
+ inBoundJmsMessage.setJMSReplyTo( queue );
+ new DefaultESBPropertiesSetter().setPropertiesFromJMSMessage( inBoundJmsMessage, msg );
+
+ JMSRouter router = new JMSRouter( createConfigTree() );
+
+ // outbound is to simulate a new jms message that is about to leave the ESB.
+ TextMessageImpl outBoundJmsMessage = new TextMessageImpl();
+ router.setJMSReplyTo( outBoundJmsMessage, msg );
+ }
+ finally
+ {
+ MockContextFactory.revertSetAsInitial();
+ }
+ }
+
+ @Test
+ public void constructWithDefaultPersitentAttribute() throws ConfigurationException, NamingException, JMSException
+ {
+ ConfigTree config = createConfigTree();
+ JMSRouter router = new JMSRouter( config );
+ assertTrue( router.isDeliveryModePersistent() );
+ }
- @Test
- public void constructWithPersitentAttribute() throws ConfigurationException, NamingException, JMSException
- {
- ConfigTree config = createConfigTree();
- config.setAttribute( JMSRouter.PERSISTENT_ATTR, "false" );
- JMSRouter router = new JMSRouter( config );
+ @Test
+ public void constructWithPersitentAttribute() throws ConfigurationException, NamingException, JMSException
+ {
+ ConfigTree config = createConfigTree();
+ config.setAttribute( JMSRouter.PERSISTENT_ATTR, "false" );
+ JMSRouter router = new JMSRouter( config );
- assertFalse ( router.isDeliveryModePersistent() );
- }
+ assertFalse ( router.isDeliveryModePersistent() );
+ }
- @Test
- public void constructWithDefaultPriorityAttribute() throws ConfigurationException, NamingException, JMSException
- {
- ConfigTree config = createConfigTree();
- JMSRouter router = new JMSRouter( config );
- assertEquals( javax.jms.Message.DEFAULT_PRIORITY, router.getPriority() );
- }
+ @Test
+ public void constructWithDefaultPriorityAttribute() throws ConfigurationException, NamingException, JMSException
+ {
+ ConfigTree config = createConfigTree();
+ JMSRouter router = new JMSRouter( config );
+ assertEquals( javax.jms.Message.DEFAULT_PRIORITY, router.getPriority() );
+ }
- @Test
- public void constructWithPriorityAttribute() throws ConfigurationException, NamingException, JMSException
- {
- final int expectedPriority = 9;
- ConfigTree config = createConfigTree();
- config.setAttribute( JMSRouter.PRIORITY_ATTR, String.valueOf( expectedPriority ) );
- JMSRouter router = new JMSRouter( config );
+ @Test
+ public void constructWithPriorityAttribute() throws ConfigurationException, NamingException, JMSException
+ {
+ final int expectedPriority = 9;
+ ConfigTree config = createConfigTree();
+ config.setAttribute( JMSRouter.PRIORITY_ATTR, String.valueOf( expectedPriority ) );
+ JMSRouter router = new JMSRouter( config );
- assertEquals ( expectedPriority, router.getPriority() );
- }
+ assertEquals ( expectedPriority, router.getPriority() );
+ }
- @Test
- public void constructWithDefaultTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
- {
- ConfigTree config = createConfigTree();
- JMSRouter router = new JMSRouter( config );
- assertEquals( javax.jms.Message.DEFAULT_TIME_TO_LIVE, router.getTimeToLive() );
- }
+ @Test
+ public void constructWithDefaultTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
+ {
+ ConfigTree config = createConfigTree();
+ JMSRouter router = new JMSRouter( config );
+ assertEquals( javax.jms.Message.DEFAULT_TIME_TO_LIVE, router.getTimeToLive() );
+ }
- @Test
- public void constructWithTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
- {
- final long ttl = 6000l;
- ConfigTree config = createConfigTree();
- config.setAttribute( JMSRouter.TIME_TO_LIVE_ATTR, String.valueOf( ttl ) );
- JMSRouter router = new JMSRouter( config );
+ @Test
+ public void constructWithTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
+ {
+ final long ttl = 6000l;
+ ConfigTree config = createConfigTree();
+ config.setAttribute( JMSRouter.TIME_TO_LIVE_ATTR, String.valueOf( ttl ) );
+ JMSRouter router = new JMSRouter( config );
- assertEquals ( ttl, router.getTimeToLive() );
- }
+ assertEquals ( ttl, router.getTimeToLive() );
+ }
- @Test
- public void specifyJNDIPropertiesInConfig() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
- {
- final String jndiContextFactoryName = "org.jnp.interfaces.NamingContextFactory";
- final String jndiURL = "localhost:1099";
- final String jndiPkgPrefix = "org.jboss.naming";
- final String connectionFactory = "ConnectionFactory";
+ @Test
+ public void specifyJNDIPropertiesInConfig() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
+ {
+ final String jndiContextFactoryName = "org.jnp.interfaces.NamingContextFactory";
+ final String jndiURL = "localhost:1099";
+ final String jndiPkgPrefix = "org.jboss.naming";
+ final String connectionFactory = "ConnectionFactory";
- ConfigTree config = createConfigTree();
- config.setAttribute( JMSEpr.JNDI_CONTEXT_FACTORY_TAG, jndiContextFactoryName );
- config.setAttribute( JMSEpr.JNDI_URL_TAG, jndiURL );
- config.setAttribute( JMSEpr.JNDI_PKG_PREFIX_TAG, jndiPkgPrefix );
- config.setAttribute( JMSEpr.CONNECTION_FACTORY_TAG, connectionFactory );
+ ConfigTree config = createConfigTree();
+ config.setAttribute( JMSEpr.JNDI_CONTEXT_FACTORY_TAG, jndiContextFactoryName );
+ config.setAttribute( JMSEpr.JNDI_URL_TAG, jndiURL );
+ config.setAttribute( JMSEpr.JNDI_PKG_PREFIX_TAG, jndiPkgPrefix );
+ config.setAttribute( JMSEpr.CONNECTION_FACTORY_TAG, connectionFactory );
- JMSRouter router = new JMSRouter( config );
- assertEquals( jndiContextFactoryName, router.getContextFactoryName() );
- assertEquals( jndiURL, router.getJndiURL() );
- assertEquals( jndiPkgPrefix, router.getJndiPkgPrefix() );
- assertEquals( connectionFactory, router.getConnectionFactory() );
- }
+ MockJMSRouter router = new MockJMSRouter( config );
+ assertEquals( jndiContextFactoryName, router.getContextFactoryName() );
+ assertEquals( jndiURL, router.getJndiURL() );
+ assertEquals( jndiPkgPrefix, router.getJndiPkgPrefix() );
+ assertEquals( connectionFactory, router.getConnectionFactory() );
+ }
- @Test
- public void usePropertyStrategy() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
- {
- final ConfigTree tree = createConfigTree() ;
- tree.setAttribute(JMSRouter.PROPERTY_STRATEGY, MockJMSPropertiesSetter.class.getName()) ;
- final MockJMSRouter router = new MockJMSRouter(tree) ;
- router.route(msg) ;
- assertEquals("Property setter value", PROPERTY_SETTER_TEST_NAME, router.getJmsMessage().getStringProperty(PROPERTY_SETTER_TEST_NAME)) ;
- }
-
- @Before
- public void setup() throws URISyntaxException
- {
- msg = createESBMessageObject( messageID, bodyContent );
- tree = createConfigTree();
- }
-
- // private
+ @Test
+ public void usePropertyStrategy() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
+ {
+ final ConfigTree tree = createConfigTree() ;
+ tree.setAttribute(JMSRouter.PROPERTY_STRATEGY, MockJMSPropertiesSetter.class.getName()) ;
+ final MockJMSRouter router = new MockJMSRouter(tree) ;
+ router.route(msg) ;
+ assertEquals("Property setter value", PROPERTY_SETTER_TEST_NAME, router.getJmsMessage().getStringProperty(PROPERTY_SETTER_TEST_NAME)) ;
+ }
+
+ @Before
+ public void setup() throws URISyntaxException
+ {
+ msg = createESBMessageObject( messageID, bodyContent );
+ tree = createConfigTree();
+ }
+
+ private void assertProcessContract( final String messageID, final Message msg, JMSRouter router ) throws ActionProcessingException, JMSException
+ {
+ final Message message = router.process ( msg );
+ assertNull ( "Routers process should return null", message );
+ final javax.jms.Message jmsMessage = ((MockJMSRouter) router).getJmsMessage();
+ assertEquals ( jmsMessage.getJMSCorrelationID(), messageID );
+ }
- private void assertProcessContract( final String messageID, final Message msg, JMSRouter router ) throws ActionProcessingException, JMSException
- {
- final Message message = router.process ( msg );
- assertNull ( "Routers process should return null", message );
- final javax.jms.Message jmsMessage = ((MockJMSRouter) router).getJmsMessage();
- assertEquals ( jmsMessage.getJMSCorrelationID(), messageID );
- }
+ private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+ msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
+ msg.getBody().add(body.getBytes());
+ return msg;
+ }
- private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
- {
- Message msg = MessageFactory.getInstance().getMessage();
- msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
- msg.getBody().add(body.getBytes());
- return msg;
- }
+ private static ConfigTree createConfigTree()
+ {
+ ConfigTree tree = new ConfigTree("test");
+ tree.setAttribute("jndiName", QUEUE_NAME);
+ return tree;
+ }
+
+ private static class MockJMSRouter extends JMSRouter
+ {
+ @SuppressWarnings ( "unused" )
+ private Logger log = Logger.getLogger( MockJMSRouter.class );
- private static ConfigTree createConfigTree()
- {
- ConfigTree tree = new ConfigTree("test");
- tree.setAttribute("jndiName", "/queue/A");
- return tree;
- }
-
- private static class MockJMSRouter extends JMSRouter
- {
- @SuppressWarnings ( "unused" )
- private Logger log = Logger.getLogger( MockJMSRouter.class );
+ private javax.jms.Message jmsMessage;
+
+ private String securityPrincipal;
+ private String securityCredential;
- private javax.jms.Message jmsMessage;
-
- private String securityPrincipal;
- private String securityCredential;
-
- public MockJMSRouter(ConfigTree propertiesTree) throws ConfigurationException, NamingException, JMSException
- {
- super( propertiesTree );
+ public MockJMSRouter(ConfigTree propertiesTree) throws ConfigurationException, NamingException, JMSException
+ {
+ super( propertiesTree );
}
- @Override
- protected void createQueueSetup( String queueName ) throws ConfigurationException { }
+ @Override
+ protected void createQueueSetup( String queueName ) throws ConfigurationException { }
- @Override
+ @Override
protected void createQueueSetup( String queueName,
- String jndiContextFactory,
- String jndiUrl,
- String jndiPkgPrefix,
- String connectionFactory,
- String securityPrincipal,
- String securityCredential) throws ConfigurationException
+ String jndiContextFactory,
+ String jndiUrl,
+ String jndiPkgPrefix,
+ String connectionFactory,
+ String securityPrincipal,
+ String securityCredential) throws ConfigurationException
{
- this.securityPrincipal = securityPrincipal;
- this.securityCredential = securityCredential;
+ this.securityPrincipal = securityPrincipal;
+ this.securityCredential = securityCredential;
}
- @Override
- protected void send( javax.jms.Message jmsMessage ) throws JMSException
- {
- this.jmsMessage = jmsMessage;
- }
+ @Override
+ protected void send( javax.jms.Message jmsMessage ) throws JMSException
+ {
+ this.jmsMessage = jmsMessage;
+ }
- public javax.jms.Message getJmsMessage()
- {
- return jmsMessage;
- }
+ public javax.jms.Message getJmsMessage()
+ {
+ return jmsMessage;
+ }
- @Override
- protected javax.jms.Message createJMSMessageWithObjectType( Object objectFromBody ) throws JMSException
- {
- TextMessageImpl textMessage = new TextMessageImpl();
- textMessage.setText( new String ((byte[])objectFromBody) );
- return textMessage;
- }
+ @Override
+ protected javax.jms.Message createJMSMessageWithObjectType( Object objectFromBody ) throws JMSException
+ {
+ TextMessageImpl textMessage = new TextMessageImpl();
+ textMessage.setText( new String ((byte[])objectFromBody) );
+ return textMessage;
+ }
- @Override
- protected javax.jms.Message createObjectMessage( Object message ) throws JMSException
- {
- ObjectMessageImpl impl = new ObjectMessageImpl();
- impl.setObject( (Serializable) message );
- return impl;
- }
-
- public String getSecurityPrincipal()
- {
- return securityPrincipal;
- }
+ @Override
+ protected javax.jms.Message createObjectMessage( Object message ) throws JMSException
+ {
+ ObjectMessageImpl impl = new ObjectMessageImpl();
+ impl.setObject( (Serializable) message );
+ return impl;
+ }
+
+ public String getSecurityPrincipal()
+ {
+ return securityPrincipal;
+ }
- public String getSecurityCredential()
- {
- return securityCredential;
- }
- }
-
- static class MockJMSPropertiesSetter implements JMSPropertiesSetter
- {
- public void setJMSProperties(final Message esbMsg, final javax.jms.Message jmsMessage)
- throws JMSException
- {
- jmsMessage.setStringProperty(PROPERTY_SETTER_TEST_NAME, PROPERTY_SETTER_TEST_NAME) ;
- }
- }
+ public String getSecurityCredential()
+ {
+ return securityCredential;
+ }
+ }
+
+ static class MockJMSPropertiesSetter implements JMSPropertiesSetter
+ {
+ public void setJMSProperties(final Message esbMsg, final javax.jms.Message jmsMessage)
+ throws JMSException
+ {
+ jmsMessage.setStringProperty(PROPERTY_SETTER_TEST_NAME, PROPERTY_SETTER_TEST_NAME) ;
+ }
+ }
+
+ private static final class MockQueueConnectionFactory extends QueueConnectionFactoryImpl
+ {
+ static int queueConnectionCount ;
+
+ @Override
+ public QueueConnection createQueueConnection() throws JMSException
+ {
+ queueConnectionCount++ ;
+ return (QueueConnection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {QueueConnection.class},
+ new MockQueueExceptionHandlerInvocationHandler(super.createQueueConnection())) ;
+ }
+ }
+
+ private static final class MockQueueExceptionHandlerInvocationHandler implements InvocationHandler
+ {
+ private final QueueConnection queueConnection ;
+ private javax.jms.ExceptionListener exceptionListener ;
+ static int queueSessionCount ;
+
+ MockQueueExceptionHandlerInvocationHandler(final QueueConnection queueConnection)
+ {
+ this.queueConnection = queueConnection ;
+ }
+
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
+ throws Throwable
+ {
+ final String methodName = method.getName() ;
+ if ("setExceptionListener".equals(methodName))
+ {
+ exceptionListener = (ExceptionListener)args[0] ;
+ return null ;
+ }
+ else if ("getExceptionListener".equals(methodName))
+ {
+ return exceptionListener ;
+ }
+ else
+ {
+ final Object response = method.invoke(queueConnection, args) ;
+ if (response instanceof QueueSession)
+ {
+ queueSessionCount++ ;
+ final QueueSession queueSession = (QueueSession)response ;
+ return (QueueSession)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {QueueSession.class},
+ new MockQueueSessionInvocationHandler(this, queueSession)) ;
+ }
+ else
+ {
+ return response ;
+ }
+ }
+ }
+
+ void fireExceptionListener(final JMSException exception)
+ {
+ if (exceptionListener != null)
+ {
+ exceptionListener.onException(exception) ;
+ }
+ }
+ }
+
+ private static final class MockQueueSessionInvocationHandler implements InvocationHandler
+ {
+ private final MockQueueExceptionHandlerInvocationHandler exceptionHandler ;
+ private final QueueSession queueSession ;
+ static int producerCount ;
+
+ MockQueueSessionInvocationHandler(final MockQueueExceptionHandlerInvocationHandler exceptionHandler, final QueueSession queueSession)
+ {
+ this.exceptionHandler = exceptionHandler ;
+ this.queueSession = queueSession ;
+ }
+
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
+ throws Throwable
+ {
+ final String methodName = method.getName() ;
+ if ("recover".equals(methodName))
+ {
+ return null ;
+ }
+ else if ("createProducer".equals(methodName))
+ {
+ producerCount++ ;
+ return new MockFailMessageProducer(exceptionHandler) ;
+ }
+ else if ("getAcknowledgeMode".equals(methodName))
+ {
+ return Integer.valueOf(Session.AUTO_ACKNOWLEDGE) ;
+ }
+ else if ("getTransacted".equals(methodName))
+ {
+ return Boolean.FALSE ;
+ }
+ else
+ {
+ return method.invoke(queueSession, args) ;
+ }
+ }
+ }
+
+ private static final class MockFailMessageProducer implements MessageProducer
+ {
+ private final MockQueueExceptionHandlerInvocationHandler exceptionHandler ;
+
+ public MockFailMessageProducer(final MockQueueExceptionHandlerInvocationHandler exceptionHandler)
+ {
+ this.exceptionHandler = exceptionHandler ;
+ }
+
+ public void close() throws JMSException {}
- /*
- * Just here to help Ant to find annotated test.
- */
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter( JmsRouterIntegrationTest.class );
- }
+ public int getDeliveryMode()
+ throws JMSException
+ {
+ return 0;
+ }
+ public Destination getDestination()
+ throws JMSException
+ {
+ return null;
+ }
+
+ public boolean getDisableMessageID()
+ throws JMSException
+ {
+ return false;
+ }
+
+ public boolean getDisableMessageTimestamp()
+ throws JMSException
+ {
+ return false;
+ }
+
+ public int getPriority() throws JMSException
+ {
+ return 0;
+ }
+
+ public long getTimeToLive() throws JMSException
+ {
+ return 0;
+ }
+
+ public void send(Message arg0) throws JMSException
+ {
+ exception() ;
+ }
+
+ public void send(Destination arg0, Message arg1) throws JMSException
+ {
+ throw new JMSException("Deliberate send exception") ;
+ }
+
+ public void send(Message arg0, int arg1, int arg2, long arg3) throws JMSException
+ {
+ throw new JMSException("Deliberate send exception") ;
+ }
+
+ private void exception() throws JMSException
+ {
+ final JMSException exception = new JMSException("Deliberate send exception") ;
+ exceptionHandler.fireExceptionListener(exception) ;
+ throw exception ;
+ }
+
+ public void send(Destination arg0, Message arg1, int arg2, int arg3, long arg4)
+ throws JMSException
+ {
+ }
+
+ public void setDeliveryMode(int arg0) throws JMSException {}
+
+ public void setDisableMessageID(boolean arg0) throws JMSException {}
+
+ public void setDisableMessageTimestamp(boolean arg0) throws JMSException {}
+
+ public void setPriority(int arg0) throws JMSException {}
+
+ public void setTimeToLive(long arg0) throws JMSException {}
+
+ public void send(javax.jms.Message arg0) throws JMSException
+ {
+ }
+
+ public void send(Destination arg0, javax.jms.Message arg1) throws JMSException
+ {
+ }
+
+ public void send(javax.jms.Message arg0, int arg1, int arg2, long arg3) throws JMSException
+ {
+ }
+
+ public void send(Destination arg0, javax.jms.Message arg1, int arg2, int arg3, long arg4) throws JMSException
+ {
+ }
+ }
+
+
+ /*
+ * Just here to help Ant to find annotated test.
+ */
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter( JmsRouterIntegrationTest.class );
+ }
+
}
Modified: labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbDeployerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbDeployerUnitTest.java 2009-05-24 23:26:09 UTC (rev 26714)
+++ labs/jbossesb/workspace/dbevenius/jbossas5/product/rosetta/tests/src/org/jboss/soa/esb/listeners/deployers/mc/EsbDeployerUnitTest.java 2009-05-25 07:59:42 UTC (rev 26715)
@@ -25,8 +25,6 @@
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.test.kernel.junit.MicrocontainerTest;
/**
More information about the jboss-svn-commits
mailing list