Class SSLJerseyTest
- java.lang.Object
-
- org.smallmind.web.jersey.ssl.SSLJerseyTest
-
public abstract class SSLJerseyTest extends Object
-
-
Constructor Summary
Constructors Constructor Description SSLJerseyTest()Initialize JerseyTest instance.SSLJerseyTest(javax.ws.rs.core.Application jaxrsApplication)Initialize JerseyTest instance.SSLJerseyTest(org.glassfish.jersey.test.spi.TestContainerFactory testContainerFactory)Initialize JerseyTest instance and specify the test container factory to be used by this test.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.ws.rs.client.Clientclient()Get the JAX-RS test client that ispre-configuredfor this test.voidclose(javax.ws.rs.core.Response... responses)Utility method that safely closes a response without throwing an exception.static voidcloseIfNotNull(javax.ws.rs.client.Client... clients)Utility method that safely closes a client instance without throwing an exception.protected javax.ws.rs.core.Applicationconfigure()protected voidconfigureClient(org.glassfish.jersey.client.ClientConfig config)protected org.glassfish.jersey.test.DeploymentContextconfigureDeployment()protected voiddisable(String featureName)Programmatically disable a feature with a given name.protected voidenable(String featureName)Programmatically enable a feature with a given name.protected voidforceDisable(String featureName)Programmatically force-disable a feature with a given name.protected voidforceEnable(String featureName)Programmatically force-enable a feature with a given name.protected voidforceSet(String propertyName, String value)Programmatically force-set a value of a property with a given name.protected URIgetBaseUri()Returns the base URI of the tested application.protected javax.ws.rs.client.ClientgetClient()Get the JAX-RS test client that ispre-configuredfor this test.protected intgetPort()Get the port to be used for test application deployments.protected org.glassfish.jersey.test.spi.TestContainerFactorygetTestContainerFactory()protected booleanisEnabled(String propertyName)Check if the Jersey test boolean property (flag) has been set totrue.protected voidset(String propertyName, Object value)Programmatically set a value of a property with a given name.protected voidset(String propertyName, String value)Programmatically set a value of a property with a given name.protected javax.ws.rs.client.ClientsetClient(javax.ws.rs.client.Client client)Get the old JAX-RS test client and set a new one.voidsetUp()Set up the test by creating a test container instance,startingit and by creating a newpre-configuredtest client.javax.ws.rs.client.WebTargettarget()Create a JAX-RS web target whose URI refers to thebase URIthe tested JAX-RS / Jersey application is deployed at, plus the path specified in thepathargument.javax.ws.rs.client.WebTargettarget(String path)Create a JAX-RS web target whose URI refers to thebase URIthe tested JAX-RS / Jersey application is deployed at, plus the path specified in thepathargument.voidtearDown()Tear down the test bystoppingthe test container obtained from thetest container factoryand byclosingand discarding thepre-configuredtest client that wasset upfor the test.
-
-
-
Constructor Detail
-
SSLJerseyTest
public SSLJerseyTest()
Initialize JerseyTest instance.This constructor can be used from an extending subclass.
When this constructor is used, the extending concrete subclass must implement one of the
configure()orconfigureDeployment()methods to provide the tested application configuration and deployment context.
-
SSLJerseyTest
public SSLJerseyTest(org.glassfish.jersey.test.spi.TestContainerFactory testContainerFactory)
Initialize JerseyTest instance and specify the test container factory to be used by this test.This constructor can be used from an extending subclass.
When this constructor is used, the extending concrete subclass must implement one of the
configure()orconfigureDeployment()methods to provide the tested application configuration and deployment context.- Parameters:
testContainerFactory- the test container factory to use for testing.
-
SSLJerseyTest
public SSLJerseyTest(javax.ws.rs.core.Application jaxrsApplication)
Initialize JerseyTest instance.This constructor can be used from an extending subclass.
When this constructor is used, the extending concrete subclass must implement one of the
configure()orconfigureDeployment()methods are ignored.Please note that when this constructor is used, recording of startup logs as well as configuring other
JerseyTestproperties and features may not work properly. While using this constructor should generally be avoided, in certain scenarios it may be necessary to use this constructor. (E.g. when running parameterized tests in which application is created based on test parameters passed in by JUnit framework via test constructor - in such case it is not possible to propagate the necessary information to one of the overriddenJerseyTest.configure...methods).- Parameters:
jaxrsApplication- tested application.
-
-
Method Detail
-
closeIfNotNull
public static void closeIfNotNull(javax.ws.rs.client.Client... clients)
Utility method that safely closes a client instance without throwing an exception.- Parameters:
clients- client instances to close. Each instance may benull.- Since:
- 2.5
-
enable
protected final void enable(String featureName)
Programmatically enable a feature with a given name. Enabling of the feature may be overridden via a system property.- Parameters:
featureName- name of the enabled feature.
-
disable
protected final void disable(String featureName)
Programmatically disable a feature with a given name. Disabling of the feature may be overridden via a system property.- Parameters:
featureName- name of the disabled feature.
-
forceEnable
protected final void forceEnable(String featureName)
Programmatically force-enable a feature with a given name. Force-enabling of the feature cannot be overridden via a system property. Use with care!- Parameters:
featureName- name of the force-enabled feature.
-
forceDisable
protected final void forceDisable(String featureName)
Programmatically force-disable a feature with a given name. Force-disabling of the feature cannot be overridden via a system property. Use with care!- Parameters:
featureName- name of the force-disabled feature.
-
set
protected final void set(String propertyName, Object value)
Programmatically set a value of a property with a given name. The property value may be overridden via a system property.- Parameters:
propertyName- name of the property.value- property value.
-
set
protected final void set(String propertyName, String value)
Programmatically set a value of a property with a given name. The property value may be overridden via a system property.- Parameters:
propertyName- name of the property.value- property value.
-
forceSet
protected final void forceSet(String propertyName, String value)
Programmatically force-set a value of a property with a given name. The force-set property value cannot be overridden via a system property.- Parameters:
propertyName- name of the property.value- property value.
-
isEnabled
protected final boolean isEnabled(String propertyName)
Check if the Jersey test boolean property (flag) has been set totrue.- Parameters:
propertyName- name of the Jersey test boolean property.- Returns:
trueif the test property has been enabled,falseotherwise.
-
configure
protected javax.ws.rs.core.Application configure()
-
configureDeployment
protected org.glassfish.jersey.test.DeploymentContext configureDeployment()
-
getTestContainerFactory
protected org.glassfish.jersey.test.spi.TestContainerFactory getTestContainerFactory() throws org.glassfish.jersey.test.spi.TestContainerException- Throws:
org.glassfish.jersey.test.spi.TestContainerException
-
target
public final javax.ws.rs.client.WebTarget target()
Create a JAX-RS web target whose URI refers to thebase URIthe tested JAX-RS / Jersey application is deployed at, plus the path specified in thepathargument.This method is an equivalent of calling client().target(getBaseUri()).
- Returns:
- the created JAX-RS web target.
-
target
public final javax.ws.rs.client.WebTarget target(String path)
Create a JAX-RS web target whose URI refers to thebase URIthe tested JAX-RS / Jersey application is deployed at, plus the path specified in thepathargument.This method is an equivalent of calling
target().path(path).- Parameters:
path- relative path (from tested application base URI) this web target should point to.- Returns:
- the created JAX-RS web target.
-
client
public final javax.ws.rs.client.Client client()
Get the JAX-RS test client that ispre-configuredfor this test.- Returns:
- the configured test client.
-
setUp
public void setUp() throws ExceptionSet up the test by creating a test container instance,startingit and by creating a newpre-configuredtest client. The test container is obtained from thetest container factory.- Throws:
org.glassfish.jersey.test.spi.TestContainerException- if the default test container factory cannot be obtained, or the test application deployment context is not supported by the test container factory.Exception- if an exception is thrown during setting up the test environment.
-
tearDown
public void tearDown() throws ExceptionTear down the test bystoppingthe test container obtained from thetest container factoryand byclosingand discarding thepre-configuredtest client that wasset upfor the test.- Throws:
Exception- if an exception is thrown during tearing down the test environment.
-
getClient
protected javax.ws.rs.client.Client getClient()
Get the JAX-RS test client that ispre-configuredfor this test. This method can be overridden.- Returns:
- the configured test client.
-
setClient
protected javax.ws.rs.client.Client setClient(javax.ws.rs.client.Client client)
Get the old JAX-RS test client and set a new one. This method can be overridden.- Parameters:
client- the configured test client.- Returns:
- old configured test client.
-
configureClient
protected void configureClient(org.glassfish.jersey.client.ClientConfig config)
-
getBaseUri
protected URI getBaseUri()
Returns the base URI of the tested application.- Returns:
- the base URI of the tested application.
-
getPort
protected final int getPort()
Get the port to be used for test application deployments.- Returns:
- The HTTP port of the URI
-
close
public final void close(javax.ws.rs.core.Response... responses)
Utility method that safely closes a response without throwing an exception.- Parameters:
responses- responses to close. Each response may benull.- Since:
- 2.5
-
-