use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class FullResponse method assertContentType.
public void assertContentType(String mimeType) {
Header type = getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_TYPE);
String value = type.getValue();
if (!mimeType.equals(value))
throw new IllegalStateException("Expected mimeType=" + mimeType + " but found type=" + value);
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class TestFlashAndSelect method testMultiSelectSingleSelection.
@Test
public void testMultiSelectSingleSelection() {
HttpDummyRequest req1 = Requests.createPostRequest("/multiselect", "entity.id", user.getId() + "", //invalid first name
"entity.firstName", //invalid first name
"NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "", "selectedRoles", "j");
http11Socket.send(req1);
FullResponse response1 = ResponseExtract.assertSingleResponse(http11Socket);
response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
String urlPath = "/multiselect/" + user.getId();
Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
Header cookieHeader = response1.createCookieRequestHeader();
req.addHeader(cookieHeader);
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("<option value=`b` >Badass</script>".replace('`', '\"'));
response.assertContains("<option value=`j` selected=`selected`>Jerk</script>".replace('`', '\"'));
response.assertContains("<option value=`d` >Delinquint</script>".replace('`', '\"'));
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class TestAsyncHibernate method saveBean.
private String saveBean(String path) {
HttpRequest req = Requests.createRequest(KnownHttpMethod.POST, path);
http11Socket.send(req);
List<FullResponse> responses1 = http11Socket.getResponses();
Assert.assertEquals(0, responses1.size());
List<Runnable> runnables = mockExecutor.getRunnablesScheduled();
runnables.get(0).run();
mockExecutor.clear();
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
Header header = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.LOCATION);
String url = header.getValue();
return url;
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class Requests method createJsonRequest.
public static HttpDummyRequest createJsonRequest(KnownHttpMethod method, String url) {
HttpRequest request = createRequest(method, url);
String json = "{ `query`: `cats and dogs`, `meta`: { `numResults`: 4 } }".replace("`", "\"");
DataWrapper body = gen.wrapByteArray(json.getBytes());
HttpData data = new HttpData(body, true);
request.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
return new HttpDummyRequest(request, data);
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class Requests method createRequest.
public static HttpRequest createRequest(KnownHttpMethod method, String url, Integer port) {
HttpUri httpUri = new HttpUri(url);
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(method);
requestLine.setUri(httpUri);
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
if (port == null)
req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
else
req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com:" + port));
return req;
}
Aggregations