use of org.webpieces.httpparser.api.dto.HttpResponse in project webpieces by deanhiller.
the class TestResponseParsing method testBasic.
@Test
public void testBasic() {
HttpResponseStatus status = new HttpResponseStatus();
status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse response = new HttpResponse();
response.setStatusLine(statusLine);
String result1 = response.toString();
String result2 = parser.marshalToString(response);
String msg = "HTTP/1.1 200 OK\r\n\r\n";
Assert.assertEquals(msg, result1);
Assert.assertEquals(msg, result2);
}
use of org.webpieces.httpparser.api.dto.HttpResponse in project webpieces by deanhiller.
the class TestResponseParsing method createOkResponse.
static HttpResponse createOkResponse() {
Header header1 = new Header();
header1.setName(KnownHeaderName.ACCEPT);
header1.setValue("CooolValue");
Header header2 = new Header();
//let's keep the case even though name is case-insensitive..
header2.setName("CustomerHEADER");
header2.setValue("betterValue");
HttpResponseStatus status = new HttpResponseStatus();
status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse resp = new HttpResponse();
resp.setStatusLine(statusLine);
resp.addHeader(header1);
resp.addHeader(header2);
return resp;
}
use of org.webpieces.httpparser.api.dto.HttpResponse in project webpieces by deanhiller.
the class TestResponseParsing method testWithHeadersAndBody.
@Test
public void testWithHeadersAndBody() {
HttpResponse response = createOkResponse();
String result1 = response.toString();
String result2 = parser.marshalToString(response);
String msg = "HTTP/1.1 200 OK\r\n" + "Accept: CooolValue\r\n" + "CustomerHEADER: betterValue\r\n" + "\r\n";
Assert.assertEquals(msg, result1);
Assert.assertEquals(msg, result2);
}
use of org.webpieces.httpparser.api.dto.HttpResponse in project webpieces by deanhiller.
the class TestResponseParsing method testHalfThenTwoHalvesNext.
/**
* Send in 1/2 first http message and then send in
* next 1/2 AND 1/2 of second message TOGETHER in 2nd
* payload of bytes to make sure it is handled correctly
* and then finally last 1/2
*/
@Test
public void testHalfThenTwoHalvesNext() {
HttpResponse request = createOkResponse();
byte[] payload = unwrap(parser.marshalToByteBuffer(state, request));
byte[] first = new byte[20];
byte[] second = new byte[payload.length];
byte[] third = new byte[payload.length - first.length];
System.arraycopy(payload, 0, first, 0, first.length);
System.arraycopy(payload, first.length, second, 0, payload.length - first.length);
System.arraycopy(payload, 0, second, payload.length - first.length, first.length);
System.arraycopy(payload, first.length, third, 0, third.length);
DataWrapper data1 = dataGen.wrapByteArray(first);
DataWrapper data2 = dataGen.wrapByteArray(second);
DataWrapper data3 = dataGen.wrapByteArray(third);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, data1);
Assert.assertEquals(0, memento.getParsedMessages().size());
memento = parser.parse(memento, data2);
Assert.assertEquals(1, memento.getParsedMessages().size());
memento = parser.parse(memento, data3);
Assert.assertEquals(1, memento.getParsedMessages().size());
}
use of org.webpieces.httpparser.api.dto.HttpResponse in project webpieces by deanhiller.
the class TestResponseParsing method test2AndHalfHttpMessages.
@Test
public void test2AndHalfHttpMessages() {
HttpResponse response = createOkResponse();
byte[] payload = unwrap(parser.marshalToByteBuffer(state, response));
byte[] first = new byte[2 * payload.length + 20];
byte[] second = new byte[payload.length - 20];
System.arraycopy(payload, 0, first, 0, payload.length);
System.arraycopy(payload, 0, first, payload.length, payload.length);
System.arraycopy(payload, 0, first, 2 * payload.length, 20);
System.arraycopy(payload, 20, second, 0, second.length);
DataWrapper data1 = dataGen.wrapByteArray(first);
DataWrapper data2 = dataGen.wrapByteArray(second);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, data1);
Assert.assertEquals(2, memento.getParsedMessages().size());
memento = parser.parse(memento, data2);
Assert.assertEquals(1, memento.getParsedMessages().size());
}
Aggregations