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: MessagePopulatorVerifier.java,v 1.2 2004/02/03 07:31:04 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.util;
46
47 import javax.jms.BytesMessage;
48 import javax.jms.MapMessage;
49 import javax.jms.Message;
50 import javax.jms.ObjectMessage;
51 import javax.jms.StreamMessage;
52 import javax.jms.TextMessage;
53
54 import org.exolab.jmscts.core.AbstractMessageVerifier;
55 import org.exolab.jmscts.core.MessagePopulator;
56
57
58 /***
59 * A helper class for populating and verifying the content of messages.
60 * This class provides no population or verification functionality -
61 * that is left to sublasses.
62 *
63 * @version $Revision: 1.2 $ $Date: 2004/02/03 07:31:04 $
64 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
65 * @see AbstractMessageVerifier
66 * @see MessagePopulator
67 */
68 public abstract class MessagePopulatorVerifier extends AbstractMessageVerifier
69 implements MessagePopulator {
70
71 /***
72 * Construct a new instance. No exceptions are expected to be thrown
73 * when invoking methods
74 */
75 public MessagePopulatorVerifier() {
76 }
77
78 /***
79 * Construct an instance with the expected exception thrown when
80 * methods are invoked
81 *
82 * @param exception the expected exception type when methods are invoked
83 */
84 public MessagePopulatorVerifier(Class exception) {
85 super(exception);
86 }
87
88 /***
89 * Populate a message with data. This method delegates the message to
90 * the appropriate populator method.
91 *
92 * @param message the message to populate
93 * @throws Exception for any error
94 */
95 public void populate(Message message) throws Exception {
96 if (message instanceof BytesMessage) {
97 populateBytesMessage((BytesMessage) message);
98 } else if (message instanceof MapMessage) {
99 populateMapMessage((MapMessage) message);
100 } else if (message instanceof ObjectMessage) {
101 populateObjectMessage((ObjectMessage) message);
102 } else if (message instanceof StreamMessage) {
103 populateStreamMessage((StreamMessage) message);
104 } else if (message instanceof TextMessage) {
105 populateTextMessage((TextMessage) message);
106 } else {
107 populateMessage(message);
108 }
109 }
110
111 /***
112 * Populate a Message instance with data. This method throws
113 * UnsupportedOperationException if invoked. Subclasses needing the
114 * functionality must implement it.
115 *
116 * @param message the message to populate
117 * @throws Exception for any error
118 * @throws UnsupportedOperationException if invoked
119 */
120 public void populateMessage(Message message) throws Exception {
121 throw new UnsupportedOperationException(
122 "populateMessage() not implemented by " + getClass().getName());
123 }
124
125 /***
126 * Populate a BytesMessage instance with data. This method throws
127 * UnsupportedOperationException if invoked. Subclasses needing the
128 * functionality must implement it.
129 *
130 * @param message the message to populate
131 * @throws Exception for any error
132 * @throws UnsupportedOperationException if invoked
133 */
134 public void populateBytesMessage(BytesMessage message) throws Exception {
135 throw new UnsupportedOperationException(
136 "populateBytesMessage() not implemented by "
137 + getClass().getName());
138 }
139
140 /***
141 * Populate a MapMessage instance with data. This method throws
142 * UnsupportedOperationException if invoked. Subclasses needing the
143 * functionality must implement it.
144 *
145 * @param message the message to populate
146 * @throws Exception for any error
147 * @throws UnsupportedOperationException if invoked
148 */
149 public void populateMapMessage(MapMessage message) throws Exception {
150 throw new UnsupportedOperationException(
151 "populateMapMessage() not implemented by " + getClass().getName());
152 }
153
154 /***
155 * Populate an ObjectMessage instance with data. This method throws
156 * UnsupportedOperationException if invoked. Subclasses needing the
157 * functionality must implement it.
158 *
159 * @param message the message to populate
160 * @throws Exception for any error
161 * @throws UnsupportedOperationException if invoked
162 */
163 public void populateObjectMessage(ObjectMessage message) throws Exception {
164 throw new UnsupportedOperationException(
165 "populateObjectMessage() not implemented by "
166 + getClass().getName());
167 }
168
169 /***
170 * Populate a StreamMessage instance with data. This method throws
171 * UnsupportedOperationException if invoked. Subclasses needing the
172 * functionality must implement it.
173 *
174 * @param message the message to populate
175 * @throws Exception for any error
176 * @throws UnsupportedOperationException if invoked
177 */
178 public void populateStreamMessage(StreamMessage message) throws Exception {
179 throw new UnsupportedOperationException(
180 "populateStreamMessage() not implemented by "
181 + getClass().getName());
182 }
183
184 /***
185 * Populate a TextMessage instance with data. This method throws
186 * UnsupportedOperationException if invoked. Subclasses needing the
187 * functionality must implement it.
188 *
189 * @param message the message to populate
190 * @throws Exception for any error
191 * @throws UnsupportedOperationException if invoked
192 */
193 public void populateTextMessage(TextMessage message) throws Exception {
194 throw new UnsupportedOperationException(
195 "populateTextMessage() not implemented by "
196 + getClass().getName());
197 }
198
199 /***
200 * Helper to return a byte array of the specified length, populated with
201 * an incrementing sequence of values
202 *
203 * @param length the length of the array
204 * @param start the number to start the sequence at
205 * @return a new byte array
206 */
207 protected byte[] populateByteArray(int length, int start) {
208 byte[] result = new byte[length];
209 byte j = (byte) start;
210 for (int i = 0; i < length; ++i, ++j) {
211 result[i] = j;
212 }
213 return result;
214 }
215
216 }
217
This page was automatically generated by Maven