Strabon
changeset 859:6016672577e9 temporals
added the actual files and did some refactoring
author | Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> |
---|---|
date | Tue Jan 15 12:07:55 2013 +0200 (2013-01-15) |
parents | 3026011383cc |
children | 2ee96133646a |
files | 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/java/eu/earthobservatory/runtime/postgres/temporals/QueryRewritingTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemplateTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalRelationTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalSelectionTests.java |
line diff
1.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemplateTests.java Mon Jan 14 19:42:11 2013 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,97 +0,0 @@ 1.4 -/** 1.5 - * This Source Code Form is subject to the terms of the Mozilla Public 1.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 - * 1.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 1.10 - * 1.11 - * http://www.strabon.di.uoa.gr/ 1.12 - */ 1.13 -package eu.earthobservatory.runtime.postgis.temporals; 1.14 - 1.15 -import java.io.IOException; 1.16 -import java.io.InputStream; 1.17 -import java.sql.DriverManager; 1.18 -import java.sql.ResultSet; 1.19 -import java.sql.SQLException; 1.20 -import java.sql.Statement; 1.21 -import java.util.Properties; 1.22 - 1.23 -import org.junit.AfterClass; 1.24 -import org.junit.BeforeClass; 1.25 -import org.openrdf.repository.RepositoryException; 1.26 -import org.openrdf.rio.RDFHandlerException; 1.27 -import org.openrdf.rio.RDFParseException; 1.28 - 1.29 -import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 1.30 -import eu.earthobservatory.runtime.generaldb.SimpleTests; 1.31 -import eu.earthobservatory.runtime.generaldb.Strabon; 1.32 - 1.33 -/** 1.34 - * A set of simple tests on SPARQL query functionality 1.35 - * 1.36 - * @author Panayiotis Smeros <psmeros@di.uoa.gr> 1.37 - */ 1.38 -public class TemplateTests { 1.39 - 1.40 - public static java.sql.Connection conn = null; 1.41 - public static String databaseName = null; 1.42 - public static String jdbcDriver = null; 1.43 - public static String serverName = null; 1.44 - public static String username = null; 1.45 - public static String password = null; 1.46 - public static Integer port = null; 1.47 - 1.48 - @BeforeClass 1.49 - public static Strabon beforeClass(String inputFile, String format) 1.50 - throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 1.51 - { 1.52 - // Read properties 1.53 - Properties properties = new Properties(); 1.54 - InputStream propertiesStream = SimpleTests.class.getResourceAsStream("/databases.properties"); 1.55 - properties.load(propertiesStream); 1.56 - 1.57 - serverName = properties.getProperty("temporal.postgis.serverName"); 1.58 - databaseName = properties.getProperty("temporal.postgis.databaseName"); 1.59 - port = Integer.parseInt(properties.getProperty("temporal.postgis.port")); 1.60 - username = properties.getProperty("temporal.postgis.username"); 1.61 - password = properties.getProperty("temporal.postgis.password"); 1.62 - 1.63 - // Connect to database 1.64 - Class.forName("org.postgresql.Driver"); 1.65 - String url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; 1.66 - conn = DriverManager.getConnection(url, username, password); 1.67 - 1.68 -// // Clean database 1.69 - Statement stmt = conn.createStatement(); 1.70 - ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 1.71 - "table_schema='public' AND table_name <> 'spatial_ref_sys' " + 1.72 - "AND table_name <> 'geometry_columns' AND " + 1.73 - "table_name <> 'geography_columns' AND table_name <> 'locked'"); 1.74 - while (results.next()) { 1.75 - String table_name = results.getString("table_name"); 1.76 - Statement stmt2 = conn.createStatement(); 1.77 - stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 1.78 - stmt2.close(); 1.79 - } 1.80 - stmt.close(); 1.81 - 1.82 - Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true); 1.83 - 1.84 - loadTestData(inputFile, strabon, format); 1.85 - 1.86 - return strabon; 1.87 - } 1.88 - 1.89 - @AfterClass 1.90 - public static void afterClass(Strabon strabon) throws SQLException 1.91 - { 1.92 - strabon.close(); 1.93 - } 1.94 - 1.95 - protected static void loadTestData(String inputfile, Strabon strabon, String format) 1.96 - throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault 1.97 - { 1.98 - strabon.storeInRepo(inputfile, format); 1.99 - } 1.100 -}
2.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/temporals/TemporalSelectionTests.java Mon Jan 14 19:42:11 2013 +0200 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,97 +0,0 @@ 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 static org.junit.Assert.assertEquals; 2.18 - 2.19 -import java.io.IOException; 2.20 -import java.sql.SQLException; 2.21 -import java.util.ArrayList; 2.22 - 2.23 -import org.junit.AfterClass; 2.24 -import org.junit.BeforeClass; 2.25 -import org.junit.Test; 2.26 -import org.openrdf.query.MalformedQueryException; 2.27 -import org.openrdf.query.QueryEvaluationException; 2.28 -import org.openrdf.query.TupleQueryResultHandlerException; 2.29 -import org.openrdf.repository.RepositoryException; 2.30 -import org.openrdf.rio.RDFHandlerException; 2.31 -import org.openrdf.rio.RDFParseException; 2.32 - 2.33 - 2.34 -import eu.earthobservatory.runtime.generaldb.*; 2.35 -import eu.earthobservatory.runtime.postgis.temporals.TemplateTests; 2.36 - 2.37 - 2.38 -/** 2.39 - * A set of simple tests on temporal selection functionality 2.40 - * 2.41 - * @author Panayiotis Smeros <psmeros@di.uoa.gr> 2.42 - */ 2.43 -public class TemporalSelectionTests { 2.44 - 2.45 - protected static Strabon strabon; 2.46 - 2.47 - protected static final String prefixes = 2.48 - "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + 2.49 - "PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> \n" + 2.50 - "PREFIX ex: <http://example.org/> \n" + 2.51 - "PREFIX xs: <http://www.w3.org/2001/XMLSchema#> \n" + 2.52 - "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" + 2.53 - "PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> \n"; 2.54 - 2.55 - 2.56 - @BeforeClass 2.57 - public static void beforeClass() throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 2.58 - { 2.59 - strabon = TemplateTests.beforeClass("/temporal-selection-tests.nq","NQUADS"); 2.60 - } 2.61 - 2.62 - @AfterClass 2.63 - public static void afterClass() throws SQLException 2.64 - { 2.65 - TemplateTests.afterClass(strabon); 2.66 - } 2.67 - 2.68 - 2.69 - 2.70 - @Test 2.71 - public void testSPOTQuery() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 2.72 - { 2.73 - 2.74 - String query = 2.75 - prefixes+ 2.76 - "SELECT * "+ 2.77 - "WHERE { "+ 2.78 - "?s ?p ?o ?t. "+ 2.79 - "}"; 2.80 - 2.81 - ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 2.82 - assertEquals(8, bindings.size()); 2.83 - } 2.84 - 2.85 - 2.86 - @Test 2.87 - public void testSPOQuery() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 2.88 - { 2.89 - 2.90 - String query = 2.91 - prefixes+ 2.92 - "SELECT * "+ 2.93 - "WHERE { "+ 2.94 - "?s ?p ?o. "+ 2.95 - "}"; 2.96 - 2.97 - ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 2.98 - assertEquals(9, bindings.size()); 2.99 - } 2.100 -}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/QueryRewritingTests.java Tue Jan 15 12:07:55 2013 +0200 3.3 @@ -0,0 +1,156 @@ 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.postgres.temporals; 3.14 + 3.15 + 3.16 + 3.17 +import static org.junit.Assert.assertEquals; 3.18 + 3.19 +import java.io.IOException; 3.20 +import java.sql.SQLException; 3.21 +import org.junit.AfterClass; 3.22 +import org.junit.BeforeClass; 3.23 +import org.junit.Test; 3.24 +import org.openrdf.query.MalformedQueryException; 3.25 +import org.openrdf.query.QueryEvaluationException; 3.26 +import org.openrdf.query.TupleQueryResultHandlerException; 3.27 +import org.openrdf.repository.RepositoryException; 3.28 +import org.openrdf.rio.RDFHandlerException; 3.29 +import org.openrdf.rio.RDFParseException; 3.30 + 3.31 + 3.32 +import eu.earthobservatory.runtime.generaldb.*; 3.33 +import eu.earthobservatory.runtime.postgres.temporals.TemplateTests; 3.34 + 3.35 + 3.36 +/** 3.37 + * A set of simple tests on query rewriting functionality 3.38 + * 3.39 + * @author Panayiotis Smeros <psmeros@di.uoa.gr> 3.40 + */ 3.41 +public class QueryRewritingTests { 3.42 + 3.43 + protected static Strabon strabon; 3.44 + 3.45 + protected static final String prefixes = 3.46 + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + 3.47 + "PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> \n" + 3.48 + "PREFIX ex: <http://example.org/> \n" + 3.49 + "PREFIX xs: <http://www.w3.org/2001/XMLSchema#> \n" + 3.50 + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" + 3.51 + "PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> \n"; 3.52 + 3.53 + 3.54 + @BeforeClass 3.55 + public static void beforeClass() throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 3.56 + { 3.57 + strabon = TemplateTests.beforeClass("/temporal-selection-tests.nq","NQUADS"); 3.58 + } 3.59 + 3.60 + @AfterClass 3.61 + public static void afterClass() throws SQLException 3.62 + { 3.63 + TemplateTests.afterClass(strabon); 3.64 + } 3.65 + 3.66 + 3.67 + 3.68 + @Test 3.69 + public void testQueryRewriting1() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 3.70 + { 3.71 + 3.72 + String query = 3.73 + prefixes+ 3.74 + "SELECT ?geo1 "+ 3.75 + "WHERE { "+ 3.76 + "?x strdf:hasGeometry ?geo1 . "+ 3.77 + "?y strdf:hasGeometry ?geo2 . "+ 3.78 + "FILTER(strdf:intersects(?geo1, ?geo2))."+ 3.79 + "}"; 3.80 + 3.81 + String [] querySplit=strabon.queryRewriting(query).split("GRAPH"); 3.82 + assertEquals(1, querySplit.length); 3.83 + } 3.84 + 3.85 + 3.86 + @Test 3.87 + public void testQueryRewriting2() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 3.88 + { 3.89 + 3.90 + String query = 3.91 + prefixes+ 3.92 + "select ?geo ?s1 ?s2 " + 3.93 + "where {" + 3.94 + "?s1 ?p1 ?o1 ?t1 ." + 3.95 + " ?s2 ?p2 ?o2 ?t2 ." + 3.96 + "?x strdf:hasGeometry ?geo1 ." + 3.97 + "?y strdf:hasGeometry ?geo2." + 3.98 + "FILTER(strdf:intersects(?geo1,?geo2))." + 3.99 + " FILTER(strdf:afterPeriod(?t1,?t2))}"; 3.100 + 3.101 + String [] querySplit=strabon.queryRewriting(query).split("GRAPH"); 3.102 + assertEquals(3, querySplit.length); 3.103 + } 3.104 + 3.105 + 3.106 + @Test 3.107 + public void testQueryRewriting3() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 3.108 + { 3.109 + 3.110 + String query = 3.111 + prefixes+ 3.112 + "select ?s1 " + 3.113 + "where { " + 3.114 + "?s1 ?p1 ?o1 ?t1 ." + 3.115 + "?s2 ?p2 ?o2 ?t2 ." + 3.116 + "?x1 <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> ?geo1. " + 3.117 + "?x2 <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> ?geo2. " + 3.118 + "FILTER(strdf:disjoint(?geo1,?geo2))" + 3.119 + "FILTER(strdf:afterPeriod(?t1, ?t2))."; 3.120 + 3.121 + String [] querySplit=strabon.queryRewriting(query).split("GRAPH"); 3.122 + assertEquals(3, querySplit.length); 3.123 + } 3.124 + 3.125 + @Test 3.126 + public void testQueryRewriting4() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 3.127 + { 3.128 + 3.129 + String query = 3.130 + prefixes+ 3.131 + "select distinct ?s1 ?s2 " + 3.132 + "where {" + 3.133 + "?s1 ?p1 ?ro1 ?o1 ." + 3.134 + "#?s2 ?p2 ?ro2 ?o2 . \n" + 3.135 + "FILTER(strdf:PeriodOverlaps(?o1, \"[2012-11-19 12:41:00+02, 2012-11-19 13:41:00.000001+02]\"^^<http://strdf.di.uoa.gr/ontology#validTime> ))" + 3.136 + "}"; 3.137 + 3.138 + String [] querySplit=strabon.queryRewriting(query).split("GRAPH"); 3.139 + assertEquals(2, querySplit.length); 3.140 + } 3.141 + 3.142 + 3.143 + @Test 3.144 + public void testQueryRewriting5() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 3.145 + { 3.146 + 3.147 + String query = 3.148 + prefixes+ 3.149 + "select distinct ?s1 ?s2 " + 3.150 + "where {" + 3.151 + "?s1 ?p1 ?ro1 ?o1 . " + 3.152 + "FILTER(strdf:PeriodOverlaps(?o1, \"[2012-11-19 12:41:00+02, 2012-11-19 13:41:00.000001+02]\"^^<http://strdf.di.uoa.gr/ontology#validTime>)) " + 3.153 + "#FILTER(strdf:PeriodOverlaps(?o1, \"Now\"^^<http://strdf.di.uoa.gr/ontology#validTime> )) \n " + 3.154 + "}"; 3.155 + 3.156 + String [] querySplit=strabon.queryRewriting(query).split("GRAPH"); 3.157 + assertEquals(2, querySplit.length); 3.158 + } 3.159 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemplateTests.java Tue Jan 15 12:07:55 2013 +0200 4.3 @@ -0,0 +1,97 @@ 4.4 +/** 4.5 + * This Source Code Form is subject to the terms of the Mozilla Public 4.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 4.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4.8 + * 4.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 4.10 + * 4.11 + * http://www.strabon.di.uoa.gr/ 4.12 + */ 4.13 +package eu.earthobservatory.runtime.postgres.temporals; 4.14 + 4.15 +import java.io.IOException; 4.16 +import java.io.InputStream; 4.17 +import java.sql.DriverManager; 4.18 +import java.sql.ResultSet; 4.19 +import java.sql.SQLException; 4.20 +import java.sql.Statement; 4.21 +import java.util.Properties; 4.22 + 4.23 +import org.junit.AfterClass; 4.24 +import org.junit.BeforeClass; 4.25 +import org.openrdf.repository.RepositoryException; 4.26 +import org.openrdf.rio.RDFHandlerException; 4.27 +import org.openrdf.rio.RDFParseException; 4.28 + 4.29 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 4.30 +import eu.earthobservatory.runtime.generaldb.SimpleTests; 4.31 +import eu.earthobservatory.runtime.generaldb.Strabon; 4.32 + 4.33 +/** 4.34 + * A set of simple tests on SPARQL query functionality 4.35 + * 4.36 + * @author Panayiotis Smeros <psmeros@di.uoa.gr> 4.37 + */ 4.38 +public class TemplateTests { 4.39 + 4.40 + public static java.sql.Connection conn = null; 4.41 + public static String databaseName = null; 4.42 + public static String jdbcDriver = null; 4.43 + public static String serverName = null; 4.44 + public static String username = null; 4.45 + public static String password = null; 4.46 + public static Integer port = null; 4.47 + 4.48 + @BeforeClass 4.49 + public static Strabon beforeClass(String inputFile, String format) 4.50 + throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 4.51 + { 4.52 + // Read properties 4.53 + Properties properties = new Properties(); 4.54 + InputStream propertiesStream = SimpleTests.class.getResourceAsStream("/databases.properties"); 4.55 + properties.load(propertiesStream); 4.56 + 4.57 + serverName = properties.getProperty("temporal.postgis.serverName"); 4.58 + databaseName = properties.getProperty("temporal.postgis.databaseName"); 4.59 + port = Integer.parseInt(properties.getProperty("temporal.postgis.port")); 4.60 + username = properties.getProperty("temporal.postgis.username"); 4.61 + password = properties.getProperty("temporal.postgis.password"); 4.62 + 4.63 + // Connect to database 4.64 + Class.forName("org.postgresql.Driver"); 4.65 + String url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; 4.66 + conn = DriverManager.getConnection(url, username, password); 4.67 + 4.68 +// // Clean database 4.69 + Statement stmt = conn.createStatement(); 4.70 + ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 4.71 + "table_schema='public' AND table_name <> 'spatial_ref_sys' " + 4.72 + "AND table_name <> 'geometry_columns' AND " + 4.73 + "table_name <> 'geography_columns' AND table_name <> 'locked'"); 4.74 + while (results.next()) { 4.75 + String table_name = results.getString("table_name"); 4.76 + Statement stmt2 = conn.createStatement(); 4.77 + stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 4.78 + stmt2.close(); 4.79 + } 4.80 + stmt.close(); 4.81 + 4.82 + Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true); 4.83 + 4.84 + loadTestData(inputFile, strabon, format); 4.85 + 4.86 + return strabon; 4.87 + } 4.88 + 4.89 + @AfterClass 4.90 + public static void afterClass(Strabon strabon) throws SQLException 4.91 + { 4.92 + strabon.close(); 4.93 + } 4.94 + 4.95 + protected static void loadTestData(String inputfile, Strabon strabon, String format) 4.96 + throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault 4.97 + { 4.98 + strabon.storeInRepo(inputfile, format); 4.99 + } 4.100 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalRelationTests.java Tue Jan 15 12:07:55 2013 +0200 5.3 @@ -0,0 +1,441 @@ 5.4 +/** 5.5 + * This Source Code Form is subject to the terms of the Mozilla Public 5.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 5.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5.8 + * 5.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 5.10 + * 5.11 + * http://www.strabon.di.uoa.gr/ 5.12 + */ 5.13 + 5.14 +/** 5.15 + * A set of simple tests on temporal selection functionality 5.16 + * 5.17 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> 5.18 + * 5.19 + * This class includes a set of junit tests that test the temporal relations between periods 5.20 + */ 5.21 + 5.22 +package eu.earthobservatory.runtime.postgres.temporals; 5.23 + 5.24 + 5.25 +import static org.junit.Assert.*; 5.26 + 5.27 +import java.io.IOException; 5.28 +import java.sql.SQLException; 5.29 +import java.util.ArrayList; 5.30 + 5.31 +import org.junit.AfterClass; 5.32 +import org.junit.BeforeClass; 5.33 +import org.junit.Test; 5.34 +import org.openrdf.query.MalformedQueryException; 5.35 +import org.openrdf.query.QueryEvaluationException; 5.36 +import org.openrdf.query.TupleQueryResult; 5.37 +import org.openrdf.query.TupleQueryResultHandlerException; 5.38 +import org.openrdf.query.resultio.Format; 5.39 +import org.openrdf.query.resultio.TupleQueryResultWriter; 5.40 +import org.openrdf.query.resultio.stSPARQLQueryResultWriterFactory; 5.41 +import org.openrdf.repository.RepositoryException; 5.42 +import org.openrdf.rio.RDFHandlerException; 5.43 +import org.openrdf.rio.RDFParseException; 5.44 + 5.45 + 5.46 +import eu.earthobservatory.runtime.generaldb.*; 5.47 +import eu.earthobservatory.runtime.postgres.temporals.TemplateTests; 5.48 + 5.49 + 5.50 +/** 5.51 + * A set of simple tests on query rewriting functionality 5.52 + * 5.53 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> 5.54 + */ 5.55 +public class TemporalRelationTests { 5.56 + 5.57 + protected static Strabon strabon; 5.58 + 5.59 + protected static final String prefixes = 5.60 + "PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> \n" + 5.61 + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" + 5.62 + "PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> \n"; 5.63 + 5.64 + 5.65 + @BeforeClass 5.66 + public static void beforeClass() throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 5.67 + { 5.68 + strabon = TemplateTests.beforeClass("/temporal-periods.nq","NQUADS"); 5.69 + } 5.70 + 5.71 + @AfterClass 5.72 + public static void afterClass() throws SQLException 5.73 + { 5.74 + TemplateTests.afterClass(strabon); 5.75 + } 5.76 + 5.77 + 5.78 + 5.79 + @Test 5.80 + public void testAfter() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.81 + { 5.82 + 5.83 + String query = 5.84 + prefixes+ 5.85 + "SELECT ?x1 "+ 5.86 + "WHERE { "+ 5.87 + "?x1 ?y1 ?z1 ?t1 . "+ 5.88 + "?x2 ?y2 ?z2 ?t2 . "+ 5.89 + "FILTER(strdf:after(?t1, ?t2))."+ 5.90 + "}"; 5.91 + 5.92 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.93 + 5.94 + for(String result: bindings) 5.95 + { 5.96 + System.out.println(result.toString()); 5.97 + } 5.98 + 5.99 + assertEquals(5, bindings.size()); 5.100 + assertTrue(-1 < bindings.indexOf("[x1=http://example.org/item1]")); 5.101 + assertTrue(-1 < bindings.indexOf("[x1=http://example.org/item2]")); 5.102 + assertTrue(-1 < bindings.indexOf("[x1=http://example.org/item3]")); 5.103 + assertTrue(-1 < bindings.indexOf("[x1=http://example.org/item5]")); 5.104 + assertTrue(-1 < bindings.indexOf("[x1=http://example.org/item6]")); 5.105 + } 5.106 + 5.107 + @Test 5.108 + public void testBefore() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.109 + { 5.110 + 5.111 + String query = 5.112 + prefixes+ 5.113 + "SELECT distinct ?x1 ?x2 "+ 5.114 + "WHERE { "+ 5.115 + "?x1 ?y1 ?z1 ?t1 . "+ 5.116 + "?x2 ?y2 ?z2 ?t2 . "+ 5.117 + "FILTER(strdf:before(?t1, ?t2) && ?x2!=?x1)."+ 5.118 + "}"; 5.119 + 5.120 + //TupleQueryResult result = (TupleQueryResult) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.121 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.122 + //System.out.println(bindings.toString()); 5.123 + 5.124 + for(String result: bindings) 5.125 + { 5.126 + System.out.println(result.toString()); 5.127 + } 5.128 + 5.129 + assertEquals(14, bindings.size()); 5.130 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item5]")); 5.131 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item5]")); 5.132 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item6]")); 5.133 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item4]")); 5.134 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.135 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item5]")); 5.136 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item4]")); 5.137 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.138 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item4]")); 5.139 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item4]")); 5.140 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item5]")); 5.141 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item6]")); 5.142 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item6]")); 5.143 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item4]")); 5.144 + } 5.145 + 5.146 + @Test 5.147 + public void testOverright() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.148 + { 5.149 + 5.150 + String query = 5.151 + prefixes+ 5.152 + "SELECT distinct ?x1 ?x2 "+ 5.153 + "WHERE { "+ 5.154 + "?x1 ?y1 ?z1 ?t1 . "+ 5.155 + "?x2 ?y2 ?z2 ?t2 . "+ 5.156 + "FILTER(strdf:overright(?t1, ?t2) && ?x1 != ?x2)."+ 5.157 + "}"; 5.158 + 5.159 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.160 + assertEquals(18, bindings.size()); 5.161 + //assertTrue(-1 < bindings.indexOf("")); 5.162 + for(String result: bindings) 5.163 + { 5.164 + System.out.println(result.toString()); 5.165 + } 5.166 + 5.167 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item1]")); 5.168 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item2]")); 5.169 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item3]")); 5.170 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.171 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item5]")); 5.172 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item6]")); 5.173 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item2]")); 5.174 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item3]")); 5.175 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.176 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item3]")); 5.177 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.178 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item3]")); 5.179 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item6]")); 5.180 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item1]")); 5.181 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item3]")); 5.182 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item2]")); 5.183 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item2]")); 5.184 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item1]")); 5.185 + } 5.186 + 5.187 + @Test 5.188 + public void testOverleft() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.189 + { 5.190 + 5.191 + String query = 5.192 + prefixes+ 5.193 + "SELECT distinct ?x1 ?x2 "+ 5.194 + "WHERE { "+ 5.195 + "?x1 ?y1 ?z1 ?t1 . "+ 5.196 + "?x2 ?y2 ?z2 ?t2 . "+ 5.197 + "FILTER(strdf:overleft(?t1, ?t2) && ?x1 != ?x2)."+ 5.198 + "}"; 5.199 + 5.200 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.201 + assertEquals(6, bindings.size()); 5.202 + //assertTrue(-1 < bindings.indexOf("")); 5.203 + for(String result: bindings) 5.204 + { 5.205 + System.out.println(result.toString()); 5.206 + } 5.207 + 5.208 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item3]")); 5.209 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.210 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item2]")); 5.211 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.212 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.213 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item3]")); 5.214 + } 5.215 + 5.216 + @Test 5.217 + public void testPeriodOverlaps() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.218 + { 5.219 + 5.220 + String query = 5.221 + prefixes+ 5.222 + "SELECT distinct ?x1 ?x2 "+ 5.223 + "WHERE { "+ 5.224 + "?x1 ?y1 ?z1 ?t1 . "+ 5.225 + "?x2 ?y2 ?z2 ?t2 . "+ 5.226 + "FILTER(strdf:PeriodOverlaps(?t1, ?t2) && str(?x1) != str(?x2))."+ 5.227 + "}"; 5.228 + 5.229 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.230 + 5.231 + assertEquals(6, bindings.size()); 5.232 + //assertTrue(-1 < bindings.indexOf("")); 5.233 + for(String result: bindings) 5.234 + { 5.235 + System.out.println(result.toString()); 5.236 + } 5.237 + 5.238 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item3]")); 5.239 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item2]")); 5.240 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.241 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.242 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.243 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item3]")); 5.244 + } 5.245 + 5.246 + @Test 5.247 + public void testDuring() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.248 + { 5.249 + 5.250 + String query = 5.251 + prefixes+ 5.252 + "SELECT distinct ?x1 ?x2 "+ 5.253 + "WHERE { "+ 5.254 + "?x1 ?y1 ?z1 ?t1 . "+ 5.255 + "?x2 ?y2 ?z2 ?t2 . "+ 5.256 + "FILTER(strdf:during(?t1, ?t2) && ?x1 != ?x2)."+ 5.257 + "}"; 5.258 + 5.259 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.260 + 5.261 + assertEquals(6, bindings.size()); 5.262 + //assertTrue(-1 < bindings.indexOf("")); 5.263 + for(String result: bindings) 5.264 + { 5.265 + System.out.println(result.toString()); 5.266 + } 5.267 + 5.268 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item3]")); 5.269 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.270 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item2]")); 5.271 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.272 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.273 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item3]")); 5.274 + 5.275 + } 5.276 + @Test 5.277 + public void testAdjacent() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.278 + { 5.279 + 5.280 + String query = 5.281 + prefixes+ 5.282 + "SELECT ?x1 ?x2 "+ 5.283 + "WHERE { "+ 5.284 + "?x1 ?y1 ?z1 ?t1 . "+ 5.285 + "?x2 ?y2 ?z2 ?t2 . "+ 5.286 + "FILTER(strdf:adjacent(?t1, ?t2))."+ 5.287 + "}"; 5.288 + 5.289 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.290 + for(String result: bindings) 5.291 + { 5.292 + System.out.println(result.toString()); 5.293 + } 5.294 + //assertEquals(14, bindings.size()); 5.295 + //assertTrue(-1 < bindings.indexOf("")); 5.296 + } 5.297 + 5.298 + @Test 5.299 + public void testMeets() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.300 + { 5.301 + 5.302 + String query = 5.303 + prefixes+ 5.304 + "SELECT ?x1 ?x2 "+ 5.305 + "WHERE { "+ 5.306 + "?x1 ?y1 ?z1 ?t1 . "+ 5.307 + "?x2 ?y2 ?z2 ?t2 . "+ 5.308 + "FILTER(strdf:meets(?t1, ?t2))."+ 5.309 + "}"; 5.310 + 5.311 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.312 + for(String result: bindings) 5.313 + { 5.314 + System.out.println(result.toString()); 5.315 + } 5.316 + //assertEquals(14, bindings.size()); 5.317 + //assertTrue(-1 < bindings.indexOf("")); 5.318 + } 5.319 + 5.320 + @Test 5.321 + public void testStarts() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.322 + { 5.323 + 5.324 + String query = 5.325 + prefixes+ 5.326 + "SELECT distinct ?x1 ?x2 "+ 5.327 + "WHERE { "+ 5.328 + "?x1 ?y1 ?z1 ?t1 . "+ 5.329 + "?x2 ?y2 ?z2 ?t2 . "+ 5.330 + "FILTER(strdf:starts(?t1, ?t2) && str(?x1) != str(?x2))."+ 5.331 + "}"; 5.332 + 5.333 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.334 + 5.335 + assertEquals(6, bindings.size()); 5.336 + //assertTrue(-1 < bindings.indexOf("")); 5.337 + for(String result: bindings) 5.338 + { 5.339 + System.out.println(result.toString()); 5.340 + } 5.341 + 5.342 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item3]")); 5.343 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item2]")); 5.344 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.345 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.346 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.347 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item3]")); 5.348 + 5.349 + } 5.350 + 5.351 + @Test 5.352 + public void testFinishes() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.353 + { 5.354 + 5.355 + String query = 5.356 + prefixes+ 5.357 + "SELECT distinct ?x1 ?x2 "+ 5.358 + "WHERE { "+ 5.359 + "?x1 ?y1 ?z1 ?t1 . "+ 5.360 + "?x2 ?y2 ?z2 ?t2 . "+ 5.361 + "FILTER(strdf:finishes(?t1, ?t2) && str(?x1) > str(?x2))."+ 5.362 + "}"; 5.363 + 5.364 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.365 + 5.366 + assertEquals(3, bindings.size()); 5.367 + //assertTrue(-1 < bindings.indexOf("")); 5.368 + for(String result: bindings) 5.369 + { 5.370 + System.out.println(result.toString()); 5.371 + } 5.372 + 5.373 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item3]")); 5.374 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item3]")); 5.375 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item1;x1=http://example.org/item2]")); 5.376 + } 5.377 + 5.378 + @Test 5.379 + public void testEqualsPeriod() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.380 + { 5.381 + 5.382 + String query = 5.383 + prefixes+ 5.384 + "SELECT distinct ?x1 ?x2 "+ 5.385 + "WHERE { "+ 5.386 + "?x1 ?y1 ?z1 ?t1 . "+ 5.387 + "?x2 ?y2 ?z2 ?t2 . "+ 5.388 + "FILTER(strdf:equalsPeriod(?t1, ?t2) && str(?x1) < str(?x2))."+ 5.389 + "}"; 5.390 + 5.391 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.392 + //assertEquals(3, bindings.size()); 5.393 + //assertTrue(-1 < bindings.indexOf("")); 5.394 + for(String result: bindings) 5.395 + { 5.396 + System.out.println(result.toString()); 5.397 + } 5.398 + 5.399 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.400 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.401 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.402 + } 5.403 + 5.404 + @Test 5.405 + public void testNequalsPeriod() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 5.406 + { 5.407 + 5.408 + String query = 5.409 + prefixes+ 5.410 + "SELECT distinct ?x1 ?x2 "+ 5.411 + "WHERE { "+ 5.412 + "?x1 ?y1 ?z1 ?t1 . "+ 5.413 + "?x2 ?y2 ?z2 ?t2 . "+ 5.414 + "FILTER(strdf:nequalsPeriod(?t1, ?t2) && str(?x1) < str(?x2))."+ 5.415 + "}"; 5.416 + 5.417 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 5.418 + 5.419 + assertEquals(15, bindings.size()); 5.420 + //assertTrue(-1 < bindings.indexOf("")); 5.421 + for(String result: bindings) 5.422 + { 5.423 + System.out.println(result.toString()); 5.424 + } 5.425 + 5.426 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item1]")); 5.427 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item1]")); 5.428 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item2]")); 5.429 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item4]")); 5.430 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item2;x1=http://example.org/item1]")); 5.431 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item5]")); 5.432 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item3]")); 5.433 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item1]")); 5.434 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item3]")); 5.435 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item3;x1=http://example.org/item2]")); 5.436 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item3]")); 5.437 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item5;x1=http://example.org/item1]")); 5.438 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item4]")); 5.439 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item6;x1=http://example.org/item2]")); 5.440 + assertTrue(-1 < bindings.indexOf("[x2=http://example.org/item4;x1=http://example.org/item2]")); 5.441 + 5.442 + } 5.443 +} 5.444 + 5.445 \ No newline at end of file
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalSelectionTests.java Tue Jan 15 12:07:55 2013 +0200 6.3 @@ -0,0 +1,97 @@ 6.4 +/** 6.5 + * This Source Code Form is subject to the terms of the Mozilla Public 6.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 6.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 6.8 + * 6.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 6.10 + * 6.11 + * http://www.strabon.di.uoa.gr/ 6.12 + */ 6.13 +package eu.earthobservatory.runtime.postgres.temporals; 6.14 + 6.15 + 6.16 + 6.17 +import static org.junit.Assert.assertEquals; 6.18 + 6.19 +import java.io.IOException; 6.20 +import java.sql.SQLException; 6.21 +import java.util.ArrayList; 6.22 + 6.23 +import org.junit.AfterClass; 6.24 +import org.junit.BeforeClass; 6.25 +import org.junit.Test; 6.26 +import org.openrdf.query.MalformedQueryException; 6.27 +import org.openrdf.query.QueryEvaluationException; 6.28 +import org.openrdf.query.TupleQueryResultHandlerException; 6.29 +import org.openrdf.repository.RepositoryException; 6.30 +import org.openrdf.rio.RDFHandlerException; 6.31 +import org.openrdf.rio.RDFParseException; 6.32 + 6.33 + 6.34 +import eu.earthobservatory.runtime.generaldb.*; 6.35 +import eu.earthobservatory.runtime.postgres.temporals.TemplateTests; 6.36 + 6.37 + 6.38 +/** 6.39 + * A set of simple tests on temporal selection functionality 6.40 + * 6.41 + * @author Panayiotis Smeros <psmeros@di.uoa.gr> 6.42 + */ 6.43 +public class TemporalSelectionTests { 6.44 + 6.45 + protected static Strabon strabon; 6.46 + 6.47 + protected static final String prefixes = 6.48 + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + 6.49 + "PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> \n" + 6.50 + "PREFIX ex: <http://example.org/> \n" + 6.51 + "PREFIX xs: <http://www.w3.org/2001/XMLSchema#> \n" + 6.52 + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n" + 6.53 + "PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> \n"; 6.54 + 6.55 + 6.56 + @BeforeClass 6.57 + public static void beforeClass() throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 6.58 + { 6.59 + strabon = TemplateTests.beforeClass("/temporal-selection-tests.nq","NQUADS"); 6.60 + } 6.61 + 6.62 + @AfterClass 6.63 + public static void afterClass() throws SQLException 6.64 + { 6.65 + TemplateTests.afterClass(strabon); 6.66 + } 6.67 + 6.68 + 6.69 + 6.70 + @Test 6.71 + public void testSPOTQuery() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 6.72 + { 6.73 + 6.74 + String query = 6.75 + prefixes+ 6.76 + "SELECT * "+ 6.77 + "WHERE { "+ 6.78 + "?s ?p ?o ?t. "+ 6.79 + "}"; 6.80 + 6.81 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 6.82 + assertEquals(8, bindings.size()); 6.83 + } 6.84 + 6.85 + 6.86 + @Test 6.87 + public void testSPOQuery() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, QueryEvaluationException 6.88 + { 6.89 + 6.90 + String query = 6.91 + prefixes+ 6.92 + "SELECT * "+ 6.93 + "WHERE { "+ 6.94 + "?s ?p ?o. "+ 6.95 + "}"; 6.96 + 6.97 + ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection()); 6.98 + assertEquals(9, bindings.size()); 6.99 + } 6.100 +}