Search in sources :

Example 1 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class AcceptAnnotatedReaderWriterTest method _test.

private void _test(ApplicationHandler app, String expected, String method, Object entity, String mediaType, String... accept) throws ExecutionException, InterruptedException {
    RequestContextBuilder requestContextBuilder = RequestContextBuilder.from("/", method);
    if (entity != null) {
        requestContextBuilder.entity(entity).type(mediaType);
    }
    ContainerRequest requestContext = requestContextBuilder.accept(accept).build();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ContainerResponse response = app.apply(requestContext, baos).get();
    assertThat(response.getStatus(), equalTo(Response.Status.OK.getStatusCode()));
    assertThat(baos.toString(), equalTo(expected));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder)

Example 2 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class AcceptWriterTest method _test.

private void _test(ApplicationHandler app, String expected, String method, Object entity, String mediaType, String... accept) throws ExecutionException, InterruptedException {
    RequestContextBuilder requestContextBuilder = RequestContextBuilder.from("/", method);
    if (entity != null) {
        requestContextBuilder.entity(entity).type(mediaType);
    }
    ContainerRequest requestContext = requestContextBuilder.accept(accept).build();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    app.apply(requestContext, baos);
    assertEquals(expected, baos.toString());
}
Also used : ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder)

Example 3 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class EncodedParamsTest method testEncodedOnFormParameters.

@Test
public void testEncodedOnFormParameters() throws ExecutionException, InterruptedException {
    initiateWebApplication(EncodedOnFormParameters.class);
    final RequestContextBuilder requestBuilder = RequestContextBuilder.from("/", "POST").type(MediaType.APPLICATION_FORM_URLENCODED).entity(new Form("u", "ลก"));
    apply(requestBuilder.build());
}
Also used : Form(javax.ws.rs.core.Form) RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder) Test(org.junit.Test)

Example 4 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class AbstractTest method getResponseContext.

protected ContainerResponse getResponseContext(String requestUri, String accept, Cookie... cookies) throws ExecutionException, InterruptedException {
    RequestContextBuilder requestBuilder = RequestContextBuilder.from(requestUri, "GET");
    if (accept != null) {
        requestBuilder = requestBuilder.accept(accept);
    }
    requestBuilder = requestBuilder.cookies(cookies);
    return apply(requestBuilder.build());
}
Also used : RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder)

Example 5 with RequestContextBuilder

use of org.glassfish.jersey.server.RequestContextBuilder in project jersey by jersey.

the class EncodedParamsTest method testEncodedOnPostClass.

@Test
public void testEncodedOnPostClass() throws ExecutionException, InterruptedException {
    initiateWebApplication(EncodedOnPostClass.class);
    Form form = new Form();
    form.param("f", ":f");
    RequestContextBuilder requestBuilder = RequestContextBuilder.from("/%20u;m=%20m?q=%20q", "POST").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).entity(form);
    assertEquals("content", apply(requestBuilder.build()).getEntity());
}
Also used : Form(javax.ws.rs.core.Form) RequestContextBuilder(org.glassfish.jersey.server.RequestContextBuilder) Test(org.junit.Test)

Aggregations

RequestContextBuilder (org.glassfish.jersey.server.RequestContextBuilder)7 Form (javax.ws.rs.core.Form)3 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)2 WebApplicationException (javax.ws.rs.WebApplicationException)1