org.opengis.test
Class TestCase

Show UML class diagram
Object
  extended by TestCase
Direct Known Subclasses:
AuthorityFactoryTest, CRSTest, ImageIOTestCase, NameTest, ObjectFactoryTest, Series2000Test, Series3000Test, TransformTestCase

public abstract class TestCase
extends Object

Base class of all GeoAPI tests. All concrete subclasses need at least one factory for instantiating the objects to test. The factories must be specified at subclasses construction time either directly by the implementor, or indirectly by calls to the factories(Class[]) method.

Since:
2.2
See Also:
TestSuite

Field Summary
protected  Configuration.Key<Boolean> configurationTip
          A tip set by subclasses during the execution of optional tests.
 TestWatcher listener
          A JUnit rule for listening to test execution events.
protected static Factory[] NO_FACTORY
          An empty array of factories, as a convenience for no-argument constructors.
protected  ValidatorContainer validators
          The set of Validator instances to use for verifying objects conformance (never null).
 
Constructor Summary
protected TestCase()
          Creates a new test without factory.
protected TestCase(Factory... factories)
          Creates a new test which will use the given factories to execute.
 
Method Summary
static void addTestListener(TestListener listener)
          Adds a listener to be informed every time a test begin or finish, either on success or failure.
 Configuration configuration()
          Returns information about the configuration of the test which has been run.
protected static List<Factory[]> factories(Class<? extends Factory>... types)
          Returns factory instances for given factory interfaces.
protected static List<Factory[]> factories(FactoryFilter filter, Class<? extends Factory>... types)
          Returns factory instances for given factory interfaces, excluding the factories filtered by the given filter.
protected  boolean[] getEnabledFlags(Configuration.Key<Boolean>... properties)
          Returns booleans indicating whether the given operations are enabled.
static void removeTestListener(TestListener listener)
          Removes a previously added listener.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_FACTORY

protected static final Factory[] NO_FACTORY
An empty array of factories, as a convenience for no-argument constructors.

Since:
3.1

listener

public final TestWatcher listener
A JUnit rule for listening to test execution events. This rule forwards events to all registered listeners.

This field is public because JUnit requires us to do so, but should be considered as an implementation details (it should have been a private field).

Since:
3.1

validators

protected final ValidatorContainer validators
The set of Validator instances to use for verifying objects conformance (never null). If no validators were explicitely specified, then the default validators are used.

Since:
3.1

configurationTip

protected transient Configuration.Key<Boolean> configurationTip
A tip set by subclasses during the execution of optional tests. If case of optional test failure, if this field is non-null, then a message will be logged at the INFO level for giving some tips to the developer about how he can disable the test.

Example

@Test
public void myTest() {
    if (isDerivativeSupported) {
        configurationTip = Configuration.Key.isDerivativeSupported;
        // Do some tests the require support of math transform derivatives.
    }
    configurationTip = null;
}

Since:
3.1
Constructor Detail

TestCase

protected TestCase()
Creates a new test without factory. This constructor is provided for subclasses that instantiate their test object directly, without using any factory.


TestCase

protected TestCase(Factory... factories)
Creates a new test which will use the given factories to execute.

Parameters:
factories - The factories to be used by the test. Those factories will be given to ImplementationDetails.configuration(Factory[]) in order to decide which validators to use.
Since:
3.1
Method Detail

factories

protected static List<Factory[]> factories(Class<? extends Factory>... types)
Returns factory instances for given factory interfaces. Each element in the returned list is the arguments to give to the subclass constructor. There is typically only one element in the list, but more elements could be included if many factory implementations are found for the same interface.

This method is used by static methods having the Parameterized.Parameters annotation in subclasses. For example if a subclass constructor expects 3 factories of kind CRSFactory, CSFactory and DatumFactory in that order, then that subclass contain the following method:

@Parameterized.Parameters
public static List<Factory[]> factories() {
    return factories(CRSFactory.class, CSFactory.class, DatumFactory.class);
}
Note that the arrays may contain null elements if no factory implementation were found for a given interface. All GeoAPI test cases use Assume checks in order to disable any tests that require a missing factory.

If many factory implementations were found for a given interface, then this method returns all possible combinations of those factories. For example if two instances of interface A are found (named A1 and A2), and two instances of interface B are also found (named B1 and B2), then this method returns a list containing:

{A1, B1}
{A2, B1}
{A1, B2}
{A2, B2}
The current implementation first checks the factories explicitely specified by calls to the TestSuite.setFactories(Class, Factory[]) method. In no factories were explicitely specified, then this method searches the classpath using ServiceLoader.

Parameters:
types - The kind of factories to fetch.
Returns:
All combinations of factories of the given kind. Each list element is an array having the same length than types.
Since:
3.1
See Also:
NameTest.factories(), ObjectFactoryTest.factories(), AuthorityFactoryTest.factories(), AffineTransformTest.factories(), ParameterizedTransformTest.factories()

factories

protected static List<Factory[]> factories(FactoryFilter filter,
                                           Class<? extends Factory>... types)
Returns factory instances for given factory interfaces, excluding the factories filtered by the given filter. This method performs the same work than factories(Class[]) except that the given filter is applied in addition to any filter found on the classpath.

The main purpose of this method is to get AuthorityFactory instances for a given authority name.

Parameters:
filter - An optional factory filter to use in addition to any filter declared in the classpath, or null if none.
types - The kind of factories to fetch.
Returns:
All combinations of factories of the given kind. Each list element is an array having the same length than types.
Since:
3.1

getEnabledFlags

protected final boolean[] getEnabledFlags(Configuration.Key<Boolean>... properties)
Returns booleans indicating whether the given operations are enabled. By default, every operations are enabled. However if any ImplementationDetails instance found on the classpath returns a configuration map having the value Boolean.FALSE for a given key, then the boolean value corresponding to that key is set to false.

Parameters:
properties - The key for which the flags are wanted.
Returns:
An array of the same length than properties in which each element at index i indicates whether the properties[i] test should be enabled.
Since:
3.1

configuration

public Configuration configuration()
Returns information about the configuration of the test which has been run. The content of this map depends on the TestCase subclass and on the values returned by the ImplementationDetails.configuration(Factory[]) method for the factories being tested. For a description of the map content, see any of the following subclasses:

Returns:
The configuration of the test being run, or an empty map if none. This method returns a modifiable map in order to allow subclasses to modify it.
Since:
3.1
See Also:
ImplementationDetails.configuration(Factory[])

addTestListener

public static void addTestListener(TestListener listener)
Adds a listener to be informed every time a test begin or finish, either on success or failure. This method does not check if the given listener was already registered (i.e. the same listener may be added more than once).

Parameters:
listener - The listener to add. null values are silently ignored.
Since:
3.1

removeTestListener

public static void removeTestListener(TestListener listener)
Removes a previously added listener. If the given listener has been added more than once, then only the last occurrence is removed. If the given listener is not found, then this method does nothing.

Parameters:
listener - The listener to remove. null values are silently ignored.
Since:
3.1


Copyright © 1994-2013 Open Geospatial Consortium. All Rights Reserved.