Finished test implementation.

This commit is contained in:
Simone Bordet 2012-02-09 15:47:39 +01:00
parent 2dd0ec003c
commit f1e1113a58
1 changed files with 38 additions and 23 deletions

View File

@ -26,34 +26,26 @@ import org.eclipse.jetty.spdy.frames.SynStreamFrame;
import org.junit.Assert;
import org.junit.Test;
public class ParserTest
public class LiveChromiumRequestParserTest
{
@Test
public void testSynStream() throws Exception
{
// Bytes taken with wireshark from a live chromium request
String data = "" +
"80020001010001c40000000100000000000038eadfa251b262e0666083a41706" +
byte[] bytes1 = toBytes("" +
"800200010100011a0000000100000000000038eadfa251b262e0626083a41706" +
"7bb80b75302cd6ae4017cdcdb12eb435d0b3d4d1d2d702b32c18f850732c036f" +
"68889bae850e44da94811f2d0b3308821ca80375a14e714a72065c0d2cd619f8" +
"52f37443837552f3a076b041628ae1b6a357b01e307681093b37b508a85f0f22" +
"615b0306a505b97a258949b69979401fe7e4582b64651625ea95e4a7a7e7a426" +
"01134d763158334c535e625970666e414e6a3040a98945c919aac62eaa46c640" +
"c1ccf4c492fc22ddb44c60c817e916972681ca2ba0d375338b8b4b53134b4a8a" +
"32934a4b528b75d38bf24b0b548d9c81da92f37373f3f340a91fe493625d608e" +
"cb02a67fa07001b0b4c92b812a863a099b17185840e516031f2871e780985616" +
"0616060c6cb9c0f2323f8581d9dd358481ad1898c57253814a4b4a0a18984151" +
"c9a8cfc085287f18da7df3ab3273721201d237d53350d0883034b456f0c9cc2b" +
"ad50a8b0308b3733d154700446676a786a92776689bea9b1a99ea18286b74788" +
"af8f8e424e6676aa827b6a7276bea6426852695e49a9bea1a19e8189827306b0" +
"50cd2ccdd53734d633d033b730d233318408a6a2080527a6251665424c656087" +
"2637060e582a04000000ffff";
byte[] bytes = new byte[data.length() / 2];
for (int i = 0; i < data.length(); i += 2)
{
String hex = data.substring(i, i + 2);
bytes[i / 2] = (byte)Integer.parseInt(hex, 16);
}
"52f37443837552f3a076b080b234033f28de73404c2b43630b135306b65c6059" +
"929fc2c0ecee1ac2c0560c4c7eb9a940b52525050ccc206f32ea337021f22643" +
"bb6f7e55664e4ea2bea99e81824684a1a135400a3e9979a5150a151666f16626" +
"9a0a8e40afa686a726796796e89b1a9bea992b68787b84f8fae828e46466a72a" +
"b8a72667e76b2a842695e69594ea1b0203d640c1390358e06496e6ea1b9ae901" +
"c3c5d048cfdc1c22988a22149c98965894093195811d1a150c1cb01802000000" +
"ffff");
byte[] bytes2 = toBytes("" +
"800200010100002700000003000000008000428a106660d00ee640e5d14f4b2c" +
"cb0466313d203154c217000000ffff");
final AtomicReference<ControlFrame> frameRef = new AtomicReference<>();
Parser parser = new Parser(new StandardCompressionFactory().newDecompressor());
@ -65,7 +57,7 @@ public class ParserTest
frameRef.set(frame);
}
});
parser.parse(ByteBuffer.wrap(bytes));
parser.parse(ByteBuffer.wrap(bytes1));
ControlFrame frame = frameRef.get();
Assert.assertNotNull(frame);
@ -78,6 +70,29 @@ public class ParserTest
Assert.assertNotNull(synStream.getHeaders());
Assert.assertFalse(synStream.getHeaders().isEmpty());
// TODO: gather bytes for a second identical request to test that compression is working fine
frameRef.set(null);
parser.parse(ByteBuffer.wrap(bytes2));
frame = frameRef.get();
Assert.assertNotNull(frame);
Assert.assertEquals(ControlFrameType.SYN_STREAM, frame.getType());
synStream = (SynStreamFrame)frame;
Assert.assertEquals(2, synStream.getVersion());
Assert.assertEquals(3, synStream.getStreamId());
Assert.assertEquals(0, synStream.getAssociatedStreamId());
Assert.assertEquals(2, synStream.getPriority());
Assert.assertNotNull(synStream.getHeaders());
Assert.assertFalse(synStream.getHeaders().isEmpty());
}
private byte[] toBytes(String hexs)
{
byte[] bytes = new byte[hexs.length() / 2];
for (int i = 0; i < hexs.length(); i += 2)
{
String hex = hexs.substring(i, i + 2);
bytes[i / 2] = (byte)Integer.parseInt(hex, 16);
}
return bytes;
}
}