|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.geotools.test.OnlineTestCase
public abstract class OnlineTestCase
Test support for test cases that require an "online" resource, such as an external server or database.
Online tests work off of a "fixture". A fixture is a properties file which
defines connection parameters for some remote service. Each online test case
must define the id of the fixture is uses with getFixtureId()
.
Fixtures are stored under the users home directory, under the ".geotools
"
directory. Dots "." in the fixture id represent a subdirectory path under this
configuration file directory. For example, a fixture id a.b.foo
would be
resolved to .geotools/a/b/foo.properties
.
In the event that a fixture does not exist, the test case is aborted.
Online tests connect to remote / online resources. Test cases should do all
connection / disconnection in the connect()
and disconnect()
methods.
The default behaviour of this class is that if connect()
throws an exception, the test
suite is disabled, causing each test to pass without being run. In addition, exceptions thrown by
disconnect()
are ignored. This behaviour allows tests to be robust against transient
outages of online resources, but also means that local software failures in connect()
or
disconnect()
will be silent.
To have exceptions thrown by connect()
and disconnect()
cause tests to fail,
set skip.on.failure=false
in the fixture property file. This restores the
traditional behaviour of unit tests, that is, that exceptions cause unit tests to fail.
Field Summary | |
---|---|
protected java.util.Properties |
fixture
The test fixture, null if the fixture is not available. |
protected static java.util.Map<java.lang.String,java.lang.Boolean> |
found
A static map which tracks which fixture files can not be found. |
protected static java.util.Map<java.lang.String,java.lang.Boolean> |
online
A static map which tracks which fixtures are offline. |
static java.lang.String |
ONLINE_TEST_PROFILE
System property set to totally disable any online tests |
static java.lang.String |
SKIP_ON_FAILURE_DEFAULT
The default value used for SKIP_ON_FAILURE_KEY if it is not present. |
static java.lang.String |
SKIP_ON_FAILURE_KEY
The key in the test fixture property file used to set the behaviour of the online test if connect() fails. |
protected boolean |
skipOnFailure
Flag that determines effect of exceptions in connect/disconnect. |
Constructor Summary | |
---|---|
OnlineTestCase()
|
Method Summary | |
---|---|
protected void |
connect()
Connection method, called from setUp() . |
protected java.util.Properties |
createExampleFixture()
Allows test to create a sample fixture for users. |
protected java.util.Properties |
createOfflineFixture()
Allows tests to create an offline fixture in cases where the user has not specified an explicit fixture for the test. |
protected void |
disconnect()
Disconnection method, called from tearDown() . |
protected abstract java.lang.String |
getFixtureId()
The fixture id for the test case. |
protected boolean |
isOnline()
Tests if external resources needed to run the tests are online. |
void |
run(junit.framework.TestResult result)
Override which checks if the fixture is available. |
protected void |
setUp()
Loads the test fixture for the test case. |
protected void |
setUpInternal()
Method for subclasses to latch onto the setup phase. |
protected void |
tearDown()
Tear down method for test, calls through to disconnect() if the
test is active. |
protected void |
tearDownInternal()
Method for subclasses to latch onto the teardown phase. |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, runBare, runTest, setName, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ONLINE_TEST_PROFILE
public static final java.lang.String SKIP_ON_FAILURE_KEY
connect()
fails.
public static final java.lang.String SKIP_ON_FAILURE_DEFAULT
SKIP_ON_FAILURE_KEY
if it is not present.
protected static java.util.Map<java.lang.String,java.lang.Boolean> online
protected static java.util.Map<java.lang.String,java.lang.Boolean> found
protected java.util.Properties fixture
null
if the fixture is not available.
protected boolean skipOnFailure
Constructor Detail |
---|
public OnlineTestCase()
Method Detail |
---|
public void run(junit.framework.TestResult result)
run
in interface junit.framework.Test
run
in class junit.framework.TestCase
protected final void setUp() throws java.lang.Exception
The fixture id is obtained via getFixtureId()
.
setUp
in class junit.framework.TestCase
java.lang.Exception
protected void setUpInternal() throws java.lang.Exception
java.lang.Exception
protected final void tearDown() throws java.lang.Exception
disconnect()
if the
test is active.
tearDown
in class junit.framework.TestCase
java.lang.Exception
protected void tearDownInternal() throws java.lang.Exception
java.lang.Exception
protected boolean isOnline() throws java.lang.Exception
This method can return false to indicate the online resources are not up, or can simply throw an exception.
java.lang.Exception
- Any errors that occur determining if online resources are available.protected void connect() throws java.lang.Exception
setUp()
.
Subclasses should do all initialization / connection here. In the event of a connection not being available, this method should throw an exception to abort the test case.
java.lang.Exception
- if the connection failed.protected void disconnect() throws java.lang.Exception
tearDown()
.
Subclasses should do all cleanup here.
java.lang.Exception
- if the disconnection failed.protected java.util.Properties createOfflineFixture()
Note, that this should method should on be implemented if the test case is created of creating a fixture which relies soley on embedded or offline resources. It should not reference any external or online resources as it prevents the user from running offline.
protected java.util.Properties createExampleFixture()
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 teh same id, but suffixed with .template.
protected abstract java.lang.String getFixtureId()
This name is hierarchical, similar to a java package name. Example:
"postgis.demo_bc"
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |