int value = 1;
for (int prime : primes)
value *= prime;
final AtomicInteger params = new AtomicInteger(1);
ServerParser parser = new ServerParser(new ServerParser.Listener.Adapter()
{
@Override
public void onHeader(int request, HttpField field)
{
Assert.assertEquals(id, request);
switch (field.getName())
{
case shortShortName:
Assert.assertEquals(shortShortValue, field.getValue());
params.set(params.get() * primes[0]);
break;
case shortLongName:
Assert.assertEquals(shortLongValue, field.getValue());
params.set(params.get() * primes[1]);
break;
case longShortName:
Assert.assertEquals(longShortValue, field.getValue());
params.set(params.get() * primes[2]);
break;
default:
Assert.assertEquals(longLongName, field.getName());
Assert.assertEquals(longLongValue, field.getValue());
params.set(params.get() * primes[3]);
break;
}
}
@Override
public void onHeaders(int request)
{
Assert.assertEquals(id, request);
params.set(params.get() * primes[4]);
}
});
for (ByteBuffer buffer : result.getByteBuffers())
{
parser.parse(buffer);
Assert.assertFalse(buffer.hasRemaining());
}
Assert.assertEquals(value, params.get());
// Parse again byte by byte
params.set(1);
for (ByteBuffer buffer : result.getByteBuffers())
{
buffer.flip();
while (buffer.hasRemaining())
parser.parse(ByteBuffer.wrap(new byte[]{buffer.get()}));
Assert.assertFalse(buffer.hasRemaining());
}
Assert.assertEquals(value, params.get());
}