MARMOTTA-584: added test to check data with geometries correctly works with other detabases that do not have geosparql support
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/df2c80f0 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/df2c80f0 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/df2c80f0 Branch: refs/heads/MARMOTTA-584 Commit: df2c80f0e7c95a5e536e20db29b0e2cd0fc86237 Parents: 772261f Author: Sergio Fernández <[email protected]> Authored: Fri Jul 1 15:06:09 2016 +0200 Committer: Sergio Fernández <[email protected]> Committed: Fri Jul 1 15:06:09 2016 +0200 ---------------------------------------------------------------------- ...etriesImportInNotSupportedDatabasesTest.java | 108 +++++++++++++++++++ 1 file changed, 108 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/df2c80f0/libraries/kiwi/kiwi-geosparql/src/test/java/org/apache/marmotta/kiwi/sparql/geosparql/GeometriesImportInNotSupportedDatabasesTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-geosparql/src/test/java/org/apache/marmotta/kiwi/sparql/geosparql/GeometriesImportInNotSupportedDatabasesTest.java b/libraries/kiwi/kiwi-geosparql/src/test/java/org/apache/marmotta/kiwi/sparql/geosparql/GeometriesImportInNotSupportedDatabasesTest.java new file mode 100644 index 0000000..dc2be4e --- /dev/null +++ b/libraries/kiwi/kiwi-geosparql/src/test/java/org/apache/marmotta/kiwi/sparql/geosparql/GeometriesImportInNotSupportedDatabasesTest.java @@ -0,0 +1,108 @@ +package org.apache.marmotta.kiwi.sparql.geosparql; + +import org.apache.marmotta.kiwi.config.KiWiConfiguration; +import org.apache.marmotta.kiwi.persistence.h2.H2Dialect; +import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect; +import org.apache.marmotta.kiwi.sail.KiWiStore; +import org.apache.marmotta.kiwi.sparql.sail.KiWiSparqlSail; +import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker; +import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.rio.RDFFormat; +import org.openrdf.rio.RDFParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.sql.SQLException; + +/** + * Test that geo-data imports in the geosparql non-supported databases + * + * @author Sergio Fernández ([email protected]) + */ +@RunWith(KiWiDatabaseRunner.class) [email protected]({H2Dialect.class,MySQLDialect.class}) +public class GeometriesImportInNotSupportedDatabasesTest { + + final Logger log = LoggerFactory.getLogger(this.getClass()); + + private KiWiStore store; + private Repository repository; + + private final KiWiConfiguration dbConfig; + + public GeometriesImportInNotSupportedDatabasesTest(KiWiConfiguration dbConfig) { + this.dbConfig = dbConfig; + dbConfig.setFulltextEnabled(true); + dbConfig.setFulltextLanguages(new String[] {"en"}); + DBConnectionChecker.checkDatabaseAvailability(dbConfig); + } + + @Before + public void initDatabase() throws RepositoryException, IOException, RDFParseException { + store = new KiWiStore(dbConfig); + store.setDropTablesOnShutdown(true); + repository = new SailRepository(new KiWiSparqlSail(store)); + repository.initialize(); + + log.info("load some to test..."); + final RepositoryConnection conn = repository.getConnection(); + try { + conn.begin(); + conn.add(this.getClass().getResourceAsStream("/demo_data_spain_provinces.rdf"), "http://localhost/test/geosparql", RDFFormat.RDFXML); + conn.add(this.getClass().getResourceAsStream("/demo_data_spain_towns.rdf"), "http://localhost/test/geosparql", RDFFormat.RDFXML); + conn.add(this.getClass().getResourceAsStream("/demo_data_spain_rivers.rdf"), "http://localhost/test/geosparql", RDFFormat.RDFXML); + conn.commit(); + } finally { + conn.close(); + } + } + + @After + public void dropDatabase() throws RepositoryException, SQLException { + if (store != null && store.isInitialized()) { + log.info("cleaning up test setup..."); + store.getPersistence().dropDatabase(); + repository.shutDown(); + store = null; + repository = null; + } + } + + private void testLoadFile(String path) throws RepositoryException, IOException, RDFParseException { + log.info("load test data from {}....", path); + final RepositoryConnection conn = repository.getConnection(); + try { + conn.begin(); + conn.add(this.getClass().getResourceAsStream(path), "http://localhost/test", RDFFormat.RDFXML); + conn.commit(); + //TODO: check size + } finally { + conn.close(); + } + } + + @Test + public void testSpainshProvices() throws RepositoryException, IOException, RDFParseException { + testLoadFile("/demo_data_spain_provinces.rdf"); + } + + @Test + public void testSpainshTowns() throws RepositoryException, IOException, RDFParseException { + testLoadFile("/demo_data_spain_towns.rdf"); + } + + @Test + public void testSpainshRivers() throws RepositoryException, IOException, RDFParseException { + testLoadFile("/demo_data_spain_rivers.rdf"); + } + +}
