public static void ensureEquivalent(final Message m1,final ActiveMQMessage m2) throws JMSException {
  ProxyAssertSupport.assertTrue(m1 != m2);
  ProxyAssertSupport.assertEquals(m1.getJMSTimestamp(),m2.getJMSTimestamp());
  byte[] corrIDBytes=null;
  String corrIDString=null;
  try {
    corrIDBytes=m1.getJMSCorrelationIDAsBytes();
  }
 catch (  JMSException e) {
    corrIDString=m1.getJMSCorrelationID();
  }
  if (corrIDBytes != null) {
    ProxyAssertSupport.assertTrue(Arrays.equals(corrIDBytes,m2.getJMSCorrelationIDAsBytes()));
  }
 else   if (corrIDString != null) {
    ProxyAssertSupport.assertEquals(corrIDString,m2.getJMSCorrelationID());
  }
 else {
    try {
      byte[] corrID2=m2.getJMSCorrelationIDAsBytes();
      ProxyAssertSupport.assertNull(corrID2);
    }
 catch (    JMSException e) {
      String corrID2=m2.getJMSCorrelationID();
      ProxyAssertSupport.assertNull(corrID2);
    }
  }
  ProxyAssertSupport.assertEquals(m1.getJMSReplyTo(),m2.getJMSReplyTo());
  ProxyAssertSupport.assertEquals(m1.getJMSDestination(),m2.getJMSDestination());
  ProxyAssertSupport.assertEquals(m1.getJMSDeliveryMode(),m2.getJMSDeliveryMode());
  ProxyAssertSupport.assertEquals(m1.getJMSType(),m2.getJMSType());
  ProxyAssertSupport.assertEquals(m1.getJMSExpiration(),m2.getJMSExpiration());
  ProxyAssertSupport.assertEquals(m1.getJMSPriority(),m2.getJMSPriority());
  int m1PropertyCount=0, m2PropertyCount=0;
  for (Enumeration<String> p=m1.getPropertyNames(); p.hasMoreElements(); ) {
    String name=p.nextElement();
    if (!name.startsWith("JMSX")) {
      m1PropertyCount++;
    }
  }
  for (Enumeration p=m2.getPropertyNames(); p.hasMoreElements(); ) {
    String name=(String)p.nextElement();
    if (!name.startsWith("JMSX")) {
      m2PropertyCount++;
    }
  }
  ProxyAssertSupport.assertEquals(m1PropertyCount,m2PropertyCount);
  for (Enumeration props=m1.getPropertyNames(); props.hasMoreElements(); ) {
    boolean found=false;
    String name=(String)props.nextElement();
    if (name.startsWith("JMSX")) {
      continue;
    }
    boolean booleanProperty=false;
    try {
      booleanProperty=m1.getBooleanProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertEquals(booleanProperty,m2.getBooleanProperty(name));
      continue;
    }
    byte byteProperty=0;
    try {
      byteProperty=m1.getByteProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertEquals(byteProperty,m2.getByteProperty(name));
      continue;
    }
    short shortProperty=0;
    try {
      shortProperty=m1.getShortProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertEquals(shortProperty,m2.getShortProperty(name));
      continue;
    }
    int intProperty=0;
    try {
      intProperty=m1.getIntProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertEquals(intProperty,m2.getIntProperty(name));
      continue;
    }
    long longProperty=0;
    try {
      longProperty=m1.getLongProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertEquals(longProperty,m2.getLongProperty(name));
      continue;
    }
    float floatProperty=0;
    try {
      floatProperty=m1.getFloatProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertTrue(floatProperty == m2.getFloatProperty(name));
      continue;
    }
    double doubleProperty=0;
    try {
      doubleProperty=m1.getDoubleProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertTrue(doubleProperty == m2.getDoubleProperty(name));
      continue;
    }
    String stringProperty=null;
    try {
      stringProperty=m1.getStringProperty(name);
      found=true;
    }
 catch (    JMSException e) {
    }
    if (found) {
      ProxyAssertSupport.assertEquals(stringProperty,m2.getStringProperty(name));
      continue;
    }
    ProxyAssertSupport.fail("Cannot identify property " + name);
  }
}

public static void ensureEquivalent ( final Message m1 , final ActiveMQMessage m2 ) throws JMSException { ProxyAssertSupport . assertTrue ( m1 != m2 ) ; ProxyAssertSupport . assertEquals ( m1 . getJMSTimestamp ( ) , m2 . getJMSTimestamp ( ) ) ; byte [ ] corrIDBytes = null ; String corrIDString = null ; try { corrIDBytes = m1 . getJMSCorrelationIDAsBytes ( ) ; } catch ( JMSException e ) { corrIDString = m1 . getJMSCorrelationID ( ) ; } if ( corrIDBytes != null ) { ProxyAssertSupport . assertTrue ( Arrays . equals ( corrIDBytes , m2 . getJMSCorrelationIDAsBytes ( ) ) ) ; } else if ( corrIDString != null ) { ProxyAssertSupport . assertEquals ( corrIDString , m2 . getJMSCorrelationID ( ) ) ; } else { try { byte [ ] corrID2 = m2 . getJMSCorrelationIDAsBytes ( ) ; ProxyAssertSupport . assertNull ( corrID2 ) ; } catch ( JMSException e ) { String corrID2 = m2 . getJMSCorrelationID ( ) ; ProxyAssertSupport . assertNull ( corrID2 ) ; } } ProxyAssertSupport . assertEquals ( m1 . getJMSReplyTo ( ) , m2 . getJMSReplyTo ( ) ) ; ProxyAssertSupport . assertEquals ( m1 . getJMSDestination ( ) , m2 . getJMSDestination ( ) ) ; ProxyAssertSupport . assertEquals ( m1 . getJMSDeliveryMode ( ) , m2 . getJMSDeliveryMode ( ) ) ; ProxyAssertSupport . assertEquals ( m1 . getJMSType ( ) , m2 . getJMSType ( ) ) ; ProxyAssertSupport . assertEquals ( m1 . getJMSExpiration ( ) , m2 . getJMSExpiration ( ) ) ; ProxyAssertSupport . assertEquals ( m1 . getJMSPriority ( ) , m2 . getJMSPriority ( ) ) ; int m1PropertyCount = 0 , m2PropertyCount = 0 ; for ( Enumeration < String > p = m1 . getPropertyNames ( ) ; p . hasMoreElements ( ) ; ) { String name = p . nextElement ( ) ; if ( ! name . startsWith ( "JMSX" ) ) { m1PropertyCount ++ ; } } for ( Enumeration p = m2 . getPropertyNames ( ) ; p . hasMoreElements ( ) ; ) { String name = ( String ) p . nextElement ( ) ; if ( ! name . startsWith ( "JMSX" ) ) { m2PropertyCount ++ ; } } ProxyAssertSupport . assertEquals ( m1PropertyCount , m2PropertyCount ) ; for ( Enumeration props = m1 . getPropertyNames ( ) ; props . hasMoreElements ( ) ; ) { boolean found = false ; String name = ( String ) props . nextElement ( ) ; if ( name . startsWith ( "JMSX" ) ) { continue ; } boolean booleanProperty = false ; try { booleanProperty = m1 . getBooleanProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertEquals ( booleanProperty , m2 . getBooleanProperty ( name ) ) ; continue ; } byte byteProperty = 0 ; try { byteProperty = m1 . getByteProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertEquals ( byteProperty , m2 . getByteProperty ( name ) ) ; continue ; } short shortProperty = 0 ; try { shortProperty = m1 . getShortProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertEquals ( shortProperty , m2 . getShortProperty ( name ) ) ; continue ; } int intProperty = 0 ; try { intProperty = m1 . getIntProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertEquals ( intProperty , m2 . getIntProperty ( name ) ) ; continue ; } long longProperty = 0 ; try { longProperty = m1 . getLongProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertEquals ( longProperty , m2 . getLongProperty ( name ) ) ; continue ; } float floatProperty = 0 ; try { floatProperty = m1 . getFloatProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertTrue ( floatProperty == m2 . getFloatProperty ( name ) ) ; continue ; } double doubleProperty = 0 ; try { doubleProperty = m1 . getDoubleProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertTrue ( doubleProperty == m2 . getDoubleProperty ( name ) ) ; continue ; } String stringProperty = null ; try { stringProperty = m1 . getStringProperty ( name ) ; found = true ; } catch ( JMSException e ) { } if ( found ) { ProxyAssertSupport . assertEquals ( stringProperty , m2 . getStringProperty ( name ) ) ; continue ; } ProxyAssertSupport . fail ( "Cannot identify property " + name ) ; } }
makes sure two physically different message are equivalent : they have identical jms fields and body .
