Package org.glassfish.jersey.server

Examples of org.glassfish.jersey.server.RequestContextBuilder$TestContainerRequest


    @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());
    }
View Full Code Here


    public void testCombinedEncodedOnPostClass() throws ExecutionException, InterruptedException {
        initiateWebApplication(EncodedOnPostClass.class);
        Form form = new Form();
        form.param("f", ":f");
        form.param("f2", ":f2");
        RequestContextBuilder requestBuilder = RequestContextBuilder.from("/%20u/combined;m=%20m?q=%20q",
                "POST").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).entity(form);
        assertEquals("content", apply(requestBuilder.build()).getEntity());
    }
View Full Code Here

    @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", "\u0161"));

        apply(requestBuilder.build());
    }
View Full Code Here

        _test(app, "bar: bar", "POST", new StringWrapperBar("bar"), APPLICATION_BAR, APPLICATION_BAR);
    }

    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());
    }
View Full Code Here

    }

    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());
    }
View Full Code Here

        }
    }

    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());
    }
View Full Code Here

        return (EncodingFilter) new ApplicationHandler(rc).getServiceLocator().getService(ContainerResponseFilter.class);
    }

    private void testEncoding(String expected, String... accepted) throws IOException {
        EncodingFilter filter = initializeAndGetFilter();
        RequestContextBuilder builder = RequestContextBuilder.from("/resource", "GET");
        for (String a : accepted) {
            builder.header(HttpHeaders.ACCEPT_ENCODING, a);
        }
        ContainerRequest request = builder.build();
        ContainerResponse response = new ContainerResponse(request, Response.ok("OK!").build());
        filter.filter(request, response);
        if (response.getStatus() != 200) {
            throw new WebApplicationException(Response.status(response.getStatus()).build());
        }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.server.RequestContextBuilder$TestContainerRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.