Class OnlineTestSupport

Object
OnlineTestSupport

public abstract class OnlineTestSupport extends Object
JUnit 4 test support for test cases that require an "online" resource, such as an external server or database.

See OnlineTestCase for details of behaviour and test fixture configuration.

Subclass names should end with "OnlineTest" to allow Maven to treat them specially.

This class contains an adapter to OnlineTestCase that allows its use with JUnit 4. Delegation is used to recycle the behaviour of OnlineTestCase without extending TestCase. This is necessary because TestRunners appear to give priority to JUnit 3 behaviour, ignoring JUnit 4 annotations in suites that extend TestCase.

Author:
Ben Caradoc-Davies, CSIRO Earth Science and Resource Engineering
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    protected void
    Override this method to connect to an online resource.
    protected Properties
    Allows test to create a sample fixture for users.
    protected Properties
    Allows tests to create an offline fixture in cases where the user has not specified an explicit fixture for the test.
    protected void
    Override this method to disconnect from an online resource.
    protected Properties
    Return properties configured in the fixture.
    protected abstract String
    Subclasses must override this method to return a fixture id.
    protected boolean
    Override this method to return false if you can detect that an online resource required for this test is not available,
    protected void
    Method for subclasses to latch onto the setup phase.
    protected void
    Method for subclasses to latch onto the teardown phase.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OnlineTestSupport

      public OnlineTestSupport()
  • Method Details

    • before

      public void before() throws Exception
      Throws:
      Exception
    • after

      public void after() throws Exception
      Throws:
      Exception
    • getFixtureId

      protected abstract String getFixtureId()
      Subclasses must override this method to return a fixture id.
      Returns:
      fixture id
      See Also:
    • connect

      protected void connect() throws Exception
      Override this method to connect to an online resource. Throw an exception on failure.

      Subclasses do not have to override this method, but doing so allows builders to choose to have this test disable itself when the online resource is not available.

      Throws:
      Exception
      See Also:
    • disconnect

      protected void disconnect() throws Exception
      Override this method to disconnect from an online resource. Throw an exception on failure.
      Throws:
      Exception
      See Also:
    • isOnline

      protected boolean isOnline() throws Exception
      Override this method to return false if you can detect that an online resource required for this test is not available,
      Returns:
      false if a required resource is not online
      Throws:
      Exception
      See Also:
    • setUpInternal

      protected void setUpInternal() throws Exception
      Method for subclasses to latch onto the setup phase.
      Throws:
      Exception
      See Also:
    • tearDownInternal

      protected void tearDownInternal() throws Exception
      Method for subclasses to latch onto the teardown phase.
      Throws:
      Exception
      See Also:
    • createOfflineFixture

      protected Properties createOfflineFixture()
      Allows tests to create an offline fixture in cases where the user has not specified an explicit fixture for the test.

      Note, that this should method should on be implemented if the test case is created of creating a fixture which relies solely on embedded or offline resources. It should not reference any external or online resources as it prevents the user from running offline.

      See Also:
    • createExampleFixture

      protected Properties createExampleFixture()
      Allows test to create a sample fixture for users.

      If this method returns a value the first time a fixture is looked up and not found this method will be called to create a fixture file with the same id, but suffixed with .template.

      See Also:
    • getFixture

      protected Properties getFixture()
      Return properties configured in the fixture.

      This method allows subclasses in other packages to access fixture properties.

      Returns:
      properties configured in the fixture.