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: StreamMessageVerifier.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.StreamMessage;
48  
49  import org.exolab.jmscts.core.MethodCache;
50  
51  
52  /***
53   * A helper class for populating and verifying the content of StreamMessage
54   * instances.
55   *
56   * @version     $Revision: 1.2 $ $Date: 2004/02/03 07:31:04 $
57   * @author      <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
58   * @see         MessagePopulatorVerifier
59   */
60  class StreamMessageVerifier extends MessagePopulatorVerifier {
61  
62      /***
63       * Method cache for StreamMessage
64       */
65      private static MethodCache _methods = null;
66  
67      /***
68       * Byte array size
69       */
70      private static final int BYTE_ARRAY_SIZE = 10;
71  
72  
73      /***
74       * Construct a new instance. No exceptions are expected to be thrown
75       * when invoking methods
76       */
77      public StreamMessageVerifier() {
78      }
79  
80      /***
81       * Construct an instance with the expected exception thrown when
82       * methods are invoked
83       *
84       * @param exception the expected exception type when methods are invoked
85       */
86      public StreamMessageVerifier(Class exception) {
87          super(exception);
88      }
89  
90      /***
91       * Attempt to populate a StreamMessage instance with data
92       *
93       * @param message the message to populate
94       * @throws Exception for any error
95       */
96      public void populateStreamMessage(StreamMessage message) throws Exception {
97          byte[] bytes = populateByteArray(BYTE_ARRAY_SIZE, 0);
98          invoke(message, "writeBoolean", Boolean.TRUE);
99          invoke(message, "writeByte", new Byte(Byte.MIN_VALUE));
100         invoke(message, "writeBytes", bytes);
101 
102         Object[] args = {bytes, new Integer(1), new Integer(bytes.length - 2)};
103         invoke(message, "writeBytes", args);
104         invoke(message, "writeShort", new Short(Short.MIN_VALUE));
105         invoke(message, "writeChar", new Character(Character.MIN_VALUE));
106         invoke(message, "writeInt", new Integer(Integer.MIN_VALUE));
107         invoke(message, "writeLong", new Long(Long.MIN_VALUE));
108         invoke(message, "writeFloat", new Float(Float.MIN_VALUE));
109         invoke(message, "writeDouble", new Double(Double.MIN_VALUE));
110         invoke(message, "writeString", "ABC");
111 
112         invoke(message, "writeObject", Boolean.TRUE);
113         invoke(message, "writeObject", new Byte(Byte.MAX_VALUE));
114         invoke(message, "writeObject", bytes);
115         invoke(message, "writeObject", new Short(Short.MAX_VALUE));
116         invoke(message, "writeObject", new Character(Character.MAX_VALUE));
117         invoke(message, "writeObject", new Integer(Integer.MAX_VALUE));
118         invoke(message, "writeObject", new Long(Long.MAX_VALUE));
119         invoke(message, "writeObject", new Float(Float.MAX_VALUE));
120         invoke(message, "writeObject", new Double(Double.MAX_VALUE));
121         invoke(message, "writeObject", "ABC");
122     }
123 
124     /***
125      * Attempt to verify the content of a StreamMessage invoked via the above
126      * {@link #populateStreamMessage}.
127      *
128      * @param message the message to verify
129      * @throws Exception for any error
130      */
131     public void verifyStreamMessage(StreamMessage message) throws Exception {
132         expect(message, "readBoolean", Boolean.TRUE);
133         expect(message, "readByte", new Byte(Byte.MIN_VALUE));
134 
135         byte[] buffer1 = new byte[BYTE_ARRAY_SIZE];
136         expect(message, "readBytes", buffer1, new Integer(buffer1.length));
137         equal(buffer1, populateByteArray(buffer1.length, 0));
138         expect(message, "readBytes", buffer1, new Integer(-1));
139 
140         byte[] buffer2 = new byte[BYTE_ARRAY_SIZE - 2];
141         expect(message, "readBytes", buffer2, new Integer(buffer2.length));
142         equal(buffer2, populateByteArray(buffer2.length, 1));
143         expect(message, "readBytes", buffer2, new Integer(-1));
144 
145         expect(message, "readShort", new Short(Short.MIN_VALUE));
146         expect(message, "readChar", new Character(Character.MIN_VALUE));
147         expect(message, "readInt", new Integer(Integer.MIN_VALUE));
148         expect(message, "readLong", new Long(Long.MIN_VALUE));
149         expect(message, "readFloat", new Float(Float.MIN_VALUE));
150         expect(message, "readDouble", new Double(Double.MIN_VALUE));
151         expect(message, "readString", "ABC");
152 
153         expect(message, "readObject", Boolean.TRUE);
154         expect(message, "readObject", new Byte(Byte.MAX_VALUE));
155         expect(message, "readObject", populateByteArray(BYTE_ARRAY_SIZE, 0));
156         expect(message, "readObject", new Short(Short.MAX_VALUE));
157         expect(message, "readObject", new Character(Character.MAX_VALUE));
158         expect(message, "readObject", new Integer(Integer.MAX_VALUE));
159         expect(message, "readObject", new Long(Long.MAX_VALUE));
160         expect(message, "readObject", new Float(Float.MAX_VALUE));
161         expect(message, "readObject", new Double(Double.MAX_VALUE));
162         expect(message, "readObject", "ABC");
163     }
164 
165     /***
166      * Returns a cache of the <code>StreamMessage</code> methods
167      *
168      * @return a cache of the <code>StreamMessage</code> methods
169      */
170     protected synchronized MethodCache getMethods() {
171         if (_methods == null) {
172             _methods = new MethodCache(StreamMessage.class);
173         }
174         return _methods;
175     }
176 
177 }
This page was automatically generated by Maven