Strabon

changeset 729:b27eb70e7bd6 temporals

Added some tests.
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Thu Nov 22 19:25:28 2012 +0200 (2012-11-22)
parents f0527de6dfb7
children 35884bc15005
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/QueryRewritingTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemplateTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemporalSelectionTests.java runtime/src/test/resources/databases.properties
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Nov 22 16:51:51 2012 +0200
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Nov 22 19:25:28 2012 +0200
     1.3 @@ -279,9 +279,8 @@
     1.4  		return status;
     1.5  	}
     1.6  
     1.7 -	private String queryRewriting(String queryString) 
     1.8 -	{	
     1.9 -		//TODO
    1.10 +	public String queryRewriting(String queryString) 
    1.11 +	{
    1.12  		String newQueryString="";
    1.13  		int numOfQuadruples=0;
    1.14  		int startIndex=0;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/QueryRewritingTests.java	Thu Nov 22 19:25:28 2012 +0200
     2.3 @@ -0,0 +1,99 @@
     2.4 +/**
     2.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     2.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     2.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.8 + * 
     2.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team
    2.10 + * 
    2.11 + * http://www.strabon.di.uoa.gr/
    2.12 + */
    2.13 +package eu.earthobservatory.runtime.postgis.temporals;
    2.14 +
    2.15 +
    2.16 +
    2.17 +import java.io.IOException;
    2.18 +import java.sql.SQLException;
    2.19 +import org.junit.AfterClass;
    2.20 +import org.junit.BeforeClass;
    2.21 +import org.junit.Test;
    2.22 +import org.openrdf.query.MalformedQueryException;
    2.23 +import org.openrdf.query.QueryEvaluationException;
    2.24 +import org.openrdf.query.TupleQueryResultHandlerException;
    2.25 +import org.openrdf.repository.RepositoryException;
    2.26 +import org.openrdf.rio.RDFHandlerException;
    2.27 +import org.openrdf.rio.RDFParseException;
    2.28 +
    2.29 +
    2.30 +import eu.earthobservatory.runtime.generaldb.*;
    2.31 +import eu.earthobservatory.runtime.postgis.temporals.TemplateTests;
    2.32 +
    2.33 +
    2.34 +/**
    2.35 + * A set of simple tests on query rewriting functionality 
    2.36 + * 
    2.37 + * @author Panayiotis Smeros <psmeros@di.uoa.gr>
    2.38 + */
    2.39 +public class QueryRewritingTests {
    2.40 +
    2.41 +	protected static Strabon strabon;
    2.42 +	
    2.43 +	protected static final String prefixes = 
    2.44 +		"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
    2.45 +		"PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> \n" +
    2.46 +		"PREFIX ex: <http://example.org/> \n" +
    2.47 +		"PREFIX xs: <http://www.w3.org/2001/XMLSchema#> \n" +
    2.48 +		"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" +
    2.49 +		"PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> \n";
    2.50 +
    2.51 +	
    2.52 +	@BeforeClass
    2.53 +	public static void beforeClass() throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault
    2.54 +	{
    2.55 +		strabon = TemplateTests.beforeClass("/temporal-selection-tests.nq","NQUADS");
    2.56 +	}
    2.57 +	
    2.58 +	@AfterClass
    2.59 +	public static void afterClass() throws SQLException
    2.60 +	{
    2.61 +		TemplateTests.afterClass(strabon);
    2.62 +	}
    2.63 +	
    2.64 +	
    2.65 +	
    2.66 +	@Test
    2.67 +	public void testQueryRewriting1() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException
    2.68 +	{
    2.69 +	
    2.70 +		String query = 
    2.71 +			prefixes+
    2.72 +			"SELECT ?geo1 "+ 
    2.73 +			"WHERE { "+
    2.74 +				"?x strdf:hasGeometry ?geo1 . "+
    2.75 +				"?y strdf:hasGeometry ?geo2 . "+
    2.76 +				"FILTER(strdf:intersects(?geo1, ?geo2))."+
    2.77 +				"}";
    2.78 +		
    2.79 +		System.out.println(strabon.queryRewriting(query));
    2.80 +	}
    2.81 +	
    2.82 +
    2.83 +	@Test
    2.84 +	public void testQueryRewriting2() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException
    2.85 +	{
    2.86 +	
    2.87 +		String query = 
    2.88 +			prefixes+
    2.89 +			"select ?geo ?s1 ?s2 " +
    2.90 +			"where {" +
    2.91 +			"?s1  ?p1 ?o1 ?t1 ." +
    2.92 +			" ?s2  ?p2 ?o2 ?t2 ." +
    2.93 +			"?x strdf:hasGeometry ?geo1 ." +
    2.94 +			"?y strdf:hasGeometry ?geo2." +
    2.95 +			"FILTER(strdf:intersects(?geo1,?geo2))." +
    2.96 +			"   FILTER(strdf:afterPeriod(?t1,?t2))}";	
    2.97 +		
    2.98 +		System.out.println(strabon.queryRewriting(query));
    2.99 +	}
   2.100 +
   2.101 +
   2.102 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemplateTests.java	Thu Nov 22 19:25:28 2012 +0200
     3.3 @@ -0,0 +1,97 @@
     3.4 +/**
     3.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     3.8 + * 
     3.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team
    3.10 + * 
    3.11 + * http://www.strabon.di.uoa.gr/
    3.12 + */
    3.13 +package eu.earthobservatory.runtime.postgis.temporals;
    3.14 +
    3.15 +import java.io.IOException;
    3.16 +import java.io.InputStream;
    3.17 +import java.sql.DriverManager;
    3.18 +import java.sql.ResultSet;
    3.19 +import java.sql.SQLException;
    3.20 +import java.sql.Statement;
    3.21 +import java.util.Properties;
    3.22 +
    3.23 +import org.junit.AfterClass;
    3.24 +import org.junit.BeforeClass;
    3.25 +import org.openrdf.repository.RepositoryException;
    3.26 +import org.openrdf.rio.RDFHandlerException;
    3.27 +import org.openrdf.rio.RDFParseException;
    3.28 +
    3.29 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    3.30 +import eu.earthobservatory.runtime.generaldb.SimpleTests;
    3.31 +import eu.earthobservatory.runtime.generaldb.Strabon;
    3.32 +
    3.33 +/**
    3.34 + * A set of simple tests on SPARQL query functionality 
    3.35 + * 
    3.36 + * @author Panayiotis Smeros <psmeros@di.uoa.gr>
    3.37 + */
    3.38 +public class TemplateTests {
    3.39 +	
    3.40 +	public static java.sql.Connection conn = null;
    3.41 +	public static String databaseName = null;
    3.42 +	public static String jdbcDriver = null;
    3.43 +	public static String serverName = null;
    3.44 +	public static String username = null;
    3.45 +	public static String password = null;
    3.46 +	public static Integer port = null;
    3.47 +	
    3.48 +	@BeforeClass
    3.49 +	public static Strabon beforeClass(String inputFile, String format)
    3.50 +		throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault
    3.51 +	{
    3.52 +		// Read properties
    3.53 +		Properties properties = new Properties();
    3.54 +		InputStream propertiesStream =  SimpleTests.class.getResourceAsStream("/databases.properties");
    3.55 +		properties.load(propertiesStream);
    3.56 +
    3.57 +		serverName = properties.getProperty("temporal.postgis.serverName");
    3.58 +		databaseName = properties.getProperty("temporal.postgis.databaseName");
    3.59 +		port = Integer.parseInt(properties.getProperty("temporal.postgis.port"));
    3.60 +		username = properties.getProperty("temporal.postgis.username");
    3.61 +		password = properties.getProperty("temporal.postgis.password");
    3.62 +		
    3.63 +		// Connect to database
    3.64 +		Class.forName("org.postgresql.Driver");
    3.65 +		String url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName;
    3.66 +		conn = DriverManager.getConnection(url, username, password);
    3.67 +				
    3.68 +//		// Clean database
    3.69 +		Statement stmt = conn.createStatement();
    3.70 +		ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " +
    3.71 +						"table_schema='public' AND table_name <> 'spatial_ref_sys' " +
    3.72 +						"AND table_name <> 'geometry_columns' AND " +
    3.73 +						"table_name <> 'geography_columns' AND table_name <> 'locked'");
    3.74 +		while (results.next()) {
    3.75 +			String table_name = results.getString("table_name");
    3.76 +			Statement stmt2 = conn.createStatement();
    3.77 +			stmt2.executeUpdate("DROP TABLE \""+table_name+"\"");
    3.78 +			stmt2.close();
    3.79 +		}
    3.80 +		stmt.close();
    3.81 +		
    3.82 +	    Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true);
    3.83 +		
    3.84 +		loadTestData(inputFile, strabon, format);
    3.85 +		
    3.86 +		return strabon;
    3.87 +	}
    3.88 +	
    3.89 +	@AfterClass
    3.90 +	public static void afterClass(Strabon strabon) throws SQLException
    3.91 +	{
    3.92 +		strabon.close();
    3.93 +	}
    3.94 +	
    3.95 +	protected static void loadTestData(String inputfile, Strabon strabon, String format)
    3.96 +		throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault
    3.97 +	{
    3.98 +		strabon.storeInRepo(inputfile, format);
    3.99 +	}
   3.100 +}
     4.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemporalSelectionTests.java	Thu Nov 22 16:51:51 2012 +0200
     4.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemporalSelectionTests.java	Thu Nov 22 19:25:28 2012 +0200
     4.3 @@ -6,18 +6,93 @@
     4.4   * Copyright (C) 2010, 2011, 2012, Pyravlos Team
     4.5   * 
     4.6   * http://www.strabon.di.uoa.gr/
     4.7 + */
     4.8 +package eu.earthobservatory.runtime.postgis.temporals;
     4.9 +
    4.10 +
    4.11 +
    4.12 +import static org.junit.Assert.assertEquals;
    4.13 +
    4.14 +import java.io.IOException;
    4.15 +import java.sql.SQLException;
    4.16 +import java.util.ArrayList;
    4.17 +
    4.18 +import org.junit.AfterClass;
    4.19 +import org.junit.BeforeClass;
    4.20 +import org.junit.Test;
    4.21 +import org.openrdf.query.MalformedQueryException;
    4.22 +import org.openrdf.query.QueryEvaluationException;
    4.23 +import org.openrdf.query.TupleQueryResultHandlerException;
    4.24 +import org.openrdf.repository.RepositoryException;
    4.25 +import org.openrdf.rio.RDFHandlerException;
    4.26 +import org.openrdf.rio.RDFParseException;
    4.27 +
    4.28 +
    4.29 +import eu.earthobservatory.runtime.generaldb.*;
    4.30 +import eu.earthobservatory.runtime.postgis.temporals.TemplateTests;
    4.31 +
    4.32 +
    4.33 +/**
    4.34 + * A set of simple tests on temporal selection functionality 
    4.35   * 
    4.36   * @author Panayiotis Smeros <psmeros@di.uoa.gr>
    4.37   */
    4.38 -package eu.earthobservatory.runtime.postgis.temporals;
    4.39 +public class TemporalSelectionTests {
    4.40  
    4.41 +	protected static Strabon strabon;
    4.42 +	
    4.43 +	protected static final String prefixes = 
    4.44 +		"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
    4.45 +		"PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> \n" +
    4.46 +		"PREFIX ex: <http://example.org/> \n" +
    4.47 +		"PREFIX xs: <http://www.w3.org/2001/XMLSchema#> \n" +
    4.48 +		"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" +
    4.49 +		"PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> \n";
    4.50  
    4.51 +	
    4.52 +	@BeforeClass
    4.53 +	public static void beforeClass() throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault
    4.54 +	{
    4.55 +		strabon = TemplateTests.beforeClass("/temporal-selection-tests.nq","NQUADS");
    4.56 +	}
    4.57 +	
    4.58 +	@AfterClass
    4.59 +	public static void afterClass() throws SQLException
    4.60 +	{
    4.61 +		TemplateTests.afterClass(strabon);
    4.62 +	}
    4.63 +	
    4.64 +	
    4.65 +	
    4.66 +	@Test
    4.67 +	public void testSPOTQuery() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException
    4.68 +	{
    4.69 +	
    4.70 +		String query = 
    4.71 +			prefixes+
    4.72 +			"SELECT * "+ 
    4.73 +			"WHERE { "+
    4.74 +				"?s ?p ?o ?t. "+
    4.75 +			"}";
    4.76 +		
    4.77 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    4.78 +		assertEquals(8, bindings.size());
    4.79 +	}
    4.80  
    4.81 -/**
    4.82 - * A set of simple tests on Temporal Selection functionality 
    4.83 - * 
    4.84 - */
    4.85 -public class TemporalSelectionTests {
    4.86 +
    4.87 +	@Test
    4.88 +	public void testSPOQuery() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException
    4.89 +	{
    4.90  	
    4.91 -
    4.92 +		String query = 
    4.93 +			prefixes+
    4.94 +			"SELECT * "+ 
    4.95 +			"WHERE { "+
    4.96 +				"?s ?p ?o. "+
    4.97 +			"}";
    4.98 +		
    4.99 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
   4.100 +		System.out.println(bindings);
   4.101 +		assertEquals(9, bindings.size());
   4.102 +	}
   4.103  }
     5.1 --- a/runtime/src/test/resources/databases.properties	Thu Nov 22 16:51:51 2012 +0200
     5.2 +++ b/runtime/src/test/resources/databases.properties	Thu Nov 22 19:25:28 2012 +0200
     5.3 @@ -11,3 +11,10 @@
     5.4  monetdb.username = monetdb
     5.5  monetdb.password = monetdb
     5.6  monetdb.port = 50000
     5.7 +
     5.8 +# PostGIS-Temporal
     5.9 +temporal.postgis.databaseName = endpoint_temporal
    5.10 +temporal.postgis.serverName = localhost
    5.11 +temporal.postgis.username = postgres
    5.12 +temporal.postgis.password = postgres
    5.13 +temporal.postgis.port = 5432
    5.14 \ No newline at end of file