Strabon

changeset 973:fd5c334c7fa8

Almost finished the test. Final check with the existing results need to be done.
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Wed Apr 03 20:19:14 2013 +0300 (2013-04-03)
parents ffda52025190
children f658d2b036d9
files testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TestStore.java testsuite/src/test/resources/TestStore.rq testsuite/src/test/resources/TestStore.sr
line diff
     1.1 --- a/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Tue Apr 02 21:17:55 2013 +0300
     1.2 +++ b/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Wed Apr 03 20:19:14 2013 +0300
     1.3 @@ -3,39 +3,26 @@
     1.4   * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.5   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.6   * 
     1.7 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team
     1.8 + * Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team
     1.9   * 
    1.10   * http://www.strabon.di.uoa.gr/
    1.11   */
    1.12  package eu.earthobservatory.runtime.postgis;
    1.13  
    1.14 -import java.io.IOException;
    1.15 +import static org.junit.Assert.assertNull;
    1.16  import java.io.InputStream;
    1.17 +import java.sql.Connection;
    1.18  import java.sql.DriverManager;
    1.19  import java.sql.PreparedStatement;
    1.20  import java.sql.ResultSet;
    1.21  import java.sql.SQLException;
    1.22 -import java.sql.Statement;
    1.23 -import java.sql.Connection;
    1.24  import java.util.ArrayList;
    1.25  import java.util.Properties;
    1.26 -
    1.27 -import org.junit.AfterClass;
    1.28 -import org.junit.BeforeClass;
    1.29 -import org.openrdf.repository.RepositoryException;
    1.30 -import org.openrdf.rio.RDFHandlerException;
    1.31 -import org.openrdf.rio.RDFParseException;
    1.32 -
    1.33 -
    1.34 -import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    1.35 -import eu.earthobservatory.runtime.generaldb.Strabon;
    1.36 -
    1.37 -import static org.junit.Assert.assertNull;
    1.38 +import eu.earthobservatory.runtime.postgis.Strabon;
    1.39  
    1.40  /**
    1.41 - * A set of simple tests on SPARQL query functionality 
    1.42 + * A template class with useful methods for the tests.  
    1.43   * 
    1.44 - * @author George Garbis <ggarbis@di.uoa.gr>
    1.45   * @author Panayiotis Smeros <psmeros@di.uoa.gr>
    1.46   */
    1.47  public class TemplateTests {
    1.48 @@ -50,8 +37,7 @@
    1.49  	public static Connection conn = null;
    1.50  	public static String databaseName = null;
    1.51  	
    1.52 -	@BeforeClass
    1.53 -	public static Strabon beforeClass() throws Exception
    1.54 +	public static Strabon beforeClass(String datasetFile) throws Exception
    1.55  	{
    1.56  		String url="";
    1.57  		ArrayList<String> databases=new ArrayList<String>();
    1.58 @@ -100,11 +86,15 @@
    1.59  		
    1.60  	    Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true);
    1.61  
    1.62 +	    if(datasetFile.endsWith(".nt"))
    1.63 +	    	strabon.storeInRepo(datasetFile, "NTRIPLES");
    1.64 +	    else if(datasetFile.endsWith(".nq"))
    1.65 +	    	strabon.storeInRepo(datasetFile, "NQUADS");
    1.66 +	    
    1.67  		return strabon;
    1.68  	}
    1.69  	
    1.70 -	
    1.71 -	@AfterClass
    1.72 +
    1.73  	public static void afterClass(Strabon strabon) throws SQLException
    1.74  	{
    1.75  		strabon.close();
    1.76 @@ -120,54 +110,4 @@
    1.77  		pst.close();
    1.78  		conn.close();
    1.79  	}
    1.80 -	
    1.81 -	
    1.82 -	// Clean database
    1.83 -//	Statement stmt = conn.createStatement();
    1.84 -//	ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " +
    1.85 -//					"table_schema='public' AND table_name <> 'spatial_ref_sys' " +
    1.86 -//					"AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " +
    1.87 -//					"AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " +
    1.88 -//					"AND table_name <> 'locked'"
    1.89 -//				);
    1.90 -//	while (results.next()) {
    1.91 -//		String table_name = results.getString("table_name");
    1.92 -//		Statement stmt2 = conn.createStatement();
    1.93 -//		stmt2.executeUpdate("DROP TABLE \""+table_name+"\"");
    1.94 -//		stmt2.close();
    1.95 -//	}
    1.96 -//	stmt.close();
    1.97 -	
    1.98 -//	/**
    1.99 -//	 * @throws java.lang.Exception
   1.100 -//	 */
   1.101 -//	@Before
   1.102 -//	public void before()
   1.103 -//		throws Exception
   1.104 -//	{
   1.105 -//		
   1.106 -//	}
   1.107 -//
   1.108 -//	/**
   1.109 -//	 * @throws java.lang.Exception
   1.110 -//	 */
   1.111 -//	@After
   1.112 -//	public void after()
   1.113 -//		throws Exception
   1.114 -//	{
   1.115 -//		// Clean database
   1.116 -//		Statement stmt = conn.createStatement();
   1.117 -//		ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " +
   1.118 -//						"table_schema='public' and table_name <> 'spatial_ref_sys' " +
   1.119 -//						"and table_name <> 'geometry_columns' and " +
   1.120 -//						"table_name <> 'geography_columns' and table_name <> 'locked'");
   1.121 -//		while (results.next()) {
   1.122 -//			String table_name = results.getString("table_name");
   1.123 -//			Statement stmt2 = conn.createStatement();
   1.124 -//			stmt2.executeUpdate("DROP TABLE \""+table_name+"\"");
   1.125 -//			stmt2.close();
   1.126 -//		}
   1.127 -//			
   1.128 -//		stmt.close();
   1.129 -//	}
   1.130  }
     2.1 --- a/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TestStore.java	Tue Apr 02 21:17:55 2013 +0300
     2.2 +++ b/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TestStore.java	Wed Apr 03 20:19:14 2013 +0300
     2.3 @@ -9,17 +9,17 @@
     2.4   */
     2.5  package eu.earthobservatory.runtime.postgis;
     2.6  
     2.7 -import java.io.IOException;
     2.8 +import java.io.*;
     2.9  import java.sql.SQLException;
    2.10 -
    2.11 +import java.util.ArrayList;
    2.12 +import java.util.Iterator;
    2.13  import org.junit.AfterClass;
    2.14  import org.junit.BeforeClass;
    2.15  import org.junit.Test;
    2.16 -import org.openrdf.repository.RepositoryException;
    2.17 -import org.openrdf.rio.RDFHandlerException;
    2.18 -import org.openrdf.rio.RDFParseException;
    2.19 -import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    2.20 -import eu.earthobservatory.runtime.generaldb.Strabon;
    2.21 +import org.openrdf.query.MalformedQueryException;
    2.22 +import org.openrdf.query.QueryEvaluationException;
    2.23 +import org.openrdf.query.TupleQueryResultHandlerException;
    2.24 +import eu.earthobservatory.runtime.postgis.Strabon;
    2.25  
    2.26  /**
    2.27   * A set of simple tests on SPARQL query functionality 
    2.28 @@ -29,18 +29,41 @@
    2.29  public class TestStore{
    2.30  	
    2.31  	private static Strabon strabon;
    2.32 -
    2.33 +	
    2.34 +	private static final String datasetFile = "/TestStore.nt";
    2.35 +	private static final String queryFile = "/TestStore.rq";
    2.36 +	private static final String resultsFile = "/TestStore.sr";
    2.37  
    2.38  	@BeforeClass
    2.39  	public static void beforeClass() throws Exception
    2.40  	{
    2.41 -		strabon = TemplateTests.beforeClass();
    2.42 +		strabon = TemplateTests.beforeClass(datasetFile);
    2.43  	}
    2.44  	
    2.45  	@Test
    2.46 -	public void test() throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault
    2.47 +	public void test() throws IOException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException
    2.48  	{
    2.49 -		strabon.storeInRepo("/"+this.getClass().getSimpleName()+".nt", "NTRIPLES");
    2.50 +		BufferedReader reader = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(queryFile)));
    2.51 +		String query="";
    2.52 +		
    2.53 +		while (reader.ready()) 
    2.54 +		{
    2.55 +			query+=reader.readLine()+"\n";
    2.56 +		}
    2.57 +
    2.58 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(query,strabon.getSailRepoConnection());
    2.59 +		ArrayList<String> queryResults = new ArrayList<String>();
    2.60 +		
    2.61 +		Iterator<String> iterator = bindings.iterator();
    2.62 +		while(iterator.hasNext())
    2.63 +		{
    2.64 +			String binding = iterator.next();
    2.65 +			System.out.println(binding);
    2.66 +			binding=binding.replaceAll("[[A-Z][a-z][0-9]]*=", "?=");
    2.67 +			queryResults.add(binding);
    2.68 +			System.out.println(binding);
    2.69 +		}
    2.70 +
    2.71  	}
    2.72  	
    2.73  	@AfterClass
     3.1 --- a/testsuite/src/test/resources/TestStore.rq	Tue Apr 02 21:17:55 2013 +0300
     3.2 +++ b/testsuite/src/test/resources/TestStore.rq	Wed Apr 03 20:19:14 2013 +0300
     3.3 @@ -1,2 +1,3 @@
     3.4  SELECT *
     3.5 -WHERE{?s ?p ?o}
     3.6 \ No newline at end of file
     3.7 +WHERE{?s ?p ?o}
     3.8 +ORDER BY ?s
     3.9 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/testsuite/src/test/resources/TestStore.sr	Wed Apr 03 20:19:14 2013 +0300
     4.3 @@ -0,0 +1,8 @@
     4.4 +[?=http://example.org/item1;?="POINT(1 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>;?=http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry]
     4.5 +[?=http://example.org/item1;?="1"^^<http://www.w3.org/2001/XMLSchema#int>;?=http://example.org/id]
     4.6 +[?=http://example.org/item1;?="10"^^<http://www.w3.org/2001/XMLSchema#int>;?=http://example.org/value]
     4.7 +[?=http://example.org/item2;?="POINT(2 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>;?=http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry]
     4.8 +[?=http://example.org/item2;?="20"^^<http://www.w3.org/2001/XMLSchema#int>;?=http://example.org/value]
     4.9 +[?=http://example.org/item2;?="2"^^<http://www.w3.org/2001/XMLSchema#int>;?=http://example.org/id]
    4.10 +[?=http://example.org/item3;?="POINT(3 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>;?=http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry]
    4.11 +[?=http://example.org/item3;?="3"^^<http://www.w3.org/2001/XMLSchema#int>;?=http://example.org/id]
    4.12 \ No newline at end of file