Strabon

changeset 972:ffda52025190

Added first test in testsuite (not ready yet).
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Tue Apr 02 21:17:55 2013 +0300 (2013-04-02)
parents b628e51f9580
children fd5c334c7fa8
files testsuite/pom.xml 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.nt testsuite/src/test/resources/TestStore.rq testsuite/src/test/resources/databases.properties
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testsuite/pom.xml	Tue Apr 02 21:17:55 2013 +0300
     1.3 @@ -0,0 +1,31 @@
     1.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     1.5 +
     1.6 +	<modelVersion>4.0.0</modelVersion>
     1.7 +
     1.8 +	<parent>
     1.9 +		<groupId>eu.earthobservatory</groupId>
    1.10 +		<artifactId>strabon</artifactId>
    1.11 +		<version>3.2.9-SNAPSHOT</version>
    1.12 +	</parent>
    1.13 +
    1.14 +	<artifactId>strabon-testsuite</artifactId>
    1.15 +
    1.16 +	<name>Strabon: Test Suite</name>
    1.17 +	<description>A test suite for Strabon</description>
    1.18 +	<packaging>jar</packaging>
    1.19 +
    1.20 +	<dependencies>
    1.21 +		<dependency>
    1.22 +			<groupId>eu.earthobservatory</groupId>
    1.23 +			<artifactId>strabon-runtime</artifactId>
    1.24 +		</dependency>
    1.25 +
    1.26 +		<!-- Testing: JUnit -->
    1.27 +		<dependency>
    1.28 +			<groupId>junit</groupId>
    1.29 +			<artifactId>junit</artifactId>
    1.30 +			<scope>test</scope>
    1.31 +		</dependency>	
    1.32 +	</dependencies>
    1.33 +
    1.34 +</project>
    1.35 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Tue Apr 02 21:17:55 2013 +0300
     2.3 @@ -0,0 +1,173 @@
     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;
    2.14 +
    2.15 +import java.io.IOException;
    2.16 +import java.io.InputStream;
    2.17 +import java.sql.DriverManager;
    2.18 +import java.sql.PreparedStatement;
    2.19 +import java.sql.ResultSet;
    2.20 +import java.sql.SQLException;
    2.21 +import java.sql.Statement;
    2.22 +import java.sql.Connection;
    2.23 +import java.util.ArrayList;
    2.24 +import java.util.Properties;
    2.25 +
    2.26 +import org.junit.AfterClass;
    2.27 +import org.junit.BeforeClass;
    2.28 +import org.openrdf.repository.RepositoryException;
    2.29 +import org.openrdf.rio.RDFHandlerException;
    2.30 +import org.openrdf.rio.RDFParseException;
    2.31 +
    2.32 +
    2.33 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    2.34 +import eu.earthobservatory.runtime.generaldb.Strabon;
    2.35 +
    2.36 +import static org.junit.Assert.assertNull;
    2.37 +
    2.38 +/**
    2.39 + * A set of simple tests on SPARQL query functionality 
    2.40 + * 
    2.41 + * @author George Garbis <ggarbis@di.uoa.gr>
    2.42 + * @author Panayiotis Smeros <psmeros@di.uoa.gr>
    2.43 + */
    2.44 +public class TemplateTests {
    2.45 +	
    2.46 +	public static String databaseTemplateName = null;
    2.47 +	public static String defaultUser = null;
    2.48 +	public static String serverName = null;
    2.49 +	public static String username = null;
    2.50 +	public static String password = null;
    2.51 +	public static Integer port = null;
    2.52 +	
    2.53 +	public static Connection conn = null;
    2.54 +	public static String databaseName = null;
    2.55 +	
    2.56 +	@BeforeClass
    2.57 +	public static Strabon beforeClass() throws Exception
    2.58 +	{
    2.59 +		String url="";
    2.60 +		ArrayList<String> databases=new ArrayList<String>();
    2.61 +        PreparedStatement pst = null;
    2.62 +		
    2.63 +		// Read properties
    2.64 +		Properties properties = new Properties();
    2.65 +		InputStream propertiesStream =  TemplateTests.class.getResourceAsStream("/databases.properties");
    2.66 +		properties.load(propertiesStream);
    2.67 +
    2.68 +		databaseTemplateName = properties.getProperty("postgis.databaseTemplateName");;
    2.69 +		defaultUser = properties.getProperty("postgis.defaultUser");
    2.70 +		serverName = properties.getProperty("postgis.serverName");
    2.71 +		username = properties.getProperty("postgis.username");
    2.72 +		password = properties.getProperty("postgis.password");
    2.73 +		port = Integer.parseInt(properties.getProperty("postgis.port"));
    2.74 +
    2.75 +		//Connect to server and create the temp database
    2.76 +		url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser;
    2.77 +		conn = DriverManager.getConnection(url, username, password);
    2.78 +		assertNull(conn.getWarnings());
    2.79 +		
    2.80 +        pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database");
    2.81 +        ResultSet rs = pst.executeQuery();
    2.82 +
    2.83 +        while (rs.next()) {
    2.84 +        	databases.add(rs.getString(1));
    2.85 +        }
    2.86 +        rs.close();
    2.87 +        pst.close();
    2.88 +   
    2.89 +        databaseName="teststrabon"+(int)(Math.random()*10000);
    2.90 +        while(databases.contains(databaseName)){
    2.91 +        	databaseName+="0";
    2.92 +        }
    2.93 +        	
    2.94 +        
    2.95 +		pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName);
    2.96 +		pst.executeUpdate();
    2.97 +		pst.close();
    2.98 +		conn.close();
    2.99 +
   2.100 +		url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName;
   2.101 +		conn = DriverManager.getConnection(url, username, password);
   2.102 +		assertNull(conn.getWarnings());
   2.103 +		
   2.104 +	    Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true);
   2.105 +
   2.106 +		return strabon;
   2.107 +	}
   2.108 +	
   2.109 +	
   2.110 +	@AfterClass
   2.111 +	public static void afterClass(Strabon strabon) throws SQLException
   2.112 +	{
   2.113 +		strabon.close();
   2.114 +		
   2.115 +		//Drop the temp database
   2.116 +		conn.close();
   2.117 +		String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser;
   2.118 +		conn = DriverManager.getConnection(url, username, password);
   2.119 +		assertNull(conn.getWarnings());
   2.120 +		
   2.121 +		PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName);
   2.122 +		pst.executeUpdate();
   2.123 +		pst.close();
   2.124 +		conn.close();
   2.125 +	}
   2.126 +	
   2.127 +	
   2.128 +	// Clean database
   2.129 +//	Statement stmt = conn.createStatement();
   2.130 +//	ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " +
   2.131 +//					"table_schema='public' AND table_name <> 'spatial_ref_sys' " +
   2.132 +//					"AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " +
   2.133 +//					"AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " +
   2.134 +//					"AND table_name <> 'locked'"
   2.135 +//				);
   2.136 +//	while (results.next()) {
   2.137 +//		String table_name = results.getString("table_name");
   2.138 +//		Statement stmt2 = conn.createStatement();
   2.139 +//		stmt2.executeUpdate("DROP TABLE \""+table_name+"\"");
   2.140 +//		stmt2.close();
   2.141 +//	}
   2.142 +//	stmt.close();
   2.143 +	
   2.144 +//	/**
   2.145 +//	 * @throws java.lang.Exception
   2.146 +//	 */
   2.147 +//	@Before
   2.148 +//	public void before()
   2.149 +//		throws Exception
   2.150 +//	{
   2.151 +//		
   2.152 +//	}
   2.153 +//
   2.154 +//	/**
   2.155 +//	 * @throws java.lang.Exception
   2.156 +//	 */
   2.157 +//	@After
   2.158 +//	public void after()
   2.159 +//		throws Exception
   2.160 +//	{
   2.161 +//		// Clean database
   2.162 +//		Statement stmt = conn.createStatement();
   2.163 +//		ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " +
   2.164 +//						"table_schema='public' and table_name <> 'spatial_ref_sys' " +
   2.165 +//						"and table_name <> 'geometry_columns' and " +
   2.166 +//						"table_name <> 'geography_columns' and table_name <> 'locked'");
   2.167 +//		while (results.next()) {
   2.168 +//			String table_name = results.getString("table_name");
   2.169 +//			Statement stmt2 = conn.createStatement();
   2.170 +//			stmt2.executeUpdate("DROP TABLE \""+table_name+"\"");
   2.171 +//			stmt2.close();
   2.172 +//		}
   2.173 +//			
   2.174 +//		stmt.close();
   2.175 +//	}
   2.176 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TestStore.java	Tue Apr 02 21:17:55 2013 +0300
     3.3 @@ -0,0 +1,51 @@
     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;
    3.14 +
    3.15 +import java.io.IOException;
    3.16 +import java.sql.SQLException;
    3.17 +
    3.18 +import org.junit.AfterClass;
    3.19 +import org.junit.BeforeClass;
    3.20 +import org.junit.Test;
    3.21 +import org.openrdf.repository.RepositoryException;
    3.22 +import org.openrdf.rio.RDFHandlerException;
    3.23 +import org.openrdf.rio.RDFParseException;
    3.24 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    3.25 +import eu.earthobservatory.runtime.generaldb.Strabon;
    3.26 +
    3.27 +/**
    3.28 + * A set of simple tests on SPARQL query functionality 
    3.29 + * 
    3.30 + * @author Panayiotis Smeros <psmeros@di.uoa.gr
    3.31 + */
    3.32 +public class TestStore{
    3.33 +	
    3.34 +	private static Strabon strabon;
    3.35 +
    3.36 +
    3.37 +	@BeforeClass
    3.38 +	public static void beforeClass() throws Exception
    3.39 +	{
    3.40 +		strabon = TemplateTests.beforeClass();
    3.41 +	}
    3.42 +	
    3.43 +	@Test
    3.44 +	public void test() throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault
    3.45 +	{
    3.46 +		strabon.storeInRepo("/"+this.getClass().getSimpleName()+".nt", "NTRIPLES");
    3.47 +	}
    3.48 +	
    3.49 +	@AfterClass
    3.50 +	public static void afterClass() throws SQLException
    3.51 +	{
    3.52 +		TemplateTests.afterClass(strabon);
    3.53 +	}
    3.54 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/testsuite/src/test/resources/TestStore.nt	Tue Apr 02 21:17:55 2013 +0300
     4.3 @@ -0,0 +1,8 @@
     4.4 +<http://example.org/item1> <http://example.org/id> "1"^^<http://www.w3.org/2001/XMLSchema#int>.
     4.5 +<http://example.org/item2> <http://example.org/id> "2"^^<http://www.w3.org/2001/XMLSchema#int>.
     4.6 +<http://example.org/item3> <http://example.org/id> "3"^^<http://www.w3.org/2001/XMLSchema#int>.
     4.7 +<http://example.org/item1> <http://example.org/value> "10"^^<http://www.w3.org/2001/XMLSchema#int>.
     4.8 +<http://example.org/item2> <http://example.org/value> "20"^^<http://www.w3.org/2001/XMLSchema#int>.
     4.9 +<http://example.org/item1> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(1 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>.
    4.10 +<http://example.org/item2> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(2 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>.
    4.11 +<http://example.org/item3> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(3 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/testsuite/src/test/resources/TestStore.rq	Tue Apr 02 21:17:55 2013 +0300
     5.3 @@ -0,0 +1,2 @@
     5.4 +SELECT *
     5.5 +WHERE{?s ?p ?o}
     5.6 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/testsuite/src/test/resources/databases.properties	Tue Apr 02 21:17:55 2013 +0300
     6.3 @@ -0,0 +1,14 @@
     6.4 +# PostGIS
     6.5 +postgis.databaseTemplateName = template_postgis
     6.6 +postgis.defaultUser = postgres
     6.7 +postgis.serverName = localhost
     6.8 +postgis.username = postgres
     6.9 +postgis.password = postgres
    6.10 +postgis.port = 5432
    6.11 +		
    6.12 +! MonetDB
    6.13 +monetdb.databaseName = strabon-test
    6.14 +monetdb.serverName = localhost
    6.15 +monetdb.username = monetdb
    6.16 +monetdb.password = monetdb
    6.17 +monetdb.port = 50000