|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.jersey.test.framework.JerseyTest
public abstract class JerseyTest
An abstract JUnit 4.x-based unit test class for testing JAX-RS and Jersey-based applications.
At construction this class will obtain a test container factory, of type
TestContainerFactory
, and use that to obtain a configured test
container, of type TestContainer
.
Before a test method, in an extending class, is run the
TestContainer.start()
method is invoked. After the test method has
run the TestContainer.stop()
method is invoked.
The test method can invoke the resource()
to obtain a
WebResource
from which requests may be sent to and responses recieved
from the Web application under test.
If a test container factory is not explictly declared using the appropriate
constructor (see JerseyTest(TestContainerFactory)
) then a default
test container factory will be obtained as follows.
If the system property jersey.test.containerFactory is set and the
value is a fully qualified class name of a class that extends from
TestContainerFactory
then the default test container factory will
be an instance of that class. The exception TestContainerException
will be thrown if the class cannot be loaded or instantiated.
If the system property jersey.test.containerFactory is not set then
the default test container factory will be an instance of
GrizzlyWebTestContainerFactory
.
The exception TestContainerException
will be thrown if this class
cannot be loaded or instantiated.
The test container is configured from an application descriptor, of type
AppDescriptor
. The exception TestContainerException
will be thrown if the test container cannot support the application
descriptor.
An application descriptor is built from an application descriptor builder.
Two application descriptor builders are provided:
LowLevelAppDescriptor.Builder
,
compatible with low-level test containers that do not support Servlets.WebAppDescriptor.Builder
,
compatible with web-based test containers that support Servlets.WebAppDescriptor
may be
transformed to an application descriptor of type LowLevelAppDescriptor
if the state of the former is compatible with a low-level description.
The following low-level test container factories are provided:
GrizzlyTestContainerFactory
for testing with the low-level
Grizzly HTTP container.HTTPContainerFactory
for testing with the Light Weight HTTP
server distributed with Java SE 6.InMemoryTestContainerFactory
for testing in memory without
using underlying HTTP client and server side functionality
to send requests and receive responses.GrizzlyWebTestContainerFactory
for testing with the Grizzly
Web container and Servlet support.EmbeddedGlassFishTestContainerFactory
for testing with
embedded GlassFish.ExternalTestContainerFactory
for testing when the Web
application is independently deployed in a separate JVM to that of the
tests. For example, the application may be deployed to the
Glassfish v2 or v3 application server.
Constructor Summary | |
---|---|
JerseyTest()
An extending class must implement the configure() method to
provide an application descriptor. |
|
JerseyTest(AppDescriptor ad)
Construct a new instance with an application descriptor that defines how the test container is configured. |
|
JerseyTest(String... packages)
Construct a new instance with an array or a colon separated list of package names which contain resource and provider classes. |
|
JerseyTest(TestContainerFactory testContainerFactory)
Contruct a new instance with a test container factory. |
Method Summary | |
---|---|
Client |
client()
Get the client that is configured for this test. |
protected AppDescriptor |
configure()
Return an application descriptor that defines how the test container is configured. |
protected URI |
getBaseURI()
Returns the base URI of the application. |
protected int |
getPort(int defaultPort)
Returns the port to be used in the base URI. |
protected TestContainerFactory |
getTestContainerFactory()
Get the test container factory. |
WebResource |
resource()
Create a web resource whose URI refers to the base URI the Web application is deployed at. |
protected void |
setTestContainerFactory(TestContainerFactory testContainerFactory)
Sets the test container factory to to be used for testing. |
void |
setUp()
Set up the test by invoking TestContainer.start() on
the test container obtained from the test container factory. |
void |
tearDown()
Tear down the test by invoking TestContainer.stop() on
the test container obtained from the test container factory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JerseyTest() throws TestContainerException
configure()
method to
provide an application descriptor.
TestContainerException
- if the default test container factory
cannot be obtained, or the application descriptor is not
supported by the test container factory.public JerseyTest(TestContainerFactory testContainerFactory)
An extending class must implement the configure()
method to
provide an application descriptor.
testContainerFactory
- the test container factory to use for testing.
TestContainerException
- if the application descriptor is not
supported by the test container factory.public JerseyTest(AppDescriptor ad) throws TestContainerException
ad
- an application descriptor describing how to configure the
test container.
TestContainerException
- if the default test container factory
cannot be obtained, or the application descriptor is not
supported by the test container factory.public JerseyTest(String... packages) throws TestContainerException
This contructor builds an instance of WebAppDescriptor
passing
the package names to the constructor.
packages
- array or a colon separated list of package names which
contain resource and provider classes.
TestContainerException
- if the default test container factory
cannot be obtained, or the built application descriptor is not
supported by the test container factory.Method Detail |
---|
protected AppDescriptor configure()
If a constructor is utilized that does not supply an application
descriptor then this method must be overriden to return an application
descriptor, otherwise an UnsupportedOperationException
exception
will be thrown.
If a constructor is utilized that does supply an application descriptor then this method does not require to be overridden and will not be invoked.
protected void setTestContainerFactory(TestContainerFactory testContainerFactory)
testContainerFactory
- the test container factory to to be used for
testing.protected TestContainerFactory getTestContainerFactory() throws TestContainerException
If the test container factory has not been explicit set with
setTestContainerFactory(TestContainerFactory)
then
the default test container factory will be obtained.
If the system property jersey.test.containerFactory is set and the
value is a fully qualified class name of a class that extends from
TestContainerFactory
then the default test container factory will
be an instance of that class. The exception TestContainerException
will be thrown if the class cannot be loaded or instantiated.
If the system property jersey.test.containerFactory is not set then
the default test container factory will be an instance of
GrizzlyWebTestContainerFactory
.
The exception TestContainerException
will be thrown if this class
cannot be loaded or instantiated.
TestContainerException
- if the default test container factory
cannot be obtained.public WebResource resource()
public Client client()
public void setUp() throws Exception
TestContainer.start()
on
the test container obtained from the test container factory.
Exception
public void tearDown() throws Exception
TestContainer.stop()
on
the test container obtained from the test container factory.
Exception
protected URI getBaseURI()
protected int getPort(int defaultPort)
defaultPort
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |