@Test
public void testMessageDecoding() throws Exception {

    byte[] CONTENTS = new byte[MESSAGE_SIZE];
    for (int i = 0; i < MESSAGE_SIZE; i++) {
        CONTENTS[i] = 'a';
    }
    PUBLISH publish = new PUBLISH();
    publish.dup(false);
    publish.messageId((short) 127);
    publish.qos(QoS.AT_LEAST_ONCE);
    publish.payload(new Buffer(CONTENTS));
    publish.topicName(new UTF8Buffer("TOPIC"));
    DataByteArrayOutputStream output = new DataByteArrayOutputStream();
    wireFormat.marshal(publish.encode(), output);
    Buffer marshalled = output.toBuffer();
    DataByteArrayInputStream input = new DataByteArrayInputStream(marshalled);
    codec.parse(input, marshalled.length());
    assertTrue(!frames.isEmpty());
    assertEquals(1, frames.size());
    publish = new PUBLISH().decode(frames.get(0));
    assertFalse(publish.dup());
    assertEquals(MESSAGE_SIZE, publish.payload().length());
}