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: ClearTest.java,v 1.6 2004/02/03 07:31:02 tanderson Exp $
44   */
45  package org.exolab.jmscts.test.message.clear;
46  
47  import javax.jms.Message;
48  
49  import junit.framework.Test;
50  
51  import org.exolab.jmscts.core.AbstractMessageTestCase;
52  import org.exolab.jmscts.core.MessagePopulator;
53  import org.exolab.jmscts.core.TestContext;
54  import org.exolab.jmscts.core.TestCreator;
55  
56  import org.exolab.jmscts.test.message.util.EmptyMessageVerifier;
57  import org.exolab.jmscts.test.message.util.EmptyPropertyVerifier;
58  import org.exolab.jmscts.test.message.util.MessagePopulatorVerifier;
59  import org.exolab.jmscts.test.message.util.MessagePropertyVerifier;
60  import org.exolab.jmscts.test.message.util.PopulatorVerifierFactory;
61  
62  
63  /***
64   * This class tests the behaviour of <code>Message.clearBody()</code> and
65   * <code>Message.clearProperties()</code>
66   *
67   * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
68   * @version $Revision: 1.6 $
69   */
70  public class ClearTest extends AbstractMessageTestCase {
71  
72      /***
73       * Construct a new <code>ClearTest</code>
74       *
75       * @param name the name of test case
76       */
77      public ClearTest(String name) {
78          super(name);
79      }
80  
81      /***
82       * Sets up the test suite
83       *
84       * @return an instance of this class that may be run by
85       * {@link org.exolab.jmscts.core.JMSTestRunner}
86       */
87      public static Test suite() {
88          return TestCreator.createMessageTest(ClearTest.class);
89      }
90  
91      /***
92       * Get the message populator. This implementation always returns null
93       *
94       * @return null
95       */
96      public MessagePopulator getMessagePopulator() {
97          return null;
98      }
99  
100     /***
101      * Verifies that <code>Message.clearProperties()</code> can be invoked
102      * for a new message.
103      *
104      * @jmscts.requirement message.method.clearProperties
105      * @throws Exception for any error
106      */
107     public void testClearPropertiesOnCreation() throws Exception {
108         TestContext context = getContext();
109         Message message = context.getMessage();
110 
111         EmptyMessageVerifier empty = ClearHelper.createEmptyVerifier(message);
112         ClearHelper.checkClearProperties(message, empty, false);
113     }
114 
115     /***
116      * Verifies that <code>Message.clearBody()</code> can be invoked for a new
117      * message.
118      *
119      * @jmscts.message Message
120      * @jmscts.message MapMessage
121      * @jmscts.message ObjectMessage
122      * @jmscts.message TextMessage
123      * @jmscts.requirement message.method.clearBody
124      * @throws Exception for any error
125      */
126     public void testClearBodyOnCreation() throws Exception {
127         checkClearBodyOnCreation();
128     }
129 
130     /***
131      * Verifies that <code>BytesMessage.clearBody()</code> can be invoked
132      * for a new message
133      *
134      * @jmscts.message BytesMessage
135      * @jmscts.requirement message.method.clearBody
136      * @jmscts.requirement message.bytes.method.clearBody
137      * @throws Exception for any error
138      */
139     public void testBytesClearBodyOnCreation() throws Exception {
140         checkClearBodyOnCreation();
141     }
142 
143     /***
144      * Verifies that <code>StreamMessage.clearBody()</code> can be invoked
145      * for a new message
146      *
147      * @jmscts.message StreamMessage
148      * @jmscts.requirement message.method.clearBody
149      * @jmscts.requirement message.stream.method.clearBody
150      * @throws Exception for any error
151      */
152     public void testStreamClearBodyOnCreation() throws Exception {
153         checkClearBodyOnCreation();
154     }
155 
156     /***
157      * Verifies that <code>Message.clearProperties()</code> leaves the message
158      * properties empty, and doesn't clear the message body.
159      *
160      * @jmscts.requirement message.method.clearProperties
161      * @throws Exception for any error
162      */
163     public void testClearProperties() throws Exception {
164         TestContext context = getContext();
165         Message message = context.getMessage();
166 
167         MessagePopulatorVerifier properties = new MessagePropertyVerifier();
168         properties.populate(message);
169 
170         MessagePopulatorVerifier body = PopulatorVerifierFactory.create(
171             message);
172         body.populate(message);
173         ClearHelper.checkClearProperties(message, body, false);
174     }
175 
176     /***
177      * Verifies that <code>Message.clearBody()</code> leaves the message body
178      * empty, and doesn't clear the message properties.
179      *
180      * @jmscts.message Message
181      * @jmscts.message MapMessage
182      * @jmscts.message ObjectMessage
183      * @jmscts.message TextMessage
184      * @jmscts.requirement message.method.clearBody
185      * @throws Exception for any error
186      */
187     public void testClearBody() throws Exception {
188         checkClearBody();
189     }
190 
191     /***
192      * Verifies that <code>BytesMessage.clearBody()</code> leaves the message
193      * body empty, and doesn't clear the message properties.
194      *
195      * @jmscts.message BytesMessage
196      * @jmscts.requirement message.method.clearBody
197      * @jmscts.requirement message.bytes.method.clearBody
198      * @throws Exception for any error
199      */
200     public void testBytesClearBody() throws Exception {
201         checkClearBody();
202     }
203 
204     /***
205      * Verifies that <code>StreamMessage.clearBody()</code> leaves the message
206      * body empty, and doesn't clear the message properties.
207      *
208      * @jmscts.message StreamMessage
209      * @jmscts.requirement message.method.clearBody
210      * @jmscts.requirement message.stream.method.clearBody
211      * @throws Exception for any error
212      */
213     public void testStreamClearBody() throws Exception {
214         checkClearBody();
215     }
216 
217     /***
218      * Verifies that <code>Message.clearBody()</code> can be invoked for a new
219      * message.
220      *
221      * @throws Exception for any error
222      */
223     private void checkClearBodyOnCreation() throws Exception {
224         TestContext context = getContext();
225         Message message = context.getMessage();
226 
227         ClearHelper.checkClearBody(message, new EmptyPropertyVerifier());
228     }
229 
230     /***
231      * Verifies that <code>Message.clearBody()</code> leaves the message body
232      * empty, and doesn't clear the message properties.
233      *
234      * @throws Exception for any error
235      */
236     private void checkClearBody() throws Exception {
237         TestContext context = getContext();
238         Message message = context.getMessage();
239 
240         MessagePopulatorVerifier properties = new MessagePropertyVerifier();
241         properties.populate(message);
242 
243         MessagePopulatorVerifier body = PopulatorVerifierFactory.create(
244             message);
245         body.populate(message);
246         ClearHelper.checkClearBody(message, properties);
247     }
248 
249 }
This page was automatically generated by Maven