1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact tma@netspace.net.au.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: RecoverClearTest.java,v 1.10 2004/02/03 21:52:09 tanderson Exp $
44   */
45  package org.exolab.jmscts.test.message.clear;
46  
47  import java.util.Iterator;
48  import java.util.List;
49  
50  import javax.jms.Message;
51  import javax.jms.Session;
52  
53  import junit.framework.Test;
54  
55  import org.exolab.jmscts.core.AbstractSendReceiveTestCase;
56  import org.exolab.jmscts.core.MessageReceiver;
57  import org.exolab.jmscts.core.MessageSender;
58  import org.exolab.jmscts.core.MessageVerifier;
59  import org.exolab.jmscts.core.TestContext;
60  import org.exolab.jmscts.core.TestCreator;
61  
62  import org.exolab.jmscts.test.message.util.MessagePopulatorVerifier;
63  import org.exolab.jmscts.test.message.util.MessagePropertyVerifier;
64  import org.exolab.jmscts.test.message.util.PopulatorVerifierFactory;
65  
66  
67  /***
68   * This class tests the behaviour of <code>Message.clearBody()</code> and
69   * <code>Message.clearProperties()</code> for CLIENT_ACKNOWLEDGE sessions
70   * where the session is recovered.
71   *
72   * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
73   * @version $Revision: 1.10 $
74   * @jmscts.session CLIENT_ACKNOWLEDGE
75   * @jmscts.delivery all
76   */
77  public class RecoverClearTest extends AbstractSendReceiveTestCase {
78  
79      /***
80       * The destination used by this test case
81       */
82      private static final String DESTINATION = "RecoverClearTest";
83  
84  
85      /***
86       * Construct a new <code>RecoverClearTest</code>
87       *
88       * @param name the name of test case
89       */
90      public RecoverClearTest(String name) {
91          super(name);
92      }
93  
94      /***
95       * Sets up the test suite
96       *
97       * @return an instance of this class that may be run by
98       * {@link org.exolab.jmscts.core.JMSTestRunner}
99       */
100     public static Test suite() {
101         return TestCreator.createSendReceiveTest(RecoverClearTest.class);
102     }
103 
104     /***
105      * Returns the list of destination names used by this test case. These
106      * are used to pre-create destinations prior to running the test case.
107      *
108      * @return the list of destinations used by this test case
109      */
110     public String[] getDestinations() {
111         return new String[] {DESTINATION};
112     }
113 
114     /***
115      * Verifies that clearing the properties and bodies of received messages
116      * doesn't affect the messages received after recovering the session
117      *
118      * @jmscts.requirement message.method.clearProperties
119      * @jmscts.requirement message.method.clearBody
120      * @throws Exception for any error
121      */
122     public void testRecover() throws Exception {
123         final int count = 10;
124         TestContext context = getContext();
125         Message message = context.getMessage();
126         MessagePopulatorVerifier properties = new MessagePropertyVerifier();
127         MessagePopulatorVerifier body = PopulatorVerifierFactory.create(
128             message);
129 
130         MessageReceiver receiver = createReceiver(DESTINATION);
131 
132         try {
133             MessageSender sender = createSender(DESTINATION);
134             for (int i = 0; i < count; ++i) {
135                 message.clearProperties();
136                 properties.populate(message);
137                 message.clearBody();
138                 body.populate(message);
139                 sender.send(message, 1);
140             }
141 
142             // now receive and verify them
143             List messages = verify(receiver, properties, body, count);
144 
145             // clear the received messages
146             Iterator iter = messages.iterator();
147             while (iter.hasNext()) {
148                 Message received = (Message) iter.next();
149                 message.clearProperties();
150                 message.clearBody();
151             }
152 
153             // recover the session, and re-receive and verify the messages
154             // haven't changed
155             Session session = context.getSession();
156             session.recover();
157             verify(receiver, properties, body, count);
158         } finally {
159             receiver.remove();
160         }
161     }
162 
163     /***
164      * Receive messages, and verify them
165      *
166      * @param receiver the receiver
167      * @param properties the message property verifier
168      * @param body the message body verifier
169      * @param count the no. of mesages to receive
170      * @return the received messages
171      * @throws Exception for any error
172      */
173     private List verify(MessageReceiver receiver, MessageVerifier properties,
174                         MessageVerifier body, int count) throws Exception {
175 
176         TestContext context = getContext();
177 
178         // receive the messages, and verify them
179         List messages = receive(receiver, count);
180         Iterator iter = messages.iterator();
181         while (iter.hasNext()) {
182             Message received = (Message) iter.next();
183             properties.verify(received);
184             body.verify(received);
185         }
186         return messages;
187     }
188 
189 }
This page was automatically generated by Maven