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: SendReceiveReadWriteTest.java,v 1.6 2004/02/03 07:31:03 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.readwrite;
46
47 import javax.jms.Message;
48 import javax.jms.MessageNotWriteableException;
49 import javax.jms.Session;
50
51 import org.apache.log4j.Category;
52
53 import junit.framework.Test;
54
55 import org.exolab.jmscts.core.AbstractSendReceiveTestCase;
56 import org.exolab.jmscts.core.MessagePopulator;
57 import org.exolab.jmscts.core.MessageSender;
58 import org.exolab.jmscts.core.SequenceMessagePopulator;
59 import org.exolab.jmscts.core.SequencePropertyPopulator;
60 import org.exolab.jmscts.core.TestContext;
61 import org.exolab.jmscts.core.TestCreator;
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.PropertyValues;
65 import org.exolab.jmscts.test.message.util.PopulatorVerifierFactory;
66
67
68 /***
69 * This class tests that message properties and message bodies are writeable
70 * on send, and readable on receipt
71 *
72 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
73 * @version $Revision: 1.6 $
74 * @see AbstractSendReceiveTestCase
75 */
76 public class SendReceiveReadWriteTest extends AbstractSendReceiveTestCase
77 implements PropertyValues {
78
79 /***
80 * The destination used by this test case
81 */
82 private static final String DESTINATION = "SendReceiveReadWriteTest";
83
84 /***
85 * The logger
86 */
87 private static final Category log =
88 Category.getInstance(SendReceiveReadWriteTest.class);
89
90
91 /***
92 * Construct a new <code>SendReceiveReadWriteTest</code>
93 *
94 * @param name the name of test case
95 */
96 public SendReceiveReadWriteTest(String name) {
97 super(name);
98 }
99
100 /***
101 * Sets up the test suite
102 *
103 * @return an instance of this class that may be run by
104 * {@link org.exolab.jmscts.core.JMSTestRunner}
105 */
106 public static Test suite() {
107 return TestCreator.createSendReceiveTest(
108 SendReceiveReadWriteTest.class);
109 }
110
111 /***
112 * Get the message populator. This implementation always returns null
113 *
114 * @return null
115 */
116 public MessagePopulator getMessagePopulator() {
117 return null;
118 }
119
120 /***
121 * Returns the list of destination names used by this test case. These
122 * are used to pre-create destinations prior to running the test case.
123 *
124 * @return the list of destinations used by this test case
125 */
126 public String[] getDestinations() {
127 return new String[] {DESTINATION};
128 }
129
130 /***
131 * Verifies that the same message may be populated and sent more than once.
132 *
133 * @jmscts.requirement message.send
134 * @throws Exception for any error
135 */
136 public void testWriteableOnSend() throws Exception {
137 final int count = 10;
138 TestContext context = getContext();
139 Session session = context.getSession();
140 Message message = context.getMessage();
141
142 MessageSender sender = createSender(DESTINATION);
143 MessagePopulator property = new SequencePropertyPopulator();
144 MessagePopulator body = new SequenceMessagePopulator();
145
146 try {
147 for (int i = 0; i < count; ++i) {
148 try {
149 property.populate(message);
150 } catch (Exception exception) {
151 String msg = "Failed to populate message properties on "
152 + i + " iteration prior to send";
153 log.error(msg, exception);
154 fail(msg + ": " + exception);
155 }
156
157 try {
158 body.populate(message);
159 } catch (Exception exception) {
160 String msg = "Failed to populate message body on " + i
161 + " iteration prior to send";
162 log.error(msg, exception);
163 fail(msg + ": " + exception);
164 }
165 sender.send(message, 1);
166 }
167 } finally {
168 sender.close();
169 }
170 }
171
172 /***
173 * Verifies that a message's user properties and body are read-only on
174 * receipt, and that they may be subsequently cleared.
175 *
176 * @jmscts.requirement message.receive
177 * @throws Exception for any error
178 */
179 public void testReadOnlyOnReceipt() throws Exception {
180 TestContext context = getContext();
181 Session session = context.getSession();
182 Message message = context.getMessage();
183
184 Class exceptionType = MessageNotWriteableException.class;
185 MessagePopulatorVerifier properties =
186 new MessagePropertyVerifier(exceptionType);
187 MessagePopulatorVerifier body =
188 PopulatorVerifierFactory.create(message, exceptionType);
189
190 Message received = sendReceive(message, DESTINATION);
191
192 // verify that that MessageNotWriteableException is thrown for
193 // each user property type, and each set/write method of the
194 // message. An exception will only be thrown if another type
195 // of exception is generated, or one of the operations doesn't
196 // throw MessageNotWriteableException
197 try {
198 properties.populate(received);
199 } catch (Exception exception) {
200 fail("Expected MessageNotWriteableException to be thrown when "
201 + "populating the properties of a received message, but "
202 + " got exception=" + exception.getClass().getName()
203 + ", message=" + exception.getMessage());
204 }
205 try {
206 body.populate(received);
207 } catch (Exception exception) {
208 fail("Expected MessageNotWriteableException to be thrown when "
209 + "populating the body of a received message, but "
210 + " got exception=" + exception.getClass().getName()
211 + ", message=" + exception.getMessage());
212 }
213
214 try {
215 received.clearProperties();
216 } catch (Exception exception) {
217 fail("Attempt to clear the properties of a received message "
218 + "threw exception=" + exception.getClass().getName()
219 + ", message=" + exception.getMessage());
220 }
221
222 try {
223 received.clearBody();
224 } catch (Exception exception) {
225 fail("Attempt to clear the body of a received message "
226 + "threw exception=" + exception.getClass().getName()
227 + ", message=" + exception.getMessage());
228 }
229 }
230
231 }
This page was automatically generated by Maven