Skip to content

GSIP 12 Mock Test Support

jdeolive edited this page Jun 11, 2014 · 1 revision

GSIP 12 - Mock Test Support

Overview

Provide base classes which make it trivial to develop unit tests based on a “mock” GeoServer setup.

Proposed By

Justin Deoliveira

Proposal Type

Core Change

Assigned to release

tbd.

State

Obsolete

Links

JIRA task:

Dependencies

[GSIP 8 - New Configuration System]

Email discussion:

Other wiki discussions:

Motivations

Current it is hard to develop unit tests for GeoServer is hard and a lot of work. For this reason our level of unit test coverage is unacceptably low.

Assumptions

Proposal

Develop base classes which create a mock geoserver instance and make it available to test cases. Such base classes would provide the following:

  • API which allows tests to simulate requests from a client. Example:

    public class GetFeatureMockTest extends GeoServerMockTest {

    public void testGet() {
      //execute a mock GetFeature "get" request
      String request = "request=GetFeature&typeName=topp:states&....";
      org.w3c.dom.Document response = getAsDOM( request );
    
      //make assertions
      ...
    }
    
    public void testPost() {
       //execute a mock GetFeature "post" request
       String request = 
         "<wfs:GetFeature typeName="topp:states"/>";
       org.w3c.dom.Document response = postAsDOM( request );
    
       //make assertions
       ...
    }
    

    }

  • Provide an instance of the spring context which is used in a live GeoServer instance, and access to the components inside of it. Example:

    public class DataTest extends GeoServerMockTest {

    public void testData() {
       //get the "data" component / bean
       Data data = (Data) context.getBean( "data" );
    
       //make assertions
    }
    
    public void testGeoServer() {
       //get the "GeoServer" component / bean
       GeoServer geoServer = (GeoServer) context.getBean( "geoServer" );
    
       //make assertions
       ...
    }
    

    }

Implementation

The base class which sets up the “mock” GeoServer instance will simulate the spring context which is created when a live GeoServer is started. To do so a full catalog and config must be created.

Backwards compatibility issues

Risks

Participants

Justin Deoliveira

Clone this wiki locally