org.mockejb.jms
Class MessageUtility

java.lang.Object
  extended byorg.mockejb.jms.MessageUtility

public final class MessageUtility
extends java.lang.Object

Collection of utility methods.

Author:
D11 Dimitar Gospodinov

Method Summary
static boolean compare(byte[] bytes1, byte[] bytes2)
          Compares two byte arrays.
static boolean compare(javax.jms.BytesMessage msg1, javax.jms.BytesMessage msg2)
          Compares two bytes messages.
static boolean compare(javax.jms.MapMessage msg1, javax.jms.MapMessage msg2)
          Compares two map messages.
static boolean compare(javax.jms.Message msg1, javax.jms.Message msg2)
          Compares two messages.
static boolean compare(javax.jms.ObjectMessage msg1, javax.jms.ObjectMessage msg2)
          Compares two object messages.
static boolean compare(javax.jms.StreamMessage msg1, javax.jms.StreamMessage msg2)
          Compares two stream messages.
static boolean compare(java.lang.String s1, java.lang.String s2)
          Compares two strings.
static boolean compare(javax.jms.TextMessage msg1, javax.jms.TextMessage msg2)
          Compares two text messages.
static MessageImpl copyMessage(javax.jms.Message msg, boolean reset)
          Copies header, properties and body of msg to a new message of the same type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compare

public static boolean compare(java.lang.String s1,
                              java.lang.String s2)
Compares two strings. Allows null values.

Parameters:
s1 -
s2 -
Returns:
true if s1 and s2 are null or s1.equals(s2) evaluates to true. In all other cases returns false.

compare

public static boolean compare(byte[] bytes1,
                              byte[] bytes2)
Compares two byte arrays. Disallow null values.

Parameters:
bytes1 -
bytes2 -
Returns:
true if bytes1 and bytes2 have the same lengths and content. In all other cases returns false.

compare

public static boolean compare(javax.jms.Message msg1,
                              javax.jms.Message msg2)
                       throws javax.jms.JMSException
Compares two messages. Messages are considered equal if they have the same header values and properties.

Parameters:
msg1 -
msg2 -
Returns:
true if all header fields in msg1 have the same values as the corresponded header fields in msg2, and all properties from msg1 exists and have the same values in msg2, and msg2 does not have properties that do not exist in msg1.
Throws:
javax.jms.JMSException

compare

public static boolean compare(javax.jms.BytesMessage msg1,
                              javax.jms.BytesMessage msg2)
                       throws javax.jms.JMSException
Compares two bytes messages. Messages are considered equal if they have the same value for their bodies and their header fields and properties values are the same.

Parameters:
msg1 -
msg2 -
Returns:
true if the body of msg1 has the same value as the body of msg2, and compare((Message)msg1, msg2) evaluates to true. In all other cases returns false.
Throws:
javax.jms.JMSException

compare

public static boolean compare(javax.jms.MapMessage msg1,
                              javax.jms.MapMessage msg2)
                       throws javax.jms.JMSException
Compares two map messages. Messages are considered equal if they have the same value for their bodies and their header fields and properties values are the same. Bodies of map messages are considered equal if they contain the same set of name-value pairs.

Parameters:
msg1 -
msg2 -
Returns:
true if the body of msg1 has the same value as the body of msg2, and compare((Message)msg1, msg2) evaluates to true. In all other cases returns false.
Throws:
javax.jms.JMSException

compare

public static boolean compare(javax.jms.ObjectMessage msg1,
                              javax.jms.ObjectMessage msg2)
                       throws javax.jms.JMSException
Compares two object messages. Messages are considered equal if they have the same value for their bodies and their header fields and properties values are the same. Bodies of object messages are considered the same if after deserialization msg1.getObject().equals(msg2.getObject) evaluates to true or both bodies are null.

Parameters:
msg1 -
msg2 -
Returns:
true if the body of msg1 has the same value as the body of msg2, and compare((Message)msg1, msg2) evaluates to true. In all other cases returns false.
Throws:
javax.jms.JMSException

compare

public static boolean compare(javax.jms.StreamMessage msg1,
                              javax.jms.StreamMessage msg2)
                       throws javax.jms.JMSException
Compares two stream messages. Messages are considered equal if they have the same value for their bodies and their header fields and properties values are the same. Bodies of stream messages are considered the same if they have the same number of elements and corresponding elements (elements that have the same position in the stream) are from the same type and have the same values.

Parameters:
msg1 -
msg2 -
Returns:
true if the body of msg1 has the same value as the body of msg2, and compare((Message)msg1, msg2) evaluates to true. In all other cases returns false.
Throws:
javax.jms.JMSException

compare

public static boolean compare(javax.jms.TextMessage msg1,
                              javax.jms.TextMessage msg2)
                       throws javax.jms.JMSException
Compares two text messages. Messages are considered equal if they have the same value for their bodies and their header fields and properties values are the same. Bodies of text messages are considered the same if msg1.getText().equals(msg2.getText()) evaluates to true or both bodies are null.

Parameters:
msg1 -
msg2 -
Returns:
true if the body of msg1 has the same value as the body of msg2, and compare((Message)msg1, msg2) evaluates to true. In all other cases returns false.
Throws:
javax.jms.JMSException

copyMessage

public static MessageImpl copyMessage(javax.jms.Message msg,
                                      boolean reset)
                               throws javax.jms.JMSException
Copies header, properties and body of msg to a new message of the same type.

Parameters:
msg - to be copied from
reset - true if the copy should be in read only mode. If msg is already in read-only mode this parameter is redundant.
Returns:
copy of msg
Throws:
javax.jms.JMSException