Program: 41731
Project: 41731
Buggy source:
/** 
 * Test that a message received from the test peer with an AmqpValue section containing Binary and no content type is returned as a BytesMessage, verify it gives the expected data values when read, and when sent to the test peer it results in an AMQP message containing a data body section and content type of  {@link AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE}
 */
@Test(timeout=5000) public void testReceiveBytesMessageWithAmqpValueAndResendResultsInData() throws Exception {
  try (TestAmqpPeer testPeer=new TestAmqpPeer(IntegrationTestFixture.PORT)){
    Connection connection=testFixture.establishConnecton(testPeer);
    connection.start();
    testPeer.expectBegin(true);
    Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
    Queue queue=session.createQueue("String_Node_Str");
    boolean myBool=true;
    byte myByte=4;
    byte[] myBytes="String_Node_Str".getBytes();
    char myChar='d';
    double myDouble=1234567890123456789.1234;
    float myFloat=1.1F;
    int myInt=Integer.MAX_VALUE;
    long myLong=Long.MAX_VALUE;
    short myShort=25;
    String myUTF="String_Node_Str";
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    DataOutputStream dos=new DataOutputStream(baos);
    dos.writeBoolean(myBool);
    dos.writeByte(myByte);
    dos.write(myBytes);
    dos.writeChar(myChar);
    dos.writeDouble(myDouble);
    dos.writeFloat(myFloat);
    dos.writeInt(myInt);
    dos.writeLong(myLong);
    dos.writeShort(myShort);
    dos.writeUTF(myUTF);
    byte[] bytesPayload=baos.toByteArray();
    Binary binaryPayload=new Binary(bytesPayload);
    DescribedType amqpValueSectionContent=new AmqpValueDescribedType(binaryPayload);
    testPeer.expectReceiverAttach();
    testPeer.expectLinkFlowRespondWithTransfer(null,null,null,null,amqpValueSectionContent);
    testPeer.expectDispositionThatIsAcceptedAndSettled();
    MessageConsumer messageConsumer=session.createConsumer(queue);
    Message receivedMessage=messageConsumer.receive(1000);
    testPeer.waitForAllHandlersToComplete(3000);
    assertNotNull("String_Node_Str",receivedMessage);
    assertTrue("String_Node_Str",receivedMessage instanceof BytesMessage);
    BytesMessage receivedBytesMessage=(BytesMessage)receivedMessage;
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    assertEquals("String_Node_Str",myByte,receivedBytesMessage.readByte());
    byte[] readBytes=new byte[myBytes.length];
    assertEquals("String_Node_Str",myBytes.length,receivedBytesMessage.readBytes(readBytes));
    assertTrue("String_Node_Str" + Arrays.toString(readBytes),Arrays.equals(myBytes,readBytes));
    assertEquals("String_Node_Str",myChar,receivedBytesMessage.readChar());
    assertEquals("String_Node_Str",myDouble,receivedBytesMessage.readDouble(),0.0);
    assertEquals("String_Node_Str",myFloat,receivedBytesMessage.readFloat(),0.0);
    assertEquals("String_Node_Str",myInt,receivedBytesMessage.readInt());
    assertEquals("String_Node_Str",myLong,receivedBytesMessage.readLong());
    assertEquals("String_Node_Str",myShort,receivedBytesMessage.readShort());
    assertEquals("String_Node_Str",myUTF,receivedBytesMessage.readUTF());
    receivedBytesMessage.reset();
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    testPeer.expectSenderAttach();
    MessageProducer producer=session.createProducer(queue);
    MessageHeaderSectionMatcher headersMatcher=new MessageHeaderSectionMatcher(true);
    MessageAnnotationsSectionMatcher msgAnnotationsMatcher=new MessageAnnotationsSectionMatcher(true);
    msgAnnotationsMatcher.withEntry(Symbol.valueOf(AmqpMessageSupport.JMS_MSG_TYPE),equalTo(AmqpMessageSupport.JMS_BYTES_MESSAGE));
    MessagePropertiesSectionMatcher propsMatcher=new MessagePropertiesSectionMatcher(true);
    propsMatcher.withContentType(equalTo(Symbol.valueOf(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE)));
    TransferPayloadCompositeMatcher messageMatcher=new TransferPayloadCompositeMatcher();
    messageMatcher.setHeadersMatcher(headersMatcher);
    messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
    messageMatcher.setPropertiesMatcher(propsMatcher);
    messageMatcher.setMessageContentMatcher(new EncodedDataMatcher(binaryPayload));
    testPeer.expectTransfer(messageMatcher);
    producer.send(receivedBytesMessage);
    testPeer.waitForAllHandlersToComplete(3000);
  }
 }

Fixed version (ground truth):
/** 
 * Test that a message received from the test peer with an AmqpValue section containing Binary and no content type is returned as a BytesMessage, verify it gives the expected data values when read, and when sent to the test peer it results in an AMQP message containing a data body section and content type of  {@link AmqpMessageSupport#OCTET_STREAM_CONTENT_TYPE}
 */
@Test(timeout=5000) public void testReceiveBytesMessageWithAmqpValueAndResendResultsInData() throws Exception {
  try (TestAmqpPeer testPeer=new TestAmqpPeer(IntegrationTestFixture.PORT)){
    Connection connection=testFixture.establishConnecton(testPeer);
    connection.start();
    testPeer.expectBegin(true);
    Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
    Queue queue=session.createQueue("String_Node_Str");
    boolean myBool=true;
    byte myByte=4;
    byte[] myBytes="String_Node_Str".getBytes();
    char myChar='d';
    double myDouble=1234567890123456789.1234;
    float myFloat=1.1F;
    int myInt=Integer.MAX_VALUE;
    long myLong=Long.MAX_VALUE;
    short myShort=25;
    String myUTF="String_Node_Str";
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    DataOutputStream dos=new DataOutputStream(baos);
    dos.writeBoolean(myBool);
    dos.writeByte(myByte);
    dos.write(myBytes);
    dos.writeChar(myChar);
    dos.writeDouble(myDouble);
    dos.writeFloat(myFloat);
    dos.writeInt(myInt);
    dos.writeLong(myLong);
    dos.writeShort(myShort);
    dos.writeUTF(myUTF);
    byte[] bytesPayload=baos.toByteArray();
    Binary binaryPayload=new Binary(bytesPayload);
    DescribedType amqpValueSectionContent=new AmqpValueDescribedType(binaryPayload);
    testPeer.expectReceiverAttach();
    testPeer.expectLinkFlowRespondWithTransfer(null,null,null,null,amqpValueSectionContent);
    testPeer.expectDispositionThatIsAcceptedAndSettled();
    MessageConsumer messageConsumer=session.createConsumer(queue);
    Message receivedMessage=messageConsumer.receive(1000);
    testPeer.waitForAllHandlersToComplete(3000);
    assertNotNull("String_Node_Str",receivedMessage);
    assertTrue("String_Node_Str",receivedMessage instanceof BytesMessage);
    BytesMessage receivedBytesMessage=(BytesMessage)receivedMessage;
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    assertEquals("String_Node_Str",myByte,receivedBytesMessage.readByte());
    byte[] readBytes=new byte[myBytes.length];
    assertEquals("String_Node_Str",myBytes.length,receivedBytesMessage.readBytes(readBytes));
    assertTrue("String_Node_Str" + Arrays.toString(readBytes),Arrays.equals(myBytes,readBytes));
    assertEquals("String_Node_Str",myChar,receivedBytesMessage.readChar());
    assertEquals("String_Node_Str",myDouble,receivedBytesMessage.readDouble(),0.0);
    assertEquals("String_Node_Str",myFloat,receivedBytesMessage.readFloat(),0.0);
    assertEquals("String_Node_Str",myInt,receivedBytesMessage.readInt());
    assertEquals("String_Node_Str",myLong,receivedBytesMessage.readLong());
    assertEquals("String_Node_Str",myShort,receivedBytesMessage.readShort());
    assertEquals("String_Node_Str",myUTF,receivedBytesMessage.readUTF());
    receivedBytesMessage.reset();
    assertEquals("String_Node_Str",myBool,receivedBytesMessage.readBoolean());
    testPeer.expectSenderAttach();
    MessageProducer producer=session.createProducer(queue);
    MessageHeaderSectionMatcher headersMatcher=new MessageHeaderSectionMatcher(true);
    MessageAnnotationsSectionMatcher msgAnnotationsMatcher=new MessageAnnotationsSectionMatcher(true);
    msgAnnotationsMatcher.withEntry(Symbol.valueOf(AmqpMessageSupport.JMS_MSG_TYPE),equalTo(AmqpMessageSupport.JMS_BYTES_MESSAGE));
    MessagePropertiesSectionMatcher propsMatcher=new MessagePropertiesSectionMatcher(true);
    propsMatcher.withContentType(equalTo(Symbol.valueOf(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE)));
    TransferPayloadCompositeMatcher messageMatcher=new TransferPayloadCompositeMatcher();
    messageMatcher.setHeadersMatcher(headersMatcher);
    messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
    messageMatcher.setPropertiesMatcher(propsMatcher);
    messageMatcher.setMessageContentMatcher(new EncodedDataMatcher(binaryPayload));
    testPeer.expectTransfer(messageMatcher);
    producer.send(receivedBytesMessage);
    testPeer.waitForAllHandlersToComplete(3000);
  }
 }