Search in sources :

Example 6 with ResourceConfig

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

the class PathAndResourceMethodErrorsTest method testConflictingRootResourceErrors2.

@Test
@Ignore
public // TODO add cross-resource validation & un-ignore the test
void testConflictingRootResourceErrors2() {
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.registerResources(Resource.builder(PathErrorsOneResource.class).path("/{one}").build());
    resourceConfig.registerResources(Resource.builder(PathErrorsThreeResource.class).path("/{one}/").build());
    assertEquals(1, initiateWebApplication(resourceConfig));
}
Also used : ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with ResourceConfig

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

the class PathAndResourceMethodErrorsTest method testConflictingRootResourceErrors.

@Test
@Ignore
public // TODO add cross-resource validation & un-ignore the test
void testConflictingRootResourceErrors() {
    ResourceConfig resourceConfig = new ResourceConfig(PathErrorsOneResource.class, PathErrorsTwoResource.class, PathErrorsThreeResource.class);
    resourceConfig.registerResources(Resource.builder(PathErrorsOneResource.class).path("/{four}").build());
    resourceConfig.registerResources(Resource.builder(PathErrorsThreeResource.class).path("/{five}").build());
    assertEquals(4, initiateWebApplication(resourceConfig));
}
Also used : ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with ResourceConfig

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

the class ProgrammaticResourceMethodsTest method testGet.

@Test
public void testGet() throws Exception {
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("test");
    resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.ok().build();
        }
    });
    rc.registerResources(resourceBuilder.build());
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatus(RequestContextBuilder.from("/test", "GET").build(), application);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 9 with ResourceConfig

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

the class ProgrammaticResourceMethodsTest method testTwoBindersSamePath.

@Test
public void testTwoBindersSamePath() throws Exception {
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("/");
    final Resource.Builder childTest1Builder = resourceBuilder.addChildResource("test1");
    childTest1Builder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.created(URI.create("/foo")).build();
        }
    });
    Inflector<ContainerRequestContext, Response> inflector1 = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.accepted().build();
        }
    };
    final Resource.Builder childTest2Builder = resourceBuilder.addChildResource("test2");
    childTest2Builder.addMethod("GET").handledBy(inflector1);
    childTest2Builder.addMethod("HEAD").handledBy(inflector1);
    Inflector<ContainerRequestContext, Response> inflector2 = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.status(203).build();
        }
    };
    childTest1Builder.addMethod("OPTIONS").handledBy(inflector2);
    childTest1Builder.addMethod("HEAD").handledBy(inflector2);
    final Resource resource = resourceBuilder.build();
    rc.registerResources(resource);
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatusEquals(201, RequestContextBuilder.from("/test1", "GET").build(), application);
//        checkReturnedStatusEquals(203, Requests.from("/test1", "HEAD").build(), application);
//        checkReturnedStatusEquals(203, Requests.from("/test1", "OPTIONS").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "GET").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "HEAD").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "OPTIONS").build(), application);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inflector(org.glassfish.jersey.process.Inflector) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 10 with ResourceConfig

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

the class DynamicFeatureTest method testInjectedConfigurable.

@Test
public void testInjectedConfigurable() throws Exception {
    final ResourceConfig resourceConfig = getTestResourceConfig(InjectConfigurableDynamicFeature.class);
    resourceConfig.property("hello", "world");
    final ApplicationHandler application = createApplication(resourceConfig);
    assertNull(application.getConfiguration().getProperty("foo"));
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals("get", response.getEntity());
    assertNull(application.getConfiguration().getProperty("foo"));
    assertEquals("world", application.getConfiguration().getProperty("hello"));
}
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

ResourceConfig (org.glassfish.jersey.server.ResourceConfig)358 Test (org.junit.Test)135 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)105 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)62 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)33 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)29 Response (javax.ws.rs.core.Response)28 HttpServer (org.glassfish.grizzly.http.server.HttpServer)28 URI (java.net.URI)24 Resource (org.glassfish.jersey.server.model.Resource)24 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)23 IOException (java.io.IOException)22 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)22 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)17 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 MetricRegistry (com.codahale.metrics.MetricRegistry)15 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)15