use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.
the class TestJsonCustomFilter method testSyncBadJsonGet.
@Test
public void testSyncBadJsonGet() {
HttpFullRequest req = Requests.createBadJsonRequest(KnownHttpMethod.GET, "/json/45");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_400_BADREQUEST);
response.assertContains("{`error`:`invalid json in client request. Unexpected character ('c' (code 99)): was expecting a colon to separate field name and value".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.
the class TestJsonCustomFilter method testSyncJsonPost.
@Test
public void testSyncJsonPost() {
HttpFullRequest req = Requests.createJsonRequest(KnownHttpMethod.POST, "/json/45");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("{`searchTime`:99,`matches`:[`match1`,`match2`]}".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.
the class TestJsonCustomFilter method testNoAttributeValueInJsonGoesToEmptyString.
@Test
public void testNoAttributeValueInJsonGoesToEmptyString() {
// test out "something":null converts to "" in java....
String json = "{ `meta`: { `numResults`: 4 }, `testValidation`:`notBlank` }".replace("`", "\"");
HttpFullRequest req = Requests.createJsonRequest(KnownHttpMethod.POST, "/json/simple", json);
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContentType("application/json");
SearchRequest request = mockSvc.getCachedRequest();
Assert.assertEquals("", request.getQuery());
Assert.assertEquals("", request.getMeta().getExtraField());
}
use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.
the class TestJsonCustomFilter method testAsyncBadJsonPost.
@Test
public void testAsyncBadJsonPost() {
HttpFullRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/json/async/45");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_400_BADREQUEST);
response.assertContains("{`error`:`invalid json in client request. Unexpected character ('c' (code 99)): was expecting a colon to separate field name and value".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.httpclient11.api.HttpFullResponse in project webpieces by deanhiller.
the class TestGetCorsRouting method testGoodHeadersInAllDomains.
@Test
public void testGoodHeadersInAllDomains() {
String fromDomain = "http://from.this.other.domain.com";
List<String> accessHeaders = List.of("Authorization", "Content-Type");
HttpFullRequest req = Requests.createCorsRequest(fromDomain, "/allDomains", accessHeaders, KnownHttpMethod.POST);
XFuture<HttpFullResponse> respFuture = httpsSocket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
Header respDomain = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.ACCESS_CONTROL_ALLOW_ORIGIN);
Assert.assertEquals(fromDomain, respDomain.getValue());
Header varyHeader = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.VARY);
Assert.assertEquals("Origin", varyHeader.getValue());
}
Aggregations