Skip to content

Commit

Permalink
Merge pull request #14 from jyutzler/master
Browse files Browse the repository at this point in the history
Ongoing ETS maintenance
  • Loading branch information
jyutzler committed Sep 8, 2017
2 parents 3e6372e + 008aeb8 commit 02ba043
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 60 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ testng/

# IntelliJ files
*.iml
.idea/
.idea/

# MacOS
.DS_Store
35 changes: 28 additions & 7 deletions src/main/java/org/opengis/cite/gpkg12/TableVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ private static void verifyColumns(final Connection connection
throw new RuntimeException(String.format("Required column: %s.%s is missing", tableName, column.getKey())); // TODO this needs to be in the error string table
}

// We shouldn't be picky on table defaults as long as the content is correct
final ColumnDefinition columnDefinition = columns.get(column.getKey());

if(columnDefinition != null)
{
if(!columnDefinition.equals(column.getValue()) ||
!checkExpressionEquivalence(connection,
columnDefinition.getDefaultValue(),
column.getValue().getDefaultValue())) // .equals() for ColumnDefinition skips comparing default values. It's better to check for functional equivalence rather than exact string equality. This avoids issues with difference in white space as well as other trivial annoyances
column.getValue().getDefaultValue()))
{
throw new RuntimeException(String.format("Required column %s is defined as:\n%s\nbut should be:\n%s",
column.getKey(),
Expand All @@ -145,20 +146,40 @@ private static void verifyColumns(final Connection connection
}
}

/**
* .equals() for ColumnDefinition skips comparing default values.
* It's better to check for functional equivalence
* rather than exact string equality.
* This avoids issues with difference in white space
* as well as other trivial annoyances.
* @param connection
* @param definition
* @param required
* @return
* @throws SQLException
*/
private static boolean checkExpressionEquivalence(final Connection connection,
final String expression1,
final String expression2) throws SQLException
final String definition,
final String required) throws SQLException
{
if((expression1 == null) || (expression2 == null))
if((definition == null) || (required == null))
{
return (expression1 == null) && (expression2 == null);
return (definition == null) && (required == null);
}

// Sometimes people use a synonym here and functional equivalence
// isn't possible because now is always changing
if(required.replaceAll("\\s+","").equalsIgnoreCase("strftime('%Y-%m-%dT%H:%M:%fZ','now')")){
if (definition.replaceAll("\\s+","").equalsIgnoreCase("strftime('%Y-%m-%dT%H:%M:%fZ',current_timestamp)")){
return true;
}
}

try(final Statement statement = connection.createStatement())
{
final String query = String.format("SELECT (%s) = (%s);",
expression1,
expression2);
definition,
required);

try(final ResultSet results = statement.executeQuery(query))
{
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/org/opengis/cite/gpkg12/core/DataContentsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* </p>
* <ul>
* <li><a href="http://www.geopackage.org/spec/#_contents" target= "_blank">
* GeoPackage Encoding Standard - Contents</a> (OGC 12-128r12)</li>
* GeoPackage Encoding Standard - Contents</a> (OGC 12-128r14)</li>
* </ul>
*
* @author Luke Lambert
Expand All @@ -49,13 +49,13 @@ public class DataContentsTests extends CommonFixture
* "http://www.geopackage.org/spec/#table_column_data_types">GeoPackage
* Data Types</a>.
*
* @see <a href="http://www.geopackage.org/spec/#_requirement-5" target=
* @see <a href="http://www.geopackage.org/spec/#r5" target=
* "_blank">File Contents - Requirement 5</a>
*
* @throws SQLException
* If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r12: Requirement 5")
@Test(description = "See OGC 12-128r14: Requirement 5")
public void columnDataTypes() throws SQLException
{
// 1
Expand Down Expand Up @@ -103,13 +103,13 @@ public void columnDataTypes() throws SQLException
* "http://www.geopackage.org/spec/#gpkg_contents_sql">gpkg_contents Table
* Definition SQL</a>.
*
* @see <a href="http://www.geopackage.org/spec/#_requirement-13" target=
* @see <a href="http://www.geopackage.org/spec/#_r13" target=
* "_blank">Table Definition - Requirement 13</a>
*
* @throws SQLException
* If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r12: Requirement 13")
@Test(description = "See OGC 12-128r14: Requirement 13")
public void contentsTableDefinition() throws SQLException
{
try
Expand Down Expand Up @@ -143,13 +143,13 @@ public void contentsTableDefinition() throws SQLException
* The {@code table_name} column value in a {@code gpkg_contents} table row
* SHALL contain the name of a SQLite table or view.
*
* @see <a href="http://www.geopackage.org/spec/#_requirement-14" target=
* @see <a href="http://www.geopackage.org/spec/#r14" target=
* "_blank">Table Data Values - Requirement 14</a>
*
* @throws SQLException
* If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r12: Requirement 14")
@Test(description = "See OGC 12-128r14: Requirement 14")
public void contentsTablesExist() throws SQLException
{
final String query = "SELECT DISTINCT table_name " +
Expand Down Expand Up @@ -182,13 +182,13 @@ public void contentsTablesExist() throws SQLException
* and a decimal fraction of a second, with a 'Z' ('zulu') suffix
* indicating UTC.
*
* @see <a href="http://www.geopackage.org/spec/#_requirement-15" target=
* @see <a href="http://www.geopackage.org/spec/#r15" target=
* "_blank">Table Data Values - Requirement 15</a>
*
* @throws SQLException
* If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r12: Requirement 15")
@Test(description = "See OGC 12-128r14: Requirement 15")
public void timestampFormat() throws SQLException
{
// 1
Expand Down Expand Up @@ -224,13 +224,13 @@ public void timestampFormat() throws SQLException
* reference values in the {@code gpkg_spatial_ref_sys} table {@code
* srs_id} column.
*
* @see <a href="http://www.geopackage.org/spec/#_requirement-16" target=
* @see <a href="http://www.geopackage.org/spec/#r16" target=
* "_blank">Table Data Values - Requirement 16</a>
*
* @throws SQLException
* If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r12: Requirement 16")
@Test(description = "See OGC 12-128r14: Requirement 16")
public void srsIdReferencesSrsTable() throws SQLException
{
try(final Statement statement = this.databaseConnection.createStatement();
Expand All @@ -245,22 +245,23 @@ public void srsIdReferencesSrsTable() throws SQLException
* Verify that a GeoPackage contains a features or tiles table and
* gpkg_contents table row describing it.
*
* @see <a href="http://www.geopackage.org/spec/#_requirement-17" target=
* @see <a href="http://www.geopackage.org/spec/#_r17" target=
* "_blank">Options - Requirement 17</a>
*
* @throws SQLException
* If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r12: Requirement 17")
@Test(description = "See OGC 12-128r14: Requirement 17")
public void optValidGeoPackage() throws SQLException
{
try(final Statement statement = this.databaseConnection.createStatement();
final ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM gpkg_contents WHERE data_type IN ('tiles', 'features')"))
{
resultSet.next();
assertTrue(resultSet.getInt(1) > 0,
ErrorMessage.format(ErrorMessageKeys.OPTIONS_NO_FEATURES_OR_TILES));
}
//no op: requirement removed
// try(final Statement statement = this.databaseConnection.createStatement();
// final ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM gpkg_contents WHERE data_type IN ('tiles', 'features')"))
// {
// resultSet.next();
// assertTrue(resultSet.getInt(1) > 0,
// ErrorMessage.format(ErrorMessageKeys.OPTIONS_NO_FEATURES_OR_TILES));
// }
}
private static final Pattern TEXT_TYPE = Pattern.compile("TEXT\\([0-9]+\\)");
private static final Pattern BLOB_TYPE = Pattern.compile("BLOB\\([0-9]+\\)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void extensionsTableValues() throws SQLException
try ( // 1
final Statement statement = this.databaseConnection.createStatement();

final ResultSet resultSet = statement.executeQuery("SELECT table_name, column_name FROM gpkg_extensions;");
final ResultSet resultSet = statement.executeQuery("SELECT lower(table_name) AS table_name, column_name FROM gpkg_extensions;");
) {
// 2
while (resultSet.next()) {
Expand All @@ -132,13 +132,13 @@ public void extensionsTableValues() throws SQLException
// 4
final Statement statement2 = this.databaseConnection.createStatement();

final ResultSet resultSet2 = statement2.executeQuery("SELECT DISTINCT ge.table_name AS ge_table, sm.tbl_name FROM gpkg_extensions AS ge LEFT OUTER JOIN sqlite_master AS sm ON ge.table_name = sm.tbl_name;");
final ResultSet resultSet2 = statement2.executeQuery("SELECT DISTINCT lower(ge.table_name) AS ge_table, lower(sm.tbl_name) AS tbl_name FROM gpkg_extensions AS ge LEFT OUTER JOIN sqlite_master AS sm ON lower(ge.table_name) = lower(sm.tbl_name);");
) {
while (resultSet2.next()) {
// 4a
final String geTable = resultSet2.getString("ge_table");
final String tableName = resultSet2.getString("tbl_name");
assertTrue(((geTable == null) && (tableName == null)) || tableName.equals(geTable), ErrorMessage.format(ErrorMessageKeys.INVALID_DATA_TABLE, "gpkg_extensions", geTable));
assertTrue(((geTable == null) && (tableName == null)) || ((tableName != null) && tableName.equals(geTable)), ErrorMessage.format(ErrorMessageKeys.INVALID_DATA_TABLE, "gpkg_extensions", geTable));
}
}
}
Expand All @@ -163,7 +163,7 @@ public void extensionsColumnValues() throws SQLException
// 1
final Statement statement = this.databaseConnection.createStatement();

final ResultSet resultSet = statement.executeQuery("SELECT table_name, column_name FROM gpkg_extensions WHERE column_name IS NOT NULL;");
final ResultSet resultSet = statement.executeQuery("SELECT lower(table_name) AS table_name, lower(column_name) AS column_name FROM gpkg_extensions WHERE column_name IS NOT NULL;");
) {
// 2
while (resultSet.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public class CRSWKT extends CommonFixture
@BeforeClass
public void activeExtension(ITestContext testContext) throws SQLException {
Assert.assertTrue(DatabaseUtility.doesTableOrViewExist(this.databaseConnection, "gpkg_extensions"),
ErrorMessage.format(ErrorMessageKeys.MISSING_TABLE, "gpkg_extensions"));



ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "CRS WKT Extension"));

try (
final Statement statement = this.databaseConnection.createStatement();
final ResultSet resultSet = statement.executeQuery("SELECT count(*) from gpkg_extensions WHERE extension_name = 'gpkg_crs_wkt';");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.opengis.cite.gpkg12.ErrorMessage;
import org.opengis.cite.gpkg12.ErrorMessageKeys;
import org.opengis.cite.gpkg12.tiles.TileTests;
import org.opengis.cite.gpkg12.util.DatabaseUtility;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -49,6 +50,9 @@ public ElevationTests(){

@BeforeClass
public void a_ValidateExtensionPresent(ITestContext testContext) throws SQLException {
Assert.assertTrue(DatabaseUtility.doesTableOrViewExist(this.databaseConnection, "gpkg_extensions"),
ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "Elevation Extension"));

try (
final Statement statement1 = this.databaseConnection.createStatement();
ResultSet resultSet1 = statement1.executeQuery("SELECT COUNT(*) FROM gpkg_extensions WHERE table_name = 'gpkg_2d_gridded_coverage_ancillary';");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class MetadataTests extends CommonFixture
@BeforeClass
public void setUp() throws SQLException
{

this.metadataValues = new LinkedList<>();

try(final Statement statement = this.databaseConnection.createStatement())
Expand Down Expand Up @@ -100,6 +99,9 @@ public void activeExtension(ITestContext testContext) throws SQLException {
Assert.assertTrue(DatabaseUtility.doesTableOrViewExist(this.databaseConnection, "gpkg_metadata"),
ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "Metadata Option"));
} else {
Assert.assertTrue(DatabaseUtility.doesTableOrViewExist(this.databaseConnection, "gpkg_extensions"),
ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "Metadata Extension"));

Assert.assertTrue(DatabaseUtility.doesTableOrViewExist(this.databaseConnection, "gpkg_extensions"),
ErrorMessage.format(ErrorMessageKeys.MISSING_TABLE, "gpkg_extensions"));

Expand Down Expand Up @@ -255,6 +257,11 @@ public void metadataReferencesTableDefinition()
@Test(description = "See OGC 12-128r13: Requirement 140")
public void metadataExtensionTableValues() throws SQLException
{
// This requirement was not introduced until GPKG 1.2
if ((getGeopackageVersion() == GeoPackageVersion.V102) || (getGeopackageVersion() == GeoPackageVersion.V110)) {
return;
}

try (
// 1
final Statement statement = this.databaseConnection.createStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opengis.cite.gpkg12.ErrorMessage;
import org.opengis.cite.gpkg12.ErrorMessageKeys;
import org.opengis.cite.gpkg12.features.FeaturesTests;
import org.opengis.cite.gpkg12.util.DatabaseUtility;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -46,12 +47,15 @@ public class NonlinearTests extends FeaturesTests {
*/
@BeforeClass
public void validateExtensionPresent(ITestContext testContext) throws SQLException {
Assert.assertTrue(DatabaseUtility.doesTableOrViewExist(this.databaseConnection, "gpkg_extensions"),
ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "Non-Linear Geometry Types Extension"));

try (
final Statement statement1 = this.databaseConnection.createStatement();
ResultSet resultSet1 = statement1.executeQuery("SELECT COUNT(*) FROM gpkg_extensions WHERE extension_name LIKE 'gpkg_geom_%';");
) {
resultSet1.next();
Assert.assertTrue(resultSet1.getInt(1) > 0, ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "RTree Spatial Index Extension"));
Assert.assertTrue(resultSet1.getInt(1) > 0, ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, "Non-Linear Geometry Types Extension"));
}
}

Expand Down

0 comments on commit 02ba043

Please sign in to comment.