use of org.webpieces.webserver.test.http2.ResponseWrapperHttp2 in project webpieces by deanhiller.
the class TestKeepContextHttp2 method testSeperationOfMDCFromServer.
@Test
public void testSeperationOfMDCFromServer() {
String mdcKey = "test";
String mdcValue = "value";
// test out "something":null converts to "" in java....
String json = "{ `meta`: { `numResults`: 4 }, `testValidation`:`notBlank` }".replace("`", "\"");
FullRequest req = org.webpieces.webserver.test.http2.Requests.createJsonRequest("POST", "/json/simple", json);
MDC.put(mdcKey, mdcValue);
// not exactly part of this test but checking for leak of server context into client
// (only in embedded modes does this occur)
Assert.assertEquals(0, Context.getContext().size());
XFuture<FullResponse> respFuture = http2Socket.send(req);
ResponseWrapperHttp2 response = ResponseExtract.waitAndWrap(respFuture);
// not exactly part of this test but checking for leak of server context into client
// (only in embedded modes does this occur)
Assert.assertEquals(0, Context.getContext().size());
// validate that MDC was not blown away
Assert.assertEquals(mdcValue, MDC.get(mdcKey));
response.assertStatusCode(StatusCode.HTTP_200_OK);
response.assertContentType("application/json");
}
use of org.webpieces.webserver.test.http2.ResponseWrapperHttp2 in project webpieces by deanhiller.
the class TestKeepContextHttp2 method testNoAttributeValueInJsonGoesToEmptyString.
@Test
public void testNoAttributeValueInJsonGoesToEmptyString() {
String ctxKey = "test2";
String ctxValue = "value2";
String headerKey = "headerKey";
String headerVal = "headerValue";
String requestVal = "testRequestVal";
// test out "something":null converts to "" in java....
String json = "{ `meta`: { `numResults`: 4 }, `testValidation`:`notBlank` }".replace("`", "\"");
FullRequest req = org.webpieces.webserver.test.http2.Requests.createJsonRequest("POST", "/json/simple", json);
Context.put(ctxKey, ctxValue);
// Have to also test request and headers SEPARATELY as test was passing until I added this
Map<String, Object> headerMap = new HashMap<>();
headerMap.put(headerKey, headerVal);
Context.put(Context.REQUEST, requestVal);
Context.put(Context.HEADERS, headerMap);
XFuture<FullResponse> respFuture = http2Socket.send(req);
ResponseWrapperHttp2 response = ResponseExtract.waitAndWrap(respFuture);
// validate that Context was not blown away
Assert.assertEquals(ctxValue, Context.get(ctxKey));
Assert.assertEquals(requestVal, Context.get(Context.REQUEST));
Map<String, Object> headers = (Map<String, Object>) Context.get(Context.HEADERS);
Assert.assertEquals(headerVal, headers.get(headerKey));
response.assertStatusCode(StatusCode.HTTP_200_OK);
response.assertContentType("application/json");
}
use of org.webpieces.webserver.test.http2.ResponseWrapperHttp2 in project webpieces by deanhiller.
the class TestLesson8JsonHttp2 method waitAndTranslateResponse.
private SearchResponse waitAndTranslateResponse(XFuture<FullResponse> respFuture) throws InterruptedException, ExecutionException, TimeoutException, IOException, JsonParseException, JsonMappingException {
ResponseWrapperHttp2 response = ResponseExtract.waitAndWrap(respFuture);
response.assertStatusCode(StatusCode.HTTP_200_OK);
FullResponse fullResponse = respFuture.get(2, TimeUnit.SECONDS);
DataWrapper data2 = fullResponse.getPayload();
byte[] respContent = data2.createByteArray();
return mapper.readValue(respContent, SearchResponse.class);
}
Aggregations