1   /*
2    * $Id: JmsDurableTopicSingleTxTestCase.java 9392 2007-10-26 11:05:57Z akuzmin $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  package org.mule.test.integration.providers.jms.functional;
11  
12  import javax.jms.JMSException;
13  import javax.jms.Message;
14  import javax.jms.MessageConsumer;
15  import javax.jms.MessageProducer;
16  import javax.jms.Session;
17  
18  /**
19   * Testing durable topic with external subscriber
20   */
21  public class JmsDurableTopicSingleTxTestCase extends JmsDurableTopicTestCase
22  {
23  
24      public static final String TOPIC_QUEUE_NAME = "durable.broadcast";
25  
26      protected String getConfigResources()
27      {
28          return "providers/activemq/jms-durable-topic-single-tx.xml";
29      }
30  
31      /**
32       * @throws Exception
33       */
34      public void testProviderDurableSubscriber() throws Exception
35      {
36          setClientId("Client1");
37          receive(scenarioNotReceive);
38          setClientId("Client2");
39          receive(scenarioNotReceive);
40  
41          setClientId("Sender");
42          send(scenarioCommit);
43  
44          setClientId("Client1");
45          receive(scenarioCommit);
46          receive(scenarioNotReceive);
47          setClientId("Client2");
48          receive(scenarioRollback);
49          receive(scenarioCommit);
50          receive(scenarioNotReceive);
51  
52      }
53  
54      AbstractJmsFunctionalTestCase.Scenario scenarioCommit = new AbstractJmsFunctionalTestCase.AbstractScenario()
55      {
56  
57          public String getOutputQueue()
58          {
59              return TOPIC_QUEUE_NAME;
60          }
61  
62          public void send(Session session, MessageProducer producer) throws JMSException
63          {
64              producer.send(session.createTextMessage(DEFAULT_INPUT_MESSAGE));
65              session.commit();
66          }
67  
68          public Message receive(Session session, MessageConsumer consumer) throws JMSException
69          {
70              Message message = consumer.receive(TIMEOUT);
71              assertNotNull(message);
72              session.commit();
73              return message;
74          }
75  
76          public boolean isTransacted()
77          {
78              return true;
79          }
80      };
81  
82      AbstractJmsFunctionalTestCase.Scenario scenarioRollback = new AbstractJmsFunctionalTestCase.AbstractScenario()
83      {
84  
85          public String getOutputQueue()
86          {
87              return TOPIC_QUEUE_NAME;
88          }
89  
90          public void send(Session session, MessageProducer producer) throws JMSException
91          {
92              producer.send(session.createTextMessage(DEFAULT_INPUT_MESSAGE));
93              session.rollback();
94          }
95  
96          public Message receive(Session session, MessageConsumer consumer) throws JMSException
97          {
98              Message message = consumer.receive(TIMEOUT);
99              assertNotNull(message);
100             session.rollback();
101             return message;
102         }
103 
104         public boolean isTransacted()
105         {
106             return true;
107         }
108 
109     };
110 
111 
112     AbstractJmsFunctionalTestCase.Scenario scenarioNotReceive = new AbstractJmsFunctionalTestCase.AbstractScenario()
113     {
114 
115         public String getOutputQueue()
116         {
117             return TOPIC_QUEUE_NAME;
118         }
119 
120         public Message receive(Session session, MessageConsumer consumer) throws JMSException
121         {
122             Message message = consumer.receive(SMALL_TIMEOUT);
123             assertNull(message);
124             return message;
125         }
126 
127         public boolean isTransacted()
128         {
129             return true;
130         }
131 
132     };
133 
134 }