Search in sources :

Example 41 with ContainerResponse

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

the class AcceptTest method testAcceptMultiple.

@Test
public void testAcceptMultiple() throws Exception {
    ApplicationHandler app = createApplication(MultipleResource.class);
    MediaType foo = MediaType.valueOf("application/foo");
    MediaType bar = MediaType.valueOf("application/bar");
    ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept(foo).build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept(bar).build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(bar, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("*/*").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/*").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=0.1", "application/bar").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(bar, response.getMediaType());
    response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=0.5", "application/bar;q=0.1").build()).get();
    assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
    assertEquals("GET", response.getEntity());
    assertEquals(foo, response.getMediaType());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 42 with ContainerResponse

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

the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplate3.

@Test
public void testPathParamOnAmbiguousTemplate3() throws ExecutionException, InterruptedException {
    final ApplicationHandler applicationHandler = new ApplicationHandler(new ResourceConfig(ResourceABC.class, ResourceXYZ.class));
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/uuu", "GET").build()).get();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("abc:uuu", response.getEntity());
}
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 43 with ContainerResponse

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

the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplateTroughSubResourceLocator1.

@Test
public void testPathParamOnAmbiguousTemplateTroughSubResourceLocator1() throws ExecutionException, InterruptedException {
    final ApplicationHandler applicationHandler = new ApplicationHandler(new ResourceConfig(SimpleLocator.class));
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/locator/abc/uuu/a", "GET").build()).get();
    Assert.assertEquals(404, 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 44 with ContainerResponse

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

the class AmbiguousTemplateTest method testGetOnChild.

@Test
public void testGetOnChild() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(ResourceA.class, ResourceB.class, ResourceQ.class);
    ApplicationHandler app = new ApplicationHandler(resourceConfig);
    final ContainerResponse containerResponse = app.apply(RequestContextBuilder.from("/resq/a", "GET").build()).get();
    Assert.assertEquals(200, containerResponse.getStatus());
    Assert.assertEquals("getA", containerResponse.getEntity());
}
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 45 with ContainerResponse

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

the class AmbiguousTemplateTest method testOptionsOnRoot.

@Test
public void testOptionsOnRoot() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(ResourceA.class, ResourceB.class, ResourceQ.class);
    ApplicationHandler app = new ApplicationHandler(resourceConfig);
    final ContainerResponse containerResponse = app.apply(RequestContextBuilder.from("/aaa", "OPTIONS").accept(MediaType.TEXT_PLAIN).build()).get();
    Assert.assertEquals(200, containerResponse.getStatus());
    final List<String> methods = Arrays.asList(containerResponse.getEntity().toString().split(", "));
    assertThat(methods, hasItems("POST", "GET", "OPTIONS", "HEAD"));
    assertThat(methods.size(), is(4));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) 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