public void testCopyConstructor() {
    for (int j = 0; j < 10; j++) {
      byte[] bytes = new byte[1000];
      for (int i = 0; i < bytes.length; i++) {
        bytes[i] = randomByte();
      }
      ByteBuffer bb = ByteBuffer.wrap(bytes);
      MessagingBuffer body = new ByteBufferWrapper(bb);
      ServerMessageImpl message =
          new ServerMessageImpl(
              randomByte(), randomBoolean(), randomLong(), randomLong(), randomByte(), body);
      message.setDestination(new SimpleString("oasoas"));

      message.putStringProperty(new SimpleString("prop1"), new SimpleString("blah1"));
      message.putStringProperty(new SimpleString("prop2"), new SimpleString("blah2"));

      message.setMessageID(81721872);

      ServerMessage message2 = new ServerMessageImpl(message);

      assertMessagesEquivalent(message, message2);

      ServerMessage message3 = message2.copy();

      assertMessagesEquivalent(message2, message3);
    }
  }
  public void testCreateReferencesNonDurable() {
    ServerMessage msg = new ServerMessageImpl();
    msg.setDurable(false);

    Queue queue1 = EasyMock.createStrictMock(Queue.class);
    Queue queue2 = EasyMock.createStrictMock(Queue.class);
    Queue queue3 = EasyMock.createStrictMock(Queue.class);

    EasyMock.replay(queue1, queue2, queue3);

    MessageReference ref1 = msg.createReference(queue1);
    MessageReference ref2 = msg.createReference(queue2);
    MessageReference ref3 = msg.createReference(queue3);

    assertEquals(msg, ref1.getMessage());
    assertEquals(msg, ref2.getMessage());
    assertEquals(msg, ref3.getMessage());

    assertEquals(queue1, ref1.getQueue());
    assertEquals(queue2, ref2.getQueue());
    assertEquals(queue3, ref3.getQueue());

    EasyMock.verify(queue1, queue2, queue3);

    assertEquals(0, msg.getDurableRefCount());
  }
  protected void assertMessagesEquivalent(final Message msg1, final Message msg2) {
    super.assertMessagesEquivalent(msg1, msg2);

    ServerMessage smsg1 = (ServerMessage) msg1;
    ServerMessage smsg2 = (ServerMessage) msg2;

    assertEquals(smsg1.getMessageID(), smsg2.getMessageID());
  }
 public void testGetSetMessageID() {
   ServerMessage msg = (ServerMessage) createMessage();
   final long id = 91829182;
   msg.setMessageID(id);
   assertEquals(id, msg.getMessageID());
 }
 public void testMessageIDConstructor() {
   final long id = 1029812;
   ServerMessage msg = new ServerMessageImpl(id);
   assertEquals(id, msg.getMessageID());
 }
  public void testCreateReferencesDurable() {
    ServerMessage msg = new ServerMessageImpl();
    msg.setDurable(true);

    Queue queue1 = EasyMock.createStrictMock(Queue.class);
    Queue queue2 = EasyMock.createStrictMock(Queue.class);
    Queue queue3 = EasyMock.createStrictMock(Queue.class);

    EasyMock.expect(queue1.isDurable()).andReturn(true);
    EasyMock.expect(queue2.isDurable()).andReturn(true);
    EasyMock.expect(queue3.isDurable()).andReturn(false);

    EasyMock.replay(queue1, queue2, queue3);

    MessageReference ref1 = msg.createReference(queue1);
    MessageReference ref2 = msg.createReference(queue2);
    MessageReference ref3 = msg.createReference(queue3);

    assertEquals(msg, ref1.getMessage());
    assertEquals(msg, ref2.getMessage());
    assertEquals(msg, ref3.getMessage());

    assertEquals(queue1, ref1.getQueue());
    assertEquals(queue2, ref2.getQueue());
    assertEquals(queue3, ref3.getQueue());

    EasyMock.verify(queue1, queue2, queue3);

    assertEquals(2, msg.getDurableRefCount());

    msg.incrementReference(true);
    assertEquals(3, msg.getDurableRefCount());

    msg.incrementReference(true);
    assertEquals(4, msg.getDurableRefCount());

    msg.decrementDurableRefCount();
    assertEquals(3, msg.getDurableRefCount());

    msg.decrementDurableRefCount();
    assertEquals(2, msg.getDurableRefCount());

    msg.decrementDurableRefCount();
    msg.decrementDurableRefCount();
    assertEquals(0, msg.getDurableRefCount());
  }