View Javadoc

1   /*
2    * $Id: JmsConnectorJndiTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.jms.integration;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  
16  import org.junit.Test;
17  
18  /**
19   * Requires the following connector config: <jms:connector name="jmsConnector1"
20   * jndiInitialFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
21   * jndiProviderUrl="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"
22   * connectionFactoryJndiName="ConnectionFactory" /> <jms:xxx-connector
23   * name="jmsConnector2"
24   * jndiInitialFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
25   * jndiProviderUrl="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"
26   * jndiProviderProperties-ref="providerProperties" jndiDestinations="true"
27   * forceJndiDestinations="true" connectionFactoryJndiName="ConnectionFactory" />
28   * <spring:beans> <util:properties id="providerProperties"> <!-- see
29   * http://activemq.apache.org/jndi-support.html for configuring queues/topics through
30   * JNDI properties for other Jms vendors these JNDI properties will need to be
31   * available from the JNDI context --> <spring:prop key="queue.in2">in-queue2</spring:prop>
32   * <spring:prop key="topic.some/long/path/in3">in-topic3</spring:prop>
33   * </util:properties> </spring:beans>
34   */
35  public class JmsConnectorJndiTestCase extends AbstractJmsFunctionalTestCase
36  {
37      @Override
38      protected String getConfigResources()
39      {
40          return "integration/jms-jndi-config.xml";
41      }
42  
43      @Test
44      public void testConnectionFactoryFromJndi() throws Exception
45      {
46          // No need to specifically test anything here, if the ConnectionFactory 
47          // is not successfully looked up from JNDI, Mule won't even start up.
48      }
49  
50      @Test
51      public void testQueueFromJndi() throws Exception
52      {
53          MuleClient client = new MuleClient(muleContext);
54  
55          client.dispatch("ep_jndi-queue", DEFAULT_INPUT_MESSAGE, null);
56  
57          MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
58          assertNotNull(result);
59          assertEquals(DEFAULT_INPUT_MESSAGE, result.getPayloadAsString());
60      }
61  
62      @Test
63      public void testTopicFromJndi() throws Exception
64      {
65          MuleClient client = new MuleClient(muleContext);
66  
67          client.dispatch("ep_jndi-topic", DEFAULT_INPUT_MESSAGE, null);
68  
69          MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
70          assertNotNull(result);
71          assertEquals(DEFAULT_INPUT_MESSAGE, result.getPayloadAsString());
72      }
73  
74      /**
75       * Use a non-JNDI Destination when jndiDestinations="false", test should pass.
76       */
77      @Test
78      public void testNonJndiDestination() throws Exception
79      {
80          MuleClient client = new MuleClient(muleContext);
81  
82          client.dispatch("ep_non-jndi-queue", DEFAULT_INPUT_MESSAGE, null);
83  
84          MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
85          assertNotNull(result);
86          assertEquals(DEFAULT_INPUT_MESSAGE, result.getPayloadAsString());
87      }
88  
89      /**
90       * Use a non-JNDI Destination when jndiDestinations="true" but forceJndiDestinations="false", test should pass.
91       */
92      @Test
93      public void testNonJndiDestinationOptional() throws Exception
94      {
95          MuleClient client = new MuleClient(muleContext);
96  
97          client.dispatch("ep_non-jndi-queue-optional-jndi", DEFAULT_INPUT_MESSAGE, null);
98  
99          MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
100         assertNotNull(result);
101         assertEquals(DEFAULT_INPUT_MESSAGE, result.getPayloadAsString());
102     }
103 
104     /**
105      * Use a non-JNDI Destination when forceJndiDestinations="true", test should fail.
106      */
107     @Test
108     public void testNonJndiDestinationForce() throws Exception
109     {
110         MuleClient client = new MuleClient(muleContext);
111 
112         client.dispatch("ep_non-jndi-queue-force-jndi", DEFAULT_INPUT_MESSAGE, null);
113 
114         MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
115         assertNull("Attempt to look up a non-existant JNDI Destination should have failed", result);
116     }
117 }