1   /*
2    * $Id: JmsClientAcknowledgeTransactionTestCase.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   * Test jms using JmsClientAcknowledgeTransactionFactory
20   */
21  public class JmsClientAcknowledgeTransactionTestCase extends AbstractJmsFunctionalTestCase
22  {
23  
24      protected String getConfigResources()
25      {
26          return "providers/activemq/jms-client-acknowledge-tx.xml";
27      }
28  
29      public void testJmsClientAcknowledgeTransaction() throws Exception
30      {
31          send(scenarioAcknowledge);
32          receive(scenarioWithoutAcknowledge);
33          receive(scenarioAcknowledge);
34          receive(scenarioNotReceive);
35      }
36  
37      Scenario scenarioAcknowledge = new AbstractScenario()
38      {
39          //@Override
40          public int getAcknowledge()
41          {
42              return Session.CLIENT_ACKNOWLEDGE;
43          }
44  
45          public void send(Session session, MessageProducer producer) throws JMSException
46          {
47              producer.send(session.createTextMessage(DEFAULT_INPUT_MESSAGE));
48          }
49  
50          public Message receive(Session session, MessageConsumer consumer) throws JMSException
51          {
52              Message message = consumer.receive(TIMEOUT);
53              assertNotNull(message);
54              message.acknowledge();
55              return message;
56          }
57  
58          public boolean isTransacted()
59          {
60              return false;
61          }
62  
63  
64      };
65  
66      Scenario scenarioWithoutAcknowledge = new AbstractScenario()
67      {
68          //@Override
69          public int getAcknowledge()
70          {
71              return Session.CLIENT_ACKNOWLEDGE;
72          }
73  
74          public Message receive(Session session, MessageConsumer consumer) throws JMSException
75          {
76              Message message = consumer.receive(TIMEOUT);
77              assertNotNull(message);
78              return message;
79          }
80  
81      };
82  
83  
84  }