Search in sources :

Example 1 with ApplicationHandler

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

the class ExtendedUriInfoTest method testResourceMethod.

@Test
public void testResourceMethod() throws ExecutionException, InterruptedException {
    final ApplicationHandler applicationHandler = getApplication();
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root", "GET").build()).get();
    assertEquals("root", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 2 with ApplicationHandler

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

the class ExtendedUriInfoTest method testChildResourceMethod.

@Test
public void testChildResourceMethod() throws ExecutionException, InterruptedException {
    final ApplicationHandler applicationHandler = getApplication();
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root/child", "GET").build()).get();
    assertEquals("child", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) Test(org.junit.Test)

Example 3 with ApplicationHandler

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

the class ResponseMediaTypeFromProvidersTest method testSubResource.

@Test
public void testSubResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(AnotherSubResource.class);
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/resource/subresource/sub", "POST").header("Accept", "text/plain").build()).get();
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getHeaderString("Content-Type"), equalTo("text/plain"));
    assertThat((String) response.getEntity(), equalTo("AnotherSubResource"));
}
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 4 with ApplicationHandler

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

the class SubResourceLocatorCachingTest method _test.

private void _test(final String requestUri, final int subResourceCalls, final boolean sleep) throws InterruptedException, ExecutionException {
    final ApplicationHandler applicationHandler = new ApplicationHandler(config);
    ContainerResponse response = null;
    for (int i = 0; i < INVOCATION_COUNT; i++) {
        response = applicationHandler.apply(RequestContextBuilder.from(requestUri, "GET").build()).get();
        if (sleep) {
            Thread.sleep(1100);
        }
    }
    assertThat(response.getStatus(), is(200));
    assertThat((String) response.getEntity(), is("sub"));
    // Test how many times model processors method has been called.
    assertThat(processor.resourceMehtodCalls, is(1));
    assertThat(processor.subresourceMehtodCalls, is(subResourceCalls));
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler)

Example 5 with ApplicationHandler

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

the class SubResourceValidationTest method testDisable.

@Test
public void testDisable() throws ExecutionException, InterruptedException {
    ResourceConfig resourceConfig = new ResourceConfig(RootResource.class);
    resourceConfig.property(ServerProperties.RESOURCE_VALIDATION_DISABLE, "true");
    ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/root/sub", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("get", 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)

Aggregations

ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)163 Test (org.junit.Test)142 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)105 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)99 ApplicationInfoListener (org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener)17 MonitoringEventListener (org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener)17 MBeanExposer (org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer)17 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)12 Response (javax.ws.rs.core.Response)10 MediaType (javax.ws.rs.core.MediaType)8 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)8 MonitoringFeature (org.glassfish.jersey.server.internal.monitoring.MonitoringFeature)6 Resource (org.glassfish.jersey.server.model.Resource)6 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)5 ArrayList (java.util.ArrayList)4 Ignore (org.junit.Ignore)4 IOException (java.io.IOException)3 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)3 Inflector (org.glassfish.jersey.process.Inflector)3 Before (org.junit.Before)3