MessageFactory { public Message createMessage(String message) { return new Message(message.getBytes()); } protected  MessageFactory(); Message createMessage(String message); Message createMessage(ByteBuffer buffer); static final int MESSAGE_HEADER_SIZE; }
@Test public void testEmptyMessage() throws IOException { Message msgInput = messageFactory.createMessage(""); ByteBuffer rxBuffer = ByteBuffer.allocateDirect(8192); msgInput.encode(rxBuffer); rxBuffer.flip(); Message messageOutpu = messageFactory.createMessage(rxBuffer); assertEquals(messageOutpu, msgInput); }
@Test public void testLongMessage() throws IOException { String message = new StringBuffer() .append("linkset1 dahdi opc=1 apc=2 ni=3 state=UNAVAILABLE\n") .append(" link1 span=1 channelId=1 code=1 state=UNAVAILABLE\n") .append(" link2 span=2 channelId=2 code=3 state=UNAVAILABLE\n").append("\n") .append("linkset2 dahdi opc=123 apc=45678 ni=3 state=UNAVAILABLE\n").toString(); byte[] data = { 0x00, 0x00, 0x01, 0x2a, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x65, 0x74, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x61, 0x68, 0x64, 0x69, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x70, 0x63, 0x3d, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x70, 0x63, 0x3d, 0x32, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x69, 0x3d, 0x33, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x70, 0x61, 0x6e, 0x3d, 0x31, 0x20, 0x20, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x3d, 0x31, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3d, 0x31, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x32, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x70, 0x61, 0x6e, 0x3d, 0x32, 0x20, 0x20, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x3d, 0x32, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3d, 0x33, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x0a, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x65, 0x74, 0x32, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x61, 0x68, 0x64, 0x69, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x70, 0x63, 0x3d, 0x31, 0x32, 0x33, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x61, 0x70, 0x63, 0x3d, 0x34, 0x35, 0x36, 0x37, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x69, 0x3d, 0x33, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3d, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, 0x0a, 0x0a }; ByteBuffer buffer = ByteBuffer.wrap(data); Message msg = messageFactory.createMessage(buffer); for (int i = 0; i < msg.data.length; i++) { assertEquals(data[4 + i], msg.data[i]); } }