Search in sources :

Example 31 with ContainerResponse

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

the class OptionsSubResourceMethodTest method testNoOptionsDifferentSub.

@Test
public void testNoOptionsDifferentSub() throws Exception {
    initiateWebApplication(ResourceNoOptionsDifferentSub.class);
    ContainerResponse response = app.apply(RequestContextBuilder.from("/sub1", "OPTIONS").build()).get();
    assertEquals(200, response.getStatus());
    String allow = response.getHeaderString("Allow");
    assertTrue(allow.contains("OPTIONS"));
    assertTrue(allow.contains("GET"));
    assertFalse(allow.contains("PUT"));
    response = app.apply(RequestContextBuilder.from("/sub2", "OPTIONS").build()).get();
    assertEquals(200, response.getStatus());
    allow = response.getHeaderString("Allow");
    assertTrue(allow.contains("OPTIONS"));
    assertTrue(allow.contains("PUT"));
    assertFalse(allow.contains("GET"));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Test(org.junit.Test)

Example 32 with ContainerResponse

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

the class OptionsSubResourceMethodTest method testWithOptions.

@Test
public void testWithOptions() throws Exception {
    initiateWebApplication(ResourceWithOptions.class);
    ContainerResponse response = app.apply(RequestContextBuilder.from("/sub", "OPTIONS").build()).get();
    assertEquals(200, response.getStatus());
    String allow = response.getHeaderString("Allow");
    assertTrue(allow.contains("OPTIONS"));
    assertTrue(allow.contains("GET"));
    assertTrue(allow.contains("PUT"));
    assertTrue(allow.contains("POST"));
    assertTrue(allow.contains("DELETE"));
    assertTrue(allow.contains("PATCH"));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Test(org.junit.Test)

Example 33 with ContainerResponse

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

the class OptionsTest method testWithOptions.

@Test
public void testWithOptions() throws Exception {
    initiateWebApplication(ResourceWithOptions.class);
    ContainerResponse response = app.apply(RequestContextBuilder.from("/", "OPTIONS").build()).get();
    assertEquals(200, response.getStatus());
    String allow = response.getHeaderString("Allow");
    assertTrue(allow.contains("OPTIONS"));
    assertTrue(allow.contains("GET"));
    assertTrue(allow.contains("PUT"));
    assertTrue(allow.contains("POST"));
    assertTrue(allow.contains("DELETE"));
    assertTrue(allow.contains("PATCH"));
    assertEquals("OVERRIDE", response.getHeaderString("X-TEST"));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Test(org.junit.Test)

Example 34 with ContainerResponse

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

the class OptionsTest method testOptions.

private ContainerResponse testOptions(MediaType requestType, ApplicationHandler application, String path) throws InterruptedException, ExecutionException {
    final ContainerRequest request = RequestContextBuilder.from(path, "OPTIONS").accept(requestType).build();
    final ContainerResponse response = application.apply(request).get();
    Assert.assertEquals(200, response.getStatus());
    final MediaType type = response.getMediaType();
    Assert.assertEquals(requestType, type);
    return response;
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) MediaType(javax.ws.rs.core.MediaType) ContainerRequest(org.glassfish.jersey.server.ContainerRequest)

Example 35 with ContainerResponse

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

the class OptionsTest method testNoHeadInSub.

@Test
public void testNoHeadInSub() throws ExecutionException, InterruptedException {
    ApplicationHandler application = new ApplicationHandler(new ResourceConfig(ResourceWithoutGetMethod.class));
    final MediaType requestType = MediaType.TEXT_PLAIN_TYPE;
    final ContainerResponse response = testOptions(requestType, application, "/no-get/sub");
    Assert.assertFalse(((String) response.getEntity()).contains("HEAD"));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) MediaType(javax.ws.rs.core.MediaType) 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