[Geoserver-devel] Live testing ready for review

Hi,
I've just commited live testing support. Here is a summary
of what I changed.

The first thing to notice is that we not have an interface
for classes that are meant to setup a data directory for
functional testing. Here is is:

/**
  * A test data directory creator and accessor, used for functional testing
  * purposes in GeoServer
  *
  * @author Andrea Aime - TOPP
  */
public interface TestData {
     /**
      * Creates the temporary GeoServer data directory
      */
     public void setUp() throws Exception;

     /**
      * Wipes out the contents of the temporary data directory
      */
     public void tearDown() throws Exception;

     /**
      * @return The root of the data directory.
      */
     public File getDataDirectoryRoot();

     /**
      * Returns wheter the test data is available. If not the test should be skipped
      */
     public boolean isTestDataAvailable();
}

As you can see, there are methods to create the data dir,
destroy it, grab its root, and check wheter the test
data is available. This is used to skip tests where the
data dir could not be setup, think for example
when a fixture is not available or a database to which
we want to connect to is not available.

The implementors of this class are:
* the old MockData (was already there)
* a LiveData class that copies an available data dir
   into /target for testing (pure file based, no dbms)
* a LiveDbmsData that adds whatever is necessary to
   run a test against a database.

In particular, LiveDbmsData:
* looks up of a test fixture, whose identifier is provided
   as a constructor parameter, in the $home/.geoserver
   directory. The lookup fails if the property file is
   not there, or if the -Dgs.fixtureId=false parameter
   was passed to the JVM (to explicitly disable a certain
   online test)
* uses the key/value pairs contained in the property file
   to make a filtered copy of catalog.xml so that the data
   dir points to the local dbms
* uses the same connection parameters to look up a JDBC
   datastore that will give it a JDCB Connection.
   That connection is used to run a sql script to initialize
   the database state.
   The sql script location is provided in the constructor.

If you want to see an example of a test actually using
LiveDbmsData look into org.getoserver.wfsv.WFSVTestSupport,
it's a very simple test that does set up the connection to
a db, and then checks that the stuff we expect is actually
in the GeoServer catalog.

Question, comments, requests for changes: fire away! :slight_smile:
Cheers
Andrea

Hi Andrea,

Got a chance to look it over and it looks good. Not much to say besides that I think maybe the idea of a fixture could be moved up to LiveData instead of LiveDbmsData. I am thinking of use cases here of hitting other types of services besides databases.

Another thing that is more minor would be getting rid of GeoServerAbstractTesSupport and instead have the live tests override the test data instance in GeoServerTestSupport. I guess the reason why is to be able to type narrow the to mock data, since it provides some utilities to existing tests. Perhaps not worth it, but one less class is always nice.

-Justin

Andrea Aime wrote:

Hi,
I've just commited live testing support. Here is a summary
of what I changed.

The first thing to notice is that we not have an interface
for classes that are meant to setup a data directory for
functional testing. Here is is:

/**
  * A test data directory creator and accessor, used for functional testing
  * purposes in GeoServer
  *
  * @author Andrea Aime - TOPP
  */
public interface TestData {
     /**
      * Creates the temporary GeoServer data directory
      */
     public void setUp() throws Exception;

     /**
      * Wipes out the contents of the temporary data directory
      */
     public void tearDown() throws Exception;

     /**
      * @return The root of the data directory.
      */
     public File getDataDirectoryRoot();

     /**
      * Returns wheter the test data is available. If not the test should be skipped
      */
     public boolean isTestDataAvailable();
}

As you can see, there are methods to create the data dir,
destroy it, grab its root, and check wheter the test
data is available. This is used to skip tests where the
data dir could not be setup, think for example
when a fixture is not available or a database to which
we want to connect to is not available.

The implementors of this class are:
* the old MockData (was already there)
* a LiveData class that copies an available data dir
   into /target for testing (pure file based, no dbms)
* a LiveDbmsData that adds whatever is necessary to
   run a test against a database.

In particular, LiveDbmsData:
* looks up of a test fixture, whose identifier is provided
   as a constructor parameter, in the $home/.geoserver
   directory. The lookup fails if the property file is
   not there, or if the -Dgs.fixtureId=false parameter
   was passed to the JVM (to explicitly disable a certain
   online test)
* uses the key/value pairs contained in the property file
   to make a filtered copy of catalog.xml so that the data
   dir points to the local dbms
* uses the same connection parameters to look up a JDBC
   datastore that will give it a JDCB Connection.
   That connection is used to run a sql script to initialize
   the database state.
   The sql script location is provided in the constructor.

If you want to see an example of a test actually using
LiveDbmsData look into org.getoserver.wfsv.WFSVTestSupport,
it's a very simple test that does set up the connection to
a db, and then checks that the stuff we expect is actually
in the GeoServer catalog.

Question, comments, requests for changes: fire away! :slight_smile:
Cheers
Andrea

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

!DSPAM:4007,47d18b85210641030819293!

Justin Deoliveira ha scritto:

Hi Andrea,

Got a chance to look it over and it looks good. Not much to say besides that I think maybe the idea of a fixture could be moved up to LiveData instead of LiveDbmsData. I am thinking of use cases here of hitting other types of services besides databases.

Yeah, I was undecided about its location as well. Yeah, I guess a read
only test using a wfs datastore against a remote and stable WFS server
could be a use case that neeeds fixture support without sql scripts.

I'll have to make fixtureId optional in LiveData, so that the tests
aren't skipped when the fixtureId is not specified (while keep on skipping them when

Another thing that is more minor would be getting rid of GeoServerAbstractTesSupport and instead have the live tests override the test data instance in GeoServerTestSupport. I guess the reason why is to be able to type narrow the to mock data, since it provides some utilities to existing tests. Perhaps not worth it, but one less class is always nice.

Doh, looking into it I realized that I forgot to move the
populateDataDirectory method down to GeoServerTestSupport.
And that's mostly the reason to have a separate class, that method
makes sense only if you're using MockData (it's used to
add extra property or coverage elements to the mock data dir).

Committed the change. Still prefer to have a single class?

Name wise, it would be probably better to perform some changes:
GeoServerAbstractTestSupport -> GeoServerTestSupport
GeoServerTestSupport -> MockDataTestSupport

What do you think?

Cheers
Andrea