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

Implement attribute tests, and tests for those tests. #22

Merged
merged 1 commit into from Oct 27, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,75 @@
package org.opengis.cite.gpkg12.attributes;

import static org.testng.Assert.assertTrue;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;

import org.opengis.cite.gpkg12.CommonFixture;
import org.opengis.cite.gpkg12.ErrorMessage;
import org.opengis.cite.gpkg12.ErrorMessageKeys;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/**
* Defines test methods that verify a GeoPackage's content relating to
* attributes.
*
* <p style="margin-bottom: 0.5em">
* <strong>Sources</strong>
* </p>
* <ul>
* <li><a href="http://www.geopackage.org/spec/#attributes" target= "_blank">
* GeoPackage Encoding Standard - 2.4 Attributes</a> (OGC 12-128r13)</li>
* </ul>
*
* @author Brad Hards
*/
public class AttributeTests extends CommonFixture {

private final Collection<String> attributeTableNames = new ArrayList<>();

/**
* Shared setup.
*
* @throws SQLException if connection could not be established
*/
@BeforeClass
public void setUp() throws SQLException {
try (
final Statement statement = this.databaseConnection.createStatement();
final ResultSet resultSet = statement.executeQuery("SELECT table_name FROM gpkg_contents WHERE data_type = 'attributes'");) {
while (resultSet.next()) {
attributeTableNames.add(resultSet.getString(1));
}
}

Assert.assertTrue(!attributeTableNames.isEmpty(), ErrorMessage.format(ErrorMessageKeys.CONFORMANCE_CLASS_NOT_USED, getTestName()));
}

/**
* A GeoPackage MAY contain tables or updatable views containing attribute
* sets. Every such Attribute table or view in a GeoPackage SHALL have a
* column with column type INTEGER and PRIMARY KEY AUTOINCREMENT column
* constraints per GeoPackage Attributes Example Table or View Definition
* and EXAMPLE: Attributes table Create Table SQL (Informative).
*
* See Attribute User Data Tables - Requirement 119 and
* /opt/attributes/contents/data/attributes_row
*
* @throws SQLException If an SQL query causes an error
*/
@Test(description = "See OGC 12-128r14: Requirement 119")
public void attributeTableIntegerPrimaryKey() throws SQLException {
for (final String tableName : attributeTableNames) {
try (final Statement statement = databaseConnection.createStatement(); final ResultSet resultSet = statement.executeQuery(String.format("PRAGMA table_info(%s);", tableName));) {
assertTrue(resultSet.next(), ErrorMessage.format(ErrorMessageKeys.MISSING_TABLE, tableName));
}
checkPrimaryKey(tableName, getPrimaryKeyColumn(tableName));
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/opengis/cite/gpkg12/attributes/package-info.java
@@ -0,0 +1,17 @@
/**
* This package contains tests covering the <strong>attributes</strong> conformance class.
*
* A GeoPackage may contain attribute tables without geospatial locations, as well
* as containing tiles and features.
*
* <p style="margin-bottom: 0.5em">
* <strong>Sources</strong>
* </p>
* <ul>
* <li><a href="http://www.geopackage.org/spec/#_options" target="_blank">
* GeoPackage Encoding Standard - Options</a></li>
* <li><a href="http://www.geopackage.org/spec/#attributes" target="_blank">
* GeoPackage Encoding Standard - Attributes</a></li>
* </ul>
*/
package org.opengis.cite.gpkg12.attributes;
Expand Up @@ -28,7 +28,7 @@ NoSqlAccess = No available SQLite SQL API interface
SqliteOmitOptions = SQLite library compilations shall not include any OMIT options
TableDefinitionInvalid = The {0} table does not have a valid definition: {1}
MissingTable = The {0} table is missing.
TableNoPK = The features table {0} does not have a primary key.
TableNoPK = The features or attributes table {0} does not have a primary key.
TablePKNotUnique = The primary keys in table {0} are not unique.
BadSrsTableDefinition = Bad Spatial Reference System table (gpkg_spatial_ref_sys): {0}
NoGeographicSrs = The gpkg_spatial_ref_sys is missing a record for organization "EPSG" or "epsg" and organization_coordsys_id 4326
Expand Down
Expand Up @@ -28,7 +28,7 @@ NoSqlAccess = No available SQLite SQL API interface
SqliteOmitOptions = SQLite library compilations shall not include any OMIT options
TableDefinitionInvalid = The {0} table does not have a valid definition: {1}
MissingTable = The {0} table is missing.
TableNoPK = The features table {0} does not have a primary key.
TableNoPK = The features or attributes table {0} does not have a primary key.
TablePKNotUnique = The primary keys in table {0} are not unique.
BadSrsTableDefinition = Bad Spatial Reference System table (gpkg_spatial_ref_sys): {0}
NoGeographicSrs = The gpkg_spatial_ref_sys is missing a record for organization "EPSG" or "epsg" and organization_coordsys_id 4326
Expand Down
@@ -0,0 +1,59 @@
package org.opengis.cite.gpkg12.attributes;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.SQLException;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opengis.cite.gpkg12.SuiteAttribute;
import org.testng.ISuite;
import org.testng.ITestContext;

public class VerifyAttributeTests {

private static ITestContext testContext;
private static ISuite suite;
@Rule
public ExpectedException thrown = ExpectedException.none();

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

@Test
public void attributePrimarykey() throws IOException, SQLException, URISyntaxException {
URL gpkgUrl = ClassLoader.getSystemResource("gpkg/gdal_sample_v1.2_no_extensions.gpkg");
File dataFile = new File(gpkgUrl.toURI());
dataFile.setWritable(false);
when(suite.getAttribute(SuiteAttribute.TEST_SUBJ_FILE.getName())).thenReturn(dataFile);
AttributeTests iut = new AttributeTests();
iut.initCommonFixture(testContext);
iut.setUp();
iut.attributeTableIntegerPrimaryKey();
}

@Test
public void attributePrimarykeyBad() throws IOException, SQLException, URISyntaxException {
URL gpkgUrl = ClassLoader.getSystemResource("gpkg/v12_bad_attributes.gpkg");
File dataFile = new File(gpkgUrl.toURI());
dataFile.setWritable(false);
when(suite.getAttribute(SuiteAttribute.TEST_SUBJ_FILE.getName())).thenReturn(dataFile);
AttributeTests iut = new AttributeTests();
iut.initCommonFixture(testContext);
iut.setUp();
thrown.expect(AssertionError.class);
thrown.expectMessage("The features or attributes table attribute_table does not have a primary key. expected [true] but found [false]");
iut.attributeTableIntegerPrimaryKey();
}
}
Binary file not shown.