Search in sources :

Example 61 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class HttpParserTest method testTransferEncodingChunkedThenContentLength.

@Test
public void testTransferEncodingChunkedThenContentLength() {
    ByteBuffer buffer = BufferUtil.toBuffer("POST /chunk HTTP/1.1\r\n" + "Host: localhost\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Length: 1\r\n" + "\r\n" + "1\r\n" + "X\r\n" + "0\r\n" + "\r\n");
    HttpParser.RequestHandler handler = new Handler();
    HttpParser parser = new HttpParser(handler);
    parseAll(parser, buffer);
    Assert.assertEquals("POST", _methodOrVersion);
    Assert.assertEquals("/chunk", _uriOrStatus);
    Assert.assertEquals("HTTP/1.1", _versionOrReason);
    Assert.assertEquals("X", _content);
    Assert.assertTrue(_headerCompleted);
    Assert.assertTrue(_messageCompleted);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 62 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class HttpParserTest method testChunkParseNoTrailer.

@Test
public void testChunkParseNoTrailer() throws Exception {
    ByteBuffer buffer = BufferUtil.toBuffer("GET /chunk HTTP/1.0\r\n" + "Header1: value1\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "a;\r\n" + "0123456789\r\n" + "1a\r\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + "0\r\n");
    HttpParser.RequestHandler handler = new Handler();
    HttpParser parser = new HttpParser(handler);
    parseAll(parser, buffer);
    parser.atEOF();
    parser.parseNext(BufferUtil.EMPTY_BUFFER);
    Assert.assertEquals("GET", _methodOrVersion);
    Assert.assertEquals("/chunk", _uriOrStatus);
    Assert.assertEquals("HTTP/1.0", _versionOrReason);
    Assert.assertEquals(1, _headers);
    Assert.assertEquals("Header1", _hdr[0]);
    Assert.assertEquals("value1", _val[0]);
    Assert.assertEquals("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", _content);
    Assert.assertTrue(_headerCompleted);
    Assert.assertTrue(_messageCompleted);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 63 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class HttpParserTest method testNoURI2.

@Test
public void testNoURI2() throws Exception {
    ByteBuffer buffer = BufferUtil.toBuffer("GET \r\n" + "Content-Length: 0\r\n" + "Connection: close\r\n" + "\r\n");
    HttpParser.RequestHandler handler = new Handler();
    HttpParser parser = new HttpParser(handler);
    parser.parseNext(buffer);
    Assert.assertEquals(null, _methodOrVersion);
    Assert.assertEquals("No URI", _bad);
    Assert.assertFalse(buffer.hasRemaining());
    Assert.assertEquals(HttpParser.State.CLOSE, parser.getState());
    parser.atEOF();
    parser.parseNext(BufferUtil.EMPTY_BUFFER);
    Assert.assertEquals(HttpParser.State.CLOSED, parser.getState());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 64 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class HttpParserTest method testDuplicateContentLengthWithLargerThenCorrectValue.

@Test
public void testDuplicateContentLengthWithLargerThenCorrectValue() {
    ByteBuffer buffer = BufferUtil.toBuffer("POST / HTTP/1.1\r\n" + "Content-Length: 2\r\n" + "Content-Length: 1\r\n" + "Connection: close\r\n" + "\r\n" + "X");
    HttpParser.RequestHandler handler = new Handler();
    HttpParser parser = new HttpParser(handler);
    parser.parseNext(buffer);
    Assert.assertEquals("POST", _methodOrVersion);
    Assert.assertEquals("Duplicate Content-Length", _bad);
    Assert.assertFalse(buffer.hasRemaining());
    Assert.assertEquals(HttpParser.State.CLOSE, parser.getState());
    parser.atEOF();
    parser.parseNext(BufferUtil.EMPTY_BUFFER);
    Assert.assertEquals(HttpParser.State.CLOSED, parser.getState());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 65 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class HttpParserTest method testChunkParseTrailer.

@Test
public void testChunkParseTrailer() throws Exception {
    ByteBuffer buffer = BufferUtil.toBuffer("GET /chunk HTTP/1.0\r\n" + "Header1: value1\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "a;\r\n" + "0123456789\r\n" + "1a\r\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + "0\r\n" + "Trailer: value\r\n" + "\r\n");
    HttpParser.RequestHandler handler = new Handler();
    HttpParser parser = new HttpParser(handler);
    parseAll(parser, buffer);
    Assert.assertEquals("GET", _methodOrVersion);
    Assert.assertEquals("/chunk", _uriOrStatus);
    Assert.assertEquals("HTTP/1.0", _versionOrReason);
    Assert.assertEquals(1, _headers);
    Assert.assertEquals("Header1", _hdr[0]);
    Assert.assertEquals("value1", _val[0]);
    Assert.assertEquals("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", _content);
    Assert.assertEquals(1, _trailers.size());
    HttpField trailer1 = _trailers.get(0);
    Assert.assertEquals("Trailer", trailer1.getName());
    Assert.assertEquals("value", trailer1.getValue());
    Assert.assertTrue(_headerCompleted);
    Assert.assertTrue(_messageCompleted);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)597324 ArrayList (java.util.ArrayList)32672 QuickTest (com.hazelcast.test.annotation.QuickTest)27910 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)25464 File (java.io.File)24462 HashMap (java.util.HashMap)21030 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)19416 List (java.util.List)16717 IOException (java.io.IOException)13352 Map (java.util.Map)9238 Date (java.util.Date)9014 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8368 InputStream (java.io.InputStream)7753 Properties (java.util.Properties)7445 CountDownLatch (java.util.concurrent.CountDownLatch)7403 ByteArrayInputStream (java.io.ByteArrayInputStream)7401 HashSet (java.util.HashSet)7165 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6707 Response (javax.ws.rs.core.Response)6154 Ignore (org.junit.Ignore)5936