Package com.sun.jersey.test.framework

Provides support for testing JAX-RS and Jersey-based applications.

See: Description

Package com.sun.jersey.test.framework Description

Provides support for testing JAX-RS and Jersey-based applications.

The JerseyTest class may be extended to define the testing configuration and functionality.

For example, the following class is configured to use the low-level Grizzly test container factory, com.sun.jersey.test.framework.spi.container.grizzly.GrizzlyTestContainerFactory, and test that a simple resource, TestResource returns the expected results for a GET request.

public class SimpleLowLevelGrizzlyTest extends JerseyTest {

    @Path("root")
    public static class TestResource {
        @GET
        public String get() {
            return "GET";
        }
    }

    public SimpleLowLevelGrizzlyTest() {
        super(new LowLevelAppDescriptor.Builder(TestResource.class).
                contextPath("context").
                build());
    }

    @Override
    protected TestContainerFactory getTestContainerFactory() {
        return new GrizzlyTestContainerFactory();
    }

    @Test
    public void testGet() {
        WebResource r = resource().path("root");

        String s = r.get(String.class);
        Assert.assertEquals("GET", s);
    }
}
 

The following tests the same functionality using the Web-based Grizzly test container factory, com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory.

package foo;

public class WebBasedTest extends JerseyTest {

    @Path("root")
    public static class TestResource {
        @GET
        public String get() {
            return "GET";
        }
    }

    public WebBasedTest() {
        super(new WebAppDescriptor.Builder("foo").
                contextPath("context").
                build());
    }

    @Test
    public void testGet() {
        WebResource r = resource().path("root");

        String s = r.get(String.class);
        Assert.assertEquals("GET", s);
    }
}
 
The above test is actually not specific to any Web-based test container factory and will work for all provided test container factories, however the default factory will be the com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory. See the documentation on JerseyTest for more details on how to set the default test container factory.

Copyright © 2013 Oracle Corporation. All rights reserved.