Search in sources :

Example 51 with ContainerResponse

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

the class ResourceInfoTest method testInfoGet.

@Test
public void testInfoGet() throws ExecutionException, InterruptedException {
    ApplicationHandler handler = getApplication();
    final ContainerResponse response = handler.apply(RequestContextBuilder.from("/info", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("get-info", response.getEntity());
    assertResponseHeaders(response, "ResourceTestingInfo", "getInfo");
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 52 with ContainerResponse

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

the class ParamConverterInternalTest method testLazyConverter.

@Test
public void testLazyConverter() throws Exception {
    final ApplicationHandler application = new ApplicationHandler(new ResourceConfig(MyLazyParamProvider.class, Resource.class));
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
    assertEquals(400, response.getStatus());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 53 with ContainerResponse

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

the class ParamExceptionMappingTest method testURIParamException.

@Test
public void testURIParamException() throws ExecutionException, InterruptedException {
    initiateWebApplication(ParamExceptionMapperResource.class, UriExceptionMapper.class);
    ContainerResponse responseContext = getResponseContext(UriBuilder.fromPath("/").path("path/ 123").build().toString());
    assertEquals("uri", responseContext.getEntity());
    responseContext = getResponseContext(UriBuilder.fromPath("/").path("matrix;x= 123").build().toString());
    assertEquals("uri", responseContext.getEntity());
    responseContext = getResponseContext(UriBuilder.fromPath("/").path("query").queryParam("x", " 123").build().toString());
    assertEquals("uri", responseContext.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Test(org.junit.Test)

Example 54 with ContainerResponse

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

the class ParamExceptionMappingTest method testGeneralParamException.

@Test
public void testGeneralParamException() throws ExecutionException, InterruptedException {
    initiateWebApplication(ParamExceptionMapperResource.class, ParamExceptionMapper.class);
    ContainerResponse responseContext = getResponseContext(UriBuilder.fromPath("/").path("path/ 123").build().toString());
    assertEquals("param", responseContext.getEntity());
    responseContext = getResponseContext(UriBuilder.fromPath("/").path("matrix;x= 123").build().toString());
    assertEquals("param", responseContext.getEntity());
    responseContext = getResponseContext(UriBuilder.fromPath("/").path("query").queryParam("x", " 123").build().toString());
    assertEquals("param", responseContext.getEntity());
    responseContext = getResponseContext(UriBuilder.fromPath("/").path("cookie").build().toString(), new Cookie("x", " 123"));
    assertEquals("param", responseContext.getEntity());
    responseContext = apply(RequestContextBuilder.from("/header", "GET").header("x", " 123").build());
    assertEquals("param", responseContext.getEntity());
    Form f = new Form();
    f.param("x", " 123");
    responseContext = apply(RequestContextBuilder.from("/form", "POST").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).entity(f).build());
    assertEquals("param", responseContext.getEntity());
}
Also used : Cookie(javax.ws.rs.core.Cookie) ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Form(javax.ws.rs.core.Form) Test(org.junit.Test)

Example 55 with ContainerResponse

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

the class PathParamAsPrimitiveTest method testBadPrimitiveValue.

@Test
public void testBadPrimitiveValue() throws Exception {
    ContainerResponse responseContext = app.apply(RequestContextBuilder.from("/int/abcdef", "GET").build()).get();
    assertEquals(404, responseContext.getStatus());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Test(org.junit.Test)

Aggregations

ContainerResponse (org.glassfish.jersey.server.ContainerResponse)211 Test (org.junit.Test)190 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)95 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)58 MediaType (javax.ws.rs.core.MediaType)16 Form (javax.ws.rs.core.Form)14 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)14 Cookie (javax.ws.rs.core.Cookie)7 Response (javax.ws.rs.core.Response)5 Ignore (org.junit.Ignore)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)2 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)2 ContainerException (org.glassfish.jersey.server.ContainerException)2 RequestContextBuilder (org.glassfish.jersey.server.RequestContextBuilder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1