Skip to content

Devs: running integration tests

Emanuele Tajariol edited this page Feb 10, 2021 · 8 revisions

PostGIS tests

(Since 3.4.8).

In order to run persistence tests against PostGIS, run the mvn install command with the postgis profile, e.g.:

mvn clean install -Ppostgis

With this profile, the module persistence-pg-test will be included; it runs the very same set of tests implemented in the persistence module, but against a pg database.

You will need:

  • an existing local Postgres DB named geofence_test
  • the owner of the db is called geofence_test with password geofence_test.

If you need to change the test db access info, you have to edit the core/persistence-pg-test/src/test/resources/geofence-datasource-ovr.properties file.

REST integration tests

The tests in src/services/modules/rest/client will be skipped if a test server instance is not found.

In order to run the test server instance:

  • go to src/services/modules/rest/test

  • run

       mvn jetty:run
    

Then rebuild (or run the test goal) in the rest client module:

  • go to src/services/modules/rest/client

  • run

       mvn clean install
    

    and make sure the ConnectException stack traces are not dumped.

REST tests with postgis

If you want to run the tests against a PostGIS DB, run the test server instance with:

mvn jetty:run -Dgeofence-datasource-file=src/main/resources/geofence-datasource-ovr-pg.properties -Ppostgis

As in the previous test, you will need:

  • a local Postgres DB named geofence_test
  • the owner of the db is called geofence_test with password geofence_test

GeoServer integration (GeoFence standalone)

The tests in the GeoServer community module src/community/geofence will be skipped if no test server instance is found; this message will be printed for each skipped test:

    Skipping test in AccessManagerTest as GeoFence service is down: in order to run this test you need the services to be running on port 9191

In order to run the test server instance:

  • go to the GeoFence module src/services/core/webtest

  • run

       mvn jetty:run
    

Then rebuild (or run the test goal) in the geofence community module:

  • go to src/community/geofence

  • run

       mvn clean install
    

GeoServer tests with postgis

If you want to run the tests against a PostGIS DB, run the test server instance with:

mvn jetty:run -Dgeofence-datasource-file=src/main/resources/geofence-datasource-ovr-pg.properties -Ppostgis

As in the previous test, you will need:

  • a local Postgres DB named geofence_test
  • the owner of the db is called geofence_test with password geofence_test

GeoServer integration (GeoFence embedded)

Build a testable war file

Build GeoServer and the GeoFence plugins:

cd <GEOSERVER_SOURCE_ROOT>/src
mvn clean install -Pgeofence -Pgeofence-server -T4

The previous build will also create a .war. file with both geofence plugins dependencies, which are in conflict. Let's build a vanilla geoserver.war with sample data:

cd web/app
mvn clean install -Prelease

Build the plugin ZIPs:

cd <GEOSERVER_SOURCE_ROOT>/src/release
mvn clean install 
cd ../..
mvn -f src/pom.xml assembly:single -N

Create a new war with the geofence-server plugin:

cd <GEOSERVER_SOURCE_ROOT>
mkdir -p distribution/geoserver
unzip src/web/app/target/geoserver.war -d distribution/geoserver/
unzip src/target/release/geoserver-2.17-SNAPSHOT-geofence-server-plugin.zip -d distribution/geoserver/WEB-INF/lib/
cd distribution/geoserver/
zip -r ../geoserver.war *
cd ..

You can new run the geoserver.war file in tomcat or another container.

Run the test

There are no automatic test.
We can't even run the GeoFence REST API client tests because some REST paths are mapped in GeoServer in a different way than in GeoFence (the users info for instance).

We can anyway send a REST request to store a new Rule, also including a Geometry to check tht the spatial libraries are properly working:

curl -i  -u admin:geoserver -XPOST -d '<Rule><access>LIMIT</access><limits><allowedArea>MULTIPOLYGON (((1 1, 5 1, 5 5, 1 5, 1 1), (2 2, 3 2, 3 3, 2 3, 2 2)))</allowedArea></limits><priority>0</priority></Rule>' http://localhost:8080/geoserver/rest/geofence/rules -H "Content-type: application/xml"

Retrieev all the rules:

curl -i  -u admin:geoserver http://localhost:8080/geoserver/rest/geofence/rules -H "Accept: application/json"

Run the test in postGIS

Edit the file <GEOSERVER_DATA_DIR>/geofence/geofence-datasource-ovr.properties and add the lines defining a postgis backend:

geofenceEntityManagerFactory.jpaPropertyMap[hibernate.hbm2ddl.auto]=create-drop
geofenceVendorAdapter.databasePlatform=org.hibernatespatial.postgis.PostgisDialect
geofenceDataSource.driverClassName=org.postgresql.Driver
geofenceDataSource.url=jdbc:postgresql://localhost:5432/geofence_test
geofenceDataSource.username=geofence_test
geofenceDataSource.password=geofence_test 

Put the proper libraries in webapps/geoserver/WEB-INF/lib/:

Note:

  • hibernate-spatial-* versions may change: for instance
    • 1.1.3.1 is needed for JTS<1.17.0, so GeoServer <= 2.17.2
    • 1.1.3.2 is needed for JTS>=1.17.0, so GeoServer >= 2.17.3, 2.18, ...
  • hibernate-spatial-* specific DBMS will conflict, so you can only have one among h2-geodb, postgis, oracle.

Then restart GeoServer and repeat the curl requests.