org.opengis.test
Class TestSuite

Show UML class diagram
Object
  extended by TestSuite

public class TestSuite
extends Object

The suite of every tests defined in the GeoAPI conformance module. The test cases included in this test suite are:

All tests use Factory instances that are specific to the implementation being tested. By default TestSuite fetches the factory implementations with ServiceLoader, which will scan every META-INF/services/org.opengis.TheFactory files on the classpath. However implementors can override this default mechanism with explicit calls to the setFactories(Class, Factory[]) method.

Implementors can have some control on the tests (factories to use, features to test, tolerance thresholds) by registering their FactoryFilter or ImplementationDetails in the META-INF/services/ directory. As an alternative, implementors can also extend directly the various TestCase subclasses.

Example: The test suite below declares that the tolerance threshold for MyProjection needs to be relaxed by a factor 10 during inverse projections.

package org.myproject;

import org.opengis.test.TestSuite;
import org.opengis.test.CalculationType;
import org.opengis.test.ToleranceModifier;
import org.opengis.test.ToleranceModifiers;
import org.opengis.test.ImplementationDetails;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.util.Factory;
import java.util.Properties;

public class GeoapiTest extends TestSuite implements ImplementationDetails {
    @Override
    public Properties configuration(Factory... factories) {
        return null;
    }

    @Override
    public ToleranceModifier tolerance(MathTransform transform) {
        if (transform instanceof MyProjection) {
            return ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1, 10);
        }
        return null;
    }
}
The above AllTests class needs to be registered in the META-INF/services/ directory if the implementation details shall be honored (otherwise the tests will be run, but the implementation details will be ignored).

Since:
3.1
See Also:
ImplementationDetails, TestCase, Factory

Constructor Summary
protected TestSuite()
          Constructor provided for allowing subclassing.
 
Method Summary
static void clear()
          Clears all factories specified to the setFactories(Class, Factory[]) method, and clears all service loader caches.
static
<T extends Factory>
T[]
getFactories(Class<T> type)
          Returns the factory implementations explicitely given by the last call to setFactories(Class, Factory[]) for the given interface.
static void setClassLoader(ClassLoader loader)
          Sets the class loader to use for loading implementations.
static
<T extends Factory>
void
setFactories(Class<T> type, T... factory)
          Specifies the factory implementations to use for the given factory interface.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestSuite

protected TestSuite()
Constructor provided for allowing subclassing. Instances of this class usually don't need to be created.

Method Detail

setFactories

public static <T extends Factory> void setFactories(Class<T> type,
                                                    T... factory)
Specifies the factory implementations to use for the given factory interface.

Type Parameters:
T - The compile-time type of the type class argument.
Parameters:
type - The factory interface for which an implementation is specified.
factory - The implementations to use for the given interface.

getFactories

public static <T extends Factory> T[] getFactories(Class<T> type)
Returns the factory implementations explicitely given by the last call to setFactories(Class, Factory[]) for the given interface. This method does not scan the META-INF/services/<T> entries.

Type Parameters:
T - The compile-time type of the type class argument.
Parameters:
type - The factory interface for which an implementations is desired.
Returns:
The implementations for the given interface, or null if none.

setClassLoader

public static void setClassLoader(ClassLoader loader)
Sets the class loader to use for loading implementations. A null value restores the default context class loader.

Parameters:
loader - The class loader to use, or null for the default.

clear

public static void clear()
Clears all factories specified to the setFactories(Class, Factory[]) method, and clears all service loader caches. After this method call, all factories will be reloaded when first needed. This method is intended for use in situations in which new factories can be installed or removed into a running Java virtual machine.

See Also:
ServiceLoader.reload()


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