Class 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.Client client()
      Get the JAX-RS test client that is pre-configured for this test.
      void close​(javax.ws.rs.core.Response... responses)
      Utility method that safely closes a response without throwing an exception.
      static void closeIfNotNull​(javax.ws.rs.client.Client... clients)
      Utility method that safely closes a client instance without throwing an exception.
      protected javax.ws.rs.core.Application configure()  
      protected void configureClient​(org.glassfish.jersey.client.ClientConfig config)  
      protected org.glassfish.jersey.test.DeploymentContext configureDeployment()  
      protected void disable​(String featureName)
      Programmatically disable a feature with a given name.
      protected void enable​(String featureName)
      Programmatically enable a feature with a given name.
      protected void forceDisable​(String featureName)
      Programmatically force-disable a feature with a given name.
      protected void forceEnable​(String featureName)
      Programmatically force-enable a feature with a given name.
      protected void forceSet​(String propertyName, String value)
      Programmatically force-set a value of a property with a given name.
      protected URI getBaseUri()
      Returns the base URI of the tested application.
      protected javax.ws.rs.client.Client getClient()
      Get the JAX-RS test client that is pre-configured for this test.
      protected int getPort()
      Get the port to be used for test application deployments.
      protected org.glassfish.jersey.test.spi.TestContainerFactory getTestContainerFactory()  
      protected boolean isEnabled​(String propertyName)
      Check if the Jersey test boolean property (flag) has been set to true.
      protected void set​(String propertyName, Object value)
      Programmatically set a value of a property with a given name.
      protected void set​(String propertyName, String value)
      Programmatically set a value of a property with a given name.
      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.
      void setUp()
      Set up the test by creating a test container instance, starting it and by creating a new pre-configured test client.
      javax.ws.rs.client.WebTarget target()
      Create a JAX-RS web target whose URI refers to the base URI the tested JAX-RS / Jersey application is deployed at, plus the path specified in the path argument.
      javax.ws.rs.client.WebTarget target​(String path)
      Create a JAX-RS web target whose URI refers to the base URI the tested JAX-RS / Jersey application is deployed at, plus the path specified in the path argument.
      void tearDown()
      Tear down the test by stopping the test container obtained from the test container factory and by closing and discarding the pre-configured test client that was set up for 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() or configureDeployment() 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() or configureDeployment() 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() or configureDeployment() methods are ignored.

        Please note that when this constructor is used, recording of startup logs as well as configuring other JerseyTest properties 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 overridden JerseyTest.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 be null.
        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 to true.
        Parameters:
        propertyName - name of the Jersey test boolean property.
        Returns:
        true if the test property has been enabled, false otherwise.
      • 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 the base URI the tested JAX-RS / Jersey application is deployed at, plus the path specified in the path argument.

        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 the base URI the tested JAX-RS / Jersey application is deployed at, plus the path specified in the path argument.

        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 is pre-configured for this test.
        Returns:
        the configured test client.
      • setUp

        public void setUp()
                   throws Exception
        Set up the test by creating a test container instance, starting it and by creating a new pre-configured test client. The test container is obtained from the test 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 Exception
        Tear down the test by stopping the test container obtained from the test container factory and by closing and discarding the pre-configured test client that was set up for 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 is pre-configured for 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 be null.
        Since:
        2.5