From e977d228e9d1d5057b2ec7c9e094ba3908ff9a02 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Thu, 28 Jun 2018 08:29:21 +0200 Subject: [PATCH] #8 - implemented A.4.4.9 --- .../java/org/opengis/cite/wfs30/WFS3.java | 2 + .../collections/GetFeaturesOperation.java | 141 ++++++++++++++++++ .../collections/GetFeaturesOperationIT.java | 58 +++++++ 3 files changed, 201 insertions(+) create mode 100644 src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java create mode 100644 src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java diff --git a/src/main/java/org/opengis/cite/wfs30/WFS3.java b/src/main/java/org/opengis/cite/wfs30/WFS3.java index 656843c9..c1f23e54 100644 --- a/src/main/java/org/opengis/cite/wfs30/WFS3.java +++ b/src/main/java/org/opengis/cite/wfs30/WFS3.java @@ -12,6 +12,8 @@ private WFS3() { public static final String OPEN_API_MIME_TYPE = "application/openapi+json;version=3.0"; + public static final String GEOJSON_MIME_TYPE = "application/geo+json"; + public enum PATH { API( "api" ), CONFORMANCE( "conformance" ), COLLECTIONS( "collections" ); diff --git a/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java b/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java new file mode 100644 index 00000000..733c38b9 --- /dev/null +++ b/src/main/java/org/opengis/cite/wfs30/collections/GetFeaturesOperation.java @@ -0,0 +1,141 @@ +package org.opengis.cite.wfs30.collections; + +import static io.restassured.http.Method.GET; +import static org.opengis.cite.wfs30.WFS3.GEOJSON_MIME_TYPE; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.opengis.cite.wfs30.CommonFixture; +import org.opengis.cite.wfs30.SuiteAttribute; +import org.testng.ITestContext; +import org.testng.SkipException; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import io.restassured.path.json.JsonPath; +import io.restassured.response.Response; + +/** + * @author Lyn Goltz + */ +public class GetFeaturesOperation extends CommonFixture { + + private final Map collectionNameAndResponse = new HashMap<>(); + + private List> collections; + + @DataProvider(name = "collectionItemUris") + public Object[][] collectionItemUris( ITestContext testContext ) { + Object[][] collectionsData = new Object[collections.size()][]; + for ( int i = 0; i < collections.size(); i++ ) { + collectionsData[i] = new Object[] { collections.get( i ) }; + } + return collectionsData; + } + + @BeforeClass + public void retrieveRequiredInformationFromTestContext( ITestContext testContext ) { + this.collections = (List>) testContext.getSuite().getAttribute( SuiteAttribute.COLLECTIONS.getName() ); + } + + /** + * A.4.4.9. Validate the Get Features Operation + * + * a) Test Purpose: Validate that the Get Features Operation behaves as required. + * + * b) Pre-conditions: + * + * A feature collection name is provided by test A.4.4.6 + * + * Path = /collections/{name}/items + * + * c) Test Method: + * + * DO FOR each /collections{name}/items test point + * + * Issue an HTTP GET request using the test point URI + * + * Go to test A.4.4.10 + * + * d) References: Requirement 17 + * + * @param collection + * the collection under test, never null + */ + @Test(description = "Implements A.4.4.9. Validate the Get Features Operation (Requirement 17, Requirement 24)", dataProvider = "collectionItemUris", dependsOnGroups = "collections") + public void validateGetFeaturesOperation( Map collection ) { + String collectionName = (String) collection.get( "name" ); + + String getFeaturesUrl = findGetFeatureUrlForGeoJson( collection ); + if ( getFeaturesUrl.isEmpty() ) + throw new SkipException( "Could not find url for collection with name " + collectionName + + " supporting GeoJson (type " + GEOJSON_MIME_TYPE + ")" ); + + Response response = init().baseUri( getFeaturesUrl ).accept( GEOJSON_MIME_TYPE ).when().request( GET ); + response.then().statusCode( 200 ); + collectionNameAndResponse.put( collectionName, response ); + } + + /** + * A.4.4.10. Validate the Get Features Operation Response + * + * a) Test Purpose: Validate the Get Feature Operation Response. + * + * b) Pre-conditions: A collection of Features has been retrieved + * + * c) Test Method: + * + * Validate the structure of the response as follows: + * + * For HTML use TBD + * + * For GeoJSON use featureCollectionGeoJSON.yaml + * + * For GML use featureCollectionGML.yaml + * + * Validate that the following links are included in the response document: To itself, Alternate encodings of this + * document in every other media type as identified by the compliance classes for this server. + * + * Validate that each link includes a rel and type parameter. + * + * If a property timeStamp is included in the response, validate that it is close to the current time. + * + * If a property numberReturned is included in the response, validate that the number is equal to the number of + * features in the response. + * + * If a property numberMatched is included in the response, iteratively follow the next links until no next link is + * included and count the aggregated number of features returned in all responses during the iteration. Validate + * that the value is identical to the numberReturned stated in the initial response. + * + * d) References: Requirements 24, 25, 26, 27, 28 and 29 + * + * @param collection + * the collection under test, never null + */ + @Test(description = "Implements A.4.4.10. Validate the Get Features Operation Response (Requirement 25)", dataProvider = "collectionItemUris", dependsOnMethods = "validateGetFeaturesOperation") + public void validateGetFeaturesOperationResponse( Map collection ) { + String collectionName = (String) collection.get( "name" ); + Response response = collectionNameAndResponse.get( collectionName ); + if ( response == null ) + throw new SkipException( "Could not find a response for collection with name " + collectionName ); + + JsonPath jsonPath = response.jsonPath(); + // TODO... + + } + + private String findGetFeatureUrlForGeoJson( Map collection ) { + List links = (List) collection.get( "links" ); + for ( Object linkObject : links ) { + Map link = (Map) linkObject; + Object rel = link.get( "rel" ); + Object type = link.get( "type" ); + if ( "item".equals( rel ) && GEOJSON_MIME_TYPE.equals( type ) ) + return (String) link.get( "href" ); + } + return null; + } +} diff --git a/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java b/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java new file mode 100644 index 00000000..6bf581fc --- /dev/null +++ b/src/test/java/org/opengis/cite/wfs30/collections/GetFeaturesOperationIT.java @@ -0,0 +1,58 @@ +package org.opengis.cite.wfs30.collections; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.opengis.cite.wfs30.SuiteAttribute; +import org.testng.ISuite; +import org.testng.ITestContext; + +import io.restassured.path.json.JsonPath; + +/** + * @author Lyn Goltz + */ +public class GetFeaturesOperationIT { + + private static ITestContext testContext; + + private static ISuite suite; + + @BeforeClass + public static void initTestFixture() + throws Exception { + InputStream json = GetFeaturesOperationIT.class.getResourceAsStream( "../collections/collections.json" ); + JsonPath collectionsResponse = new JsonPath( json ); + List> collections = collectionsResponse.getList( "collections" ); + + testContext = mock( ITestContext.class ); + suite = mock( ISuite.class ); + when( testContext.getSuite() ).thenReturn( suite ); + + URI landingPageUri = new URI( "https://www.ldproxy.nrw.de/kataster" ); + when( suite.getAttribute( SuiteAttribute.IUT.getName() ) ).thenReturn( landingPageUri ); + when( suite.getAttribute( SuiteAttribute.COLLECTIONS.getName() ) ).thenReturn( collections ); + } + + @Test + public void testGetFeatureOperations() { + GetFeaturesOperation getFeaturesOperation = new GetFeaturesOperation(); + getFeaturesOperation.initCommonFixture( testContext ); + getFeaturesOperation.retrieveRequiredInformationFromTestContext( testContext ); + + Object[][] collections = getFeaturesOperation.collectionItemUris( testContext ); + for ( Object[] collection : collections ) { + Map parameter = (Map) collection[0]; + getFeaturesOperation.validateGetFeaturesOperation( parameter ); + getFeaturesOperation.validateGetFeaturesOperationResponse( parameter ); + } + } + +}