# HG changeset patch # User Panayiotis Smeros # Date 1364926675 -10800 # Node ID ffda52025190b364b82f8ac65a18e51196fad116 # Parent b628e51f9580fc70543754731ac474b4ef1a8ea0 Added first test in testsuite (not ready yet). diff -r b628e51f9580 -r ffda52025190 testsuite/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/pom.xml Tue Apr 02 21:17:55 2013 +0300 @@ -0,0 +1,31 @@ + + + 4.0.0 + + + eu.earthobservatory + strabon + 3.2.9-SNAPSHOT + + + strabon-testsuite + + Strabon: Test Suite + A test suite for Strabon + jar + + + + eu.earthobservatory + strabon-runtime + + + + + junit + junit + test + + + + \ No newline at end of file diff -r b628e51f9580 -r ffda52025190 testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java Tue Apr 02 21:17:55 2013 +0300 @@ -0,0 +1,173 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright (C) 2010, 2011, 2012, Pyravlos Team + * + * http://www.strabon.di.uoa.gr/ + */ +package eu.earthobservatory.runtime.postgis; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Connection; +import java.util.ArrayList; +import java.util.Properties; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.openrdf.repository.RepositoryException; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParseException; + + +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; +import eu.earthobservatory.runtime.generaldb.Strabon; + +import static org.junit.Assert.assertNull; + +/** + * A set of simple tests on SPARQL query functionality + * + * @author George Garbis + * @author Panayiotis Smeros + */ +public class TemplateTests { + + public static String databaseTemplateName = null; + public static String defaultUser = null; + public static String serverName = null; + public static String username = null; + public static String password = null; + public static Integer port = null; + + public static Connection conn = null; + public static String databaseName = null; + + @BeforeClass + public static Strabon beforeClass() throws Exception + { + String url=""; + ArrayList databases=new ArrayList(); + PreparedStatement pst = null; + + // Read properties + Properties properties = new Properties(); + InputStream propertiesStream = TemplateTests.class.getResourceAsStream("/databases.properties"); + properties.load(propertiesStream); + + databaseTemplateName = properties.getProperty("postgis.databaseTemplateName");; + defaultUser = properties.getProperty("postgis.defaultUser"); + serverName = properties.getProperty("postgis.serverName"); + username = properties.getProperty("postgis.username"); + password = properties.getProperty("postgis.password"); + port = Integer.parseInt(properties.getProperty("postgis.port")); + + //Connect to server and create the temp database + url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; + conn = DriverManager.getConnection(url, username, password); + assertNull(conn.getWarnings()); + + pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); + ResultSet rs = pst.executeQuery(); + + while (rs.next()) { + databases.add(rs.getString(1)); + } + rs.close(); + pst.close(); + + databaseName="teststrabon"+(int)(Math.random()*10000); + while(databases.contains(databaseName)){ + databaseName+="0"; + } + + + pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName); + pst.executeUpdate(); + pst.close(); + conn.close(); + + url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; + conn = DriverManager.getConnection(url, username, password); + assertNull(conn.getWarnings()); + + Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true); + + return strabon; + } + + + @AfterClass + public static void afterClass(Strabon strabon) throws SQLException + { + strabon.close(); + + //Drop the temp database + conn.close(); + String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; + conn = DriverManager.getConnection(url, username, password); + assertNull(conn.getWarnings()); + + PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName); + pst.executeUpdate(); + pst.close(); + conn.close(); + } + + + // Clean database +// Statement stmt = conn.createStatement(); +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + +// "table_schema='public' AND table_name <> 'spatial_ref_sys' " + +// "AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " + +// "AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " + +// "AND table_name <> 'locked'" +// ); +// while (results.next()) { +// String table_name = results.getString("table_name"); +// Statement stmt2 = conn.createStatement(); +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); +// stmt2.close(); +// } +// stmt.close(); + +// /** +// * @throws java.lang.Exception +// */ +// @Before +// public void before() +// throws Exception +// { +// +// } +// +// /** +// * @throws java.lang.Exception +// */ +// @After +// public void after() +// throws Exception +// { +// // Clean database +// Statement stmt = conn.createStatement(); +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + +// "and table_name <> 'geometry_columns' and " + +// "table_name <> 'geography_columns' and table_name <> 'locked'"); +// while (results.next()) { +// String table_name = results.getString("table_name"); +// Statement stmt2 = conn.createStatement(); +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); +// stmt2.close(); +// } +// +// stmt.close(); +// } +} diff -r b628e51f9580 -r ffda52025190 testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TestStore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TestStore.java Tue Apr 02 21:17:55 2013 +0300 @@ -0,0 +1,51 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright (C) 2010, 2011, 2012, Pyravlos Team + * + * http://www.strabon.di.uoa.gr/ + */ +package eu.earthobservatory.runtime.postgis; + +import java.io.IOException; +import java.sql.SQLException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openrdf.repository.RepositoryException; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParseException; +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; +import eu.earthobservatory.runtime.generaldb.Strabon; + +/** + * A set of simple tests on SPARQL query functionality + * + * @author Panayiotis Smeros "1"^^. + "2"^^. + "3"^^. + "10"^^. + "20"^^. + "POINT(1 0)"^^. + "POINT(2 0)"^^. + "POINT(3 0)"^^. diff -r b628e51f9580 -r ffda52025190 testsuite/src/test/resources/TestStore.rq --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/resources/TestStore.rq Tue Apr 02 21:17:55 2013 +0300 @@ -0,0 +1,2 @@ +SELECT * +WHERE{?s ?p ?o} \ No newline at end of file diff -r b628e51f9580 -r ffda52025190 testsuite/src/test/resources/databases.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/resources/databases.properties Tue Apr 02 21:17:55 2013 +0300 @@ -0,0 +1,14 @@ +# PostGIS +postgis.databaseTemplateName = template_postgis +postgis.defaultUser = postgres +postgis.serverName = localhost +postgis.username = postgres +postgis.password = postgres +postgis.port = 5432 + +! MonetDB +monetdb.databaseName = strabon-test +monetdb.serverName = localhost +monetdb.username = monetdb +monetdb.password = monetdb +monetdb.port = 50000