}
@Test
public void testEncodeSmallBuffer() throws Exception
{
DiameterAnswer answer = new DiameterAnswer();
answer.setCommand(Sh.UDA);
AVPList l = new AVPList();
answer.setAVPList(l);
answer.setResultCode(Common.DIAMETER_SUCCESS);
answer.setEndToEndId(33);
answer.setHopByHopId(51648);
l.add(Common.DIAMETER_SUCCESS.getAVP());
l.add(new AVP<String>(Common.ORIGIN_HOST, "cipango.org"));
l.add(new AVP<InetAddress>(Common.HOST_IP_ADDRESS, InetAddress.getLocalHost()));
l.add(new AVP<Integer>(Common.FIRMWARE_REVISION, 2));
l.add(new AVP<byte[]>(Sh.USER_DATA, "<shData>dasaiTag<shData>".getBytes()));
for (int i = 24; i < 256; i++)
{
Buffer buffer = new ByteArrayBuffer(i);
buffer = Codecs.__message.encode(buffer, answer);
// System.out.println(buffer.putIndex() + " / " + i);
DiameterMessage message = Codecs.__message.decode(buffer);
// System.out.println(message);
assertFalse(message.isRequest());
assertEquals(answer.getEndToEndId(), message.getEndToEndId());
assertEquals(answer.getHopByHopId(), message.getHopByHopId());
assertEquals(Sh.UDA, message.getCommand());
assertEquals(Common.DIAMETER_SUCCESS.getCode(), message.get(Common.RESULT_CODE).intValue());
assertEquals(InetAddress.getLocalHost(), message.get(Common.HOST_IP_ADDRESS));
assertEquals("<shData>dasaiTag<shData>", new String(message.get(Sh.USER_DATA)));
}