Search in sources :

Example 1 with ResponseWrapperHttp2

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");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) FullResponse(org.webpieces.http2client.api.dto.FullResponse) ResponseWrapperHttp2(org.webpieces.webserver.test.http2.ResponseWrapperHttp2) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) FullRequest(org.webpieces.http2client.api.dto.FullRequest) AbstractHttp2Test(org.webpieces.webserver.test.http2.AbstractHttp2Test) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 2 with ResponseWrapperHttp2

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");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) FullResponse(org.webpieces.http2client.api.dto.FullResponse) ResponseWrapperHttp2(org.webpieces.webserver.test.http2.ResponseWrapperHttp2) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) FullRequest(org.webpieces.http2client.api.dto.FullRequest) AbstractHttp2Test(org.webpieces.webserver.test.http2.AbstractHttp2Test) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 3 with ResponseWrapperHttp2

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ResponseWrapperHttp2(org.webpieces.webserver.test.http2.ResponseWrapperHttp2) FullResponse(org.webpieces.http2client.api.dto.FullResponse)

Aggregations

FullResponse (org.webpieces.http2client.api.dto.FullResponse)3 ResponseWrapperHttp2 (org.webpieces.webserver.test.http2.ResponseWrapperHttp2)3 Test (org.junit.Test)2 FullRequest (org.webpieces.http2client.api.dto.FullRequest)2 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)2 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)2 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)2 AbstractHttp2Test (org.webpieces.webserver.test.http2.AbstractHttp2Test)2 DataWrapper (org.webpieces.data.api.DataWrapper)1