Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global crs codes lookup in discovery collections crs tests #255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.opengis.cite.ogcapifeatures10.openapi3.TestPoint;
import org.opengis.cite.ogcapifeatures10.util.JsonUtils;
import org.testng.SkipException;
import org.testng.annotations.Test;

import io.restassured.path.json.JsonPath;
Expand Down Expand Up @@ -52,12 +53,14 @@ public void verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs( TestPo
if ( hasAtLeastOneSpatialFeatureCollection( collection ) ) {
String collectionId = (String) collection.get( "id" );
List<String> crs = JsonUtils.parseAsList( "crs", collection );
if ( crs.size() == 1 && "#/crs".equals( crs.get( 0 ) ) ) {
if(crs.contains("#/crs")) {
List<String> globalCrsList = JsonUtils.parseAsList( "crs", jsonPath );
assertDefaultCrs( globalCrsList,
String.format( "Collection with id '%s' at collections path %s references to global crs section but provides at least one spatial feature collections. The global crs section does not specify one of the default CRS '%s' or '%s'",
collectionId, testPoint.getPath(), DEFAULT_CRS_CODE,
DEFAULT_CRS_WITH_HEIGHT_CODE ) );
List<String> expandedCrs = Stream.of(crs, globalCrsList).flatMap(List::stream)
.filter(code -> !"#/crs".equals(code)).collect(Collectors.toList());
assertDefaultCrs( expandedCrs,
String.format( "Collection with id '%s' at collections path %s references to global crs section but provides at least one spatial feature collections. The global crs section does not specify one of the default CRS '%s' or '%s'",
collectionId, testPoint.getPath(), DEFAULT_CRS_CODE,
DEFAULT_CRS_WITH_HEIGHT_CODE ) );
} else {
assertDefaultCrs( crs,
String.format( "Collection with id '%s' at collections path %s does not specify one of the default CRS '%s' or '%s' but provides at least one spatial feature collections",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DiscoveryCollectionsStorageCrs extends AbstractDiscoveryCollections
*/
@Test(description = "Implements A.1 Discovery, Abstract Test 2 (Requirement /req/crs/fc-md-storageCrs-valid-value), "
+ "storageCrs property in the collection objects in the path /collections", dataProvider = "collectionItemUris", dependsOnGroups = "crs-conformance")
public void verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs( TestPoint testPoint, JsonPath jsonPath,
public void verifyCollectionsPathCollectionCrsPropertyContainsStorageCrs( TestPoint testPoint, JsonPath jsonPath,
Map<String, Object> collection ) {
String collectionId = (String) collection.get( "id" );
String storageCrs = (String) collection.get( "storageCrs" );
Expand All @@ -47,15 +47,18 @@ public void verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs( TestPo
collectionId, testPoint.getPath() ) );
}
List<String> crs = JsonUtils.parseAsList( "crs", collection );
if ( crs.size() == 1 && "#/crs".equals( crs.get( 0 ) ) ) {
List<String> globalCrsList = JsonUtils.parseAsList( "crs", jsonPath );
if ( !globalCrsList.contains( storageCrs ) ) {
throw new AssertionError( String.format( "Collection with id '%s' at collections path %s specifies the storageCrs '%s' which is not declared in the global list of CRSs",
collectionId, testPoint.getPath(), storageCrs ) );
}
} else if ( !crs.contains( storageCrs ) ) {
throw new AssertionError( String.format( "Collection with id '%s' at collections path %s specifies the storageCrs '%s' which is not declared as crs property",

if ( !crs.contains( storageCrs ) ) {
if( crs.contains("#/crs") ) {
List<String> globalCrsList = JsonUtils.parseAsList( "crs", jsonPath );
if ( !globalCrsList.contains( storageCrs ) ) {
throw new AssertionError( String.format( "Collection with id '%s' at collections path %s specifies the storageCrs '%s' which is not declared in the global list of CRSs",
collectionId, testPoint.getPath(), storageCrs ) );
}
} else {
throw new AssertionError( String.format( "Collection with id '%s' at collections path %s specifies the storageCrs '%s' which is not declared as crs property",
collectionId, testPoint.getPath(), storageCrs ) );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package org.opengis.cite.ogcapifeatures10.conformance.crs.discovery.collections;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opengis.cite.ogcapifeatures10.openapi3.TestPoint;
import org.testng.ISuite;
import org.testng.ITestContext;

import io.restassured.path.json.JsonPath;

/**
* @author <a href="mailto:[email protected]">Gabriel Roldan</a>
*/
public class DiscoveryCollectionsDefaultCrsTest {
private static ITestContext testContext;

private static TestPoint testPoint;

/**
* Sample response from a {@code /collections} endpoint. Contains ex
*/
private static JsonPath collectionsResponse;

private DiscoveryCollectionsDefaultCrs discoveryCollectionsDefaultCrs;

@BeforeClass
public static void initTestFixture() throws Exception {
testContext = mock(ITestContext.class);
ISuite suite = mock(ISuite.class);
when(testContext.getSuite()).thenReturn(suite);

testPoint = new TestPoint("http://localhost:8080/api/ogc/features/v1", "/collections", Collections.emptyMap());

collectionsResponse = prepareCollections();
}

@Before
public void setUp() {
discoveryCollectionsDefaultCrs = new DiscoveryCollectionsDefaultCrs();
discoveryCollectionsDefaultCrs.initCommonFixture(testContext);
}

/**
* Test a collection whose crs contains both its {@code storageCrs} and the
* global {@code #/crs} pointer
*/
@Test
public void testVerifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs_globalCrsAndStorageCrs() {
Map<String, Object> collection = collectionsResponse.getMap("collections[0]");
// preflight checks
assertNotNull(collection);
assertEquals("sf:archsites", collection.get("id"));
@SuppressWarnings("unchecked")
List<String> crs = (List<String>) collection.get("crs");
assertThat(collection.get("storageCrs"), equalTo("http://www.opengis.net/def/crs/EPSG/0/26713"));
assertThat(crs, containsInAnyOrder("#/crs", "http://www.opengis.net/def/crs/EPSG/0/26713"));

// test
discoveryCollectionsDefaultCrs.verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs(testPoint,
collectionsResponse, collection);
}

/**
* Test a collection whose crs contains only the global {@code #/crs} pointer
*/
@Test
public void testVerifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs_globalCrs() {
Map<String, Object> collection = collectionsResponse.getMap("collections[1]");
// preflight checks
assertNotNull(collection);
assertEquals("ne:populated_places", collection.get("id"));
@SuppressWarnings("unchecked")
List<String> crs = (List<String>) collection.get("crs");
assertThat(collection.get("storageCrs"), equalTo("http://www.opengis.net/def/crs/OGC/1.3/CRS84"));
assertThat(crs, contains("#/crs"));

// test
discoveryCollectionsDefaultCrs.verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs(testPoint,
collectionsResponse, collection);
}

/**
* Test a collection whose crs contains a list of crs identifiers without the
* global {@code #/crs} pointer
*/
@Test
public void testVerifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs() {
Map<String, Object> collection = collectionsResponse.getMap("collections[2]");
// preflight checks
assertNotNull(collection);
assertEquals("sf:bugsites", collection.get("id"));
@SuppressWarnings("unchecked")
List<String> crs = (List<String>) collection.get("crs");
assertThat(collection.get("storageCrs"), equalTo("http://www.opengis.net/def/crs/EPSG/0/26713"));
assertThat(crs, contains("http://www.opengis.net/def/crs/EPSG/0/26713",
"http://www.opengis.net/def/crs/OGC/1.3/CRS84"));

// test
discoveryCollectionsDefaultCrs.verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs(testPoint,
collectionsResponse, collection);
}

/**
* Test a collection whose crs does not declare any of the default CRS nor has
* the global {@code #/crs} pointer
*/
@Test(expected = AssertionError.class)
public void testVerifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs_no_default_crs() {
Map<String, Object> collection = collectionsResponse.getMap("collections[3]");
// preflight checks
assertNotNull(collection);
assertEquals("no_default_crs", collection.get("id"));

// AssertionError expected here
discoveryCollectionsDefaultCrs.verifyCollectionsPathCollectionCrsPropertyContainsDefaultCrs(testPoint,
collectionsResponse, collection);
}

private static JsonPath prepareCollections() {
return new JsonPath(Objects
.requireNonNull(DiscoveryCollectionsDefaultCrsTest.class.getResourceAsStream("collections.json")));
}
}
Loading