Strabon
changeset 1041:bbba44d70ba5
Re-organized packages.
author | Panayiotis Smeros <psmeros@di.uoa.gr> |
---|---|
date | Thu Apr 18 13:27:06 2013 +0300 (2013-04-18) |
parents | 61bc2e9bf304 |
children | 989e5948ea23 cc1504a43458 |
files | testsuite/src/test/java/eu/earthobservatory/runtime/postgis/StoreTest.java testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTest.java testsuite/src/test/java/eu/earthobservatory/runtime/postgis/Utils.java testsuite/src/test/java/eu/earthobservatory/testsuite/bugs/StoreTest.java testsuite/src/test/java/eu/earthobservatory/testsuite/utils/TemplateTest.java testsuite/src/test/java/eu/earthobservatory/testsuite/utils/Utils.java testsuite/src/test/resources/StoreTest/StoreTest.nt testsuite/src/test/resources/StoreTest/StoreTest.rq testsuite/src/test/resources/StoreTest/StoreTest.srx testsuite/src/test/resources/bugs/StoreTest/StoreTest.nt testsuite/src/test/resources/bugs/StoreTest/StoreTest.rq testsuite/src/test/resources/bugs/StoreTest/StoreTest.srx |
line diff
1.1 --- a/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/StoreTest.java Wed Apr 17 18:56:04 2013 +0300 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,18 +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, 2013 Pyravlos Team 1.10 - * 1.11 - * http://www.strabon.di.uoa.gr/ 1.12 - */ 1.13 -package eu.earthobservatory.runtime.postgis; 1.14 - 1.15 - 1.16 -/** 1.17 - * A simple store test. It tests if the input dataset is stored and retrieved correctly. 1.18 - * 1.19 - * @author Panayiotis Smeros <psmeros@di.uoa.gr 1.20 - */ 1.21 -public class StoreTest extends TemplateTest{}
2.1 --- a/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTest.java Wed Apr 17 18:56:04 2013 +0300 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,66 +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, 2013 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 org.junit.After; 2.16 -import org.junit.Before; 2.17 -import org.junit.Test; 2.18 - 2.19 -/** 2.20 - * A template test. It: 2.21 - * 1) creates a database 2.22 - * 2) stores a dataset 2.23 - * 3) poses a query 2.24 - * 4) checks if the results of the query are the expected 2.25 - * 5) drops the database 2.26 - * 2.27 - * @author Panayiotis Smeros <psmeros@di.uoa.gr 2.28 - */ 2.29 -public abstract class TemplateTest 2.30 -{ 2.31 - private String datasetFile; 2.32 - private String queryFile; 2.33 - private String resultsFile; 2.34 - 2.35 - public TemplateTest(String datasetFile, String queryFile, String resultsFile) 2.36 - { 2.37 - this.datasetFile = datasetFile; 2.38 - this.queryFile = queryFile; 2.39 - this.resultsFile = resultsFile; 2.40 - } 2.41 - 2.42 - public TemplateTest() 2.43 - { 2.44 - String testname=this.getClass().getSimpleName(); 2.45 - 2.46 - this.datasetFile="/"+testname+"/"+testname+".nt"; 2.47 - this.queryFile="/"+testname+"/"+testname+".rq"; 2.48 - this.resultsFile="/"+testname+"/"+testname+".srx"; 2.49 - } 2.50 - 2.51 - @Before 2.52 - public void before() throws Exception 2.53 - { 2.54 - Utils.createdb(); 2.55 - Utils.storeDataset(datasetFile); 2.56 - } 2.57 - 2.58 - @Test 2.59 - public void test() throws Exception 2.60 - { 2.61 - Utils.testQuery(queryFile, resultsFile); 2.62 - } 2.63 - 2.64 - @After 2.65 - public void after() throws Exception 2.66 - { 2.67 - Utils.dropdb(); 2.68 - } 2.69 -}
3.1 --- a/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/Utils.java Wed Apr 17 18:56:04 2013 +0300 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,218 +0,0 @@ 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, 2013 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 static org.junit.Assert.assertEquals; 3.16 -import static org.junit.Assert.assertFalse; 3.17 -import static org.junit.Assert.assertTrue; 3.18 -import java.io.ByteArrayInputStream; 3.19 -import java.io.ByteArrayOutputStream; 3.20 -import java.io.File; 3.21 -import java.io.IOException; 3.22 -import java.io.InputStream; 3.23 -import java.net.URISyntaxException; 3.24 -import java.sql.Connection; 3.25 -import java.sql.DriverManager; 3.26 -import java.sql.PreparedStatement; 3.27 -import java.sql.ResultSet; 3.28 -import java.sql.SQLException; 3.29 -import java.util.ArrayList; 3.30 -import java.util.Collections; 3.31 -import java.util.Iterator; 3.32 -import java.util.List; 3.33 -import java.util.Properties; 3.34 -import org.apache.commons.io.FileUtils; 3.35 -import org.openrdf.query.BindingSet; 3.36 -import org.openrdf.query.MalformedQueryException; 3.37 -import org.openrdf.query.QueryEvaluationException; 3.38 -import org.openrdf.query.TupleQueryResult; 3.39 -import org.openrdf.query.TupleQueryResultHandlerException; 3.40 -import org.openrdf.query.resultio.QueryResultIO; 3.41 -import org.openrdf.query.resultio.QueryResultParseException; 3.42 -import org.openrdf.query.resultio.TupleQueryResultFormat; 3.43 -import org.openrdf.query.resultio.UnsupportedQueryResultFormatException; 3.44 -import org.openrdf.repository.RepositoryException; 3.45 -import org.openrdf.rio.RDFHandlerException; 3.46 -import org.openrdf.rio.RDFParseException; 3.47 -import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 3.48 -import eu.earthobservatory.utils.Format; 3.49 - 3.50 -/** 3.51 - * A class with useful methods for the tests. 3.52 - * 3.53 - * @author Panayiotis Smeros <psmeros@di.uoa.gr> 3.54 - */ 3.55 -public class Utils 3.56 -{ 3.57 - private static final String dbPropertiesFile="/databases.properties"; 3.58 - 3.59 - private static String databaseTemplateName = null; 3.60 - private static String defaultUser = null; 3.61 - private static String serverName = null; 3.62 - private static String username = null; 3.63 - private static String password = null; 3.64 - private static String port = null; 3.65 - 3.66 - private static Connection conn = null; 3.67 - private static String databaseName = null; 3.68 - 3.69 - private static Strabon strabon = null; 3.70 - 3.71 - public static void createdb() throws Exception 3.72 - { 3.73 - String url=""; 3.74 - ArrayList<String> databases=new ArrayList<String>(); 3.75 - PreparedStatement pst = null; 3.76 - 3.77 - //Read properties 3.78 - Properties properties = new Properties(); 3.79 - InputStream propertiesStream = Utils.class.getResourceAsStream(dbPropertiesFile); 3.80 - properties.load(propertiesStream); 3.81 - 3.82 - if((databaseTemplateName = System.getProperty("postgis.databaseTemplateName"))==null) 3.83 - { 3.84 - databaseTemplateName = properties.getProperty("postgis.databaseTemplateName"); 3.85 - } 3.86 - 3.87 - if((defaultUser = System.getProperty("postgis.defaultUser"))==null) 3.88 - { 3.89 - defaultUser = properties.getProperty("postgis.defaultUser"); 3.90 - } 3.91 - 3.92 - if((serverName = System.getProperty("postgis.serverName"))==null) 3.93 - { 3.94 - serverName = properties.getProperty("postgis.serverName"); 3.95 - } 3.96 - 3.97 - if((username = System.getProperty("postgis.username"))==null) 3.98 - { 3.99 - username = properties.getProperty("postgis.username"); 3.100 - } 3.101 - 3.102 - if((password = System.getProperty("postgis.password"))==null) 3.103 - { 3.104 - password = properties.getProperty("postgis.password"); 3.105 - } 3.106 - 3.107 - if((port = System.getProperty("postgis.port"))==null) 3.108 - { 3.109 - port = properties.getProperty("postgis.port"); 3.110 - } 3.111 - 3.112 - //Connect to server and create the temp database 3.113 - url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; 3.114 - conn = DriverManager.getConnection(url, username, password); 3.115 - 3.116 - pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); 3.117 - ResultSet rs = pst.executeQuery(); 3.118 - 3.119 - while (rs.next()) 3.120 - { 3.121 - databases.add(rs.getString(1)); 3.122 - } 3.123 - rs.close(); 3.124 - pst.close(); 3.125 - 3.126 - databaseName="teststrabon"+(int)(Math.random()*10000); 3.127 - while(databases.contains(databaseName)) 3.128 - { 3.129 - databaseName+="0"; 3.130 - } 3.131 - 3.132 - pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName); 3.133 - pst.executeUpdate(); 3.134 - pst.close(); 3.135 - conn.close(); 3.136 - 3.137 - url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; 3.138 - conn = DriverManager.getConnection(url, username, password); 3.139 - 3.140 - strabon = new Strabon(databaseName, username, password, Integer.parseInt(port), serverName, true); 3.141 - } 3.142 - 3.143 - public static void storeDataset(String datasetFile) throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 3.144 - { 3.145 - if(datasetFile.endsWith(".nt")) 3.146 - strabon.storeInRepo(datasetFile, "NTRIPLES"); 3.147 - else if(datasetFile.endsWith(".nq")) 3.148 - strabon.storeInRepo(datasetFile, "NQUADS"); 3.149 - } 3.150 - 3.151 - public static void testQuery(String queryFile, String resultsFile) throws IOException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, URISyntaxException, QueryResultParseException, UnsupportedQueryResultFormatException 3.152 - { 3.153 - ByteArrayOutputStream resultsStream = new ByteArrayOutputStream(); 3.154 - String query = FileUtils.readFileToString(new File(Utils.class.getResource(queryFile).toURI())); 3.155 - 3.156 - //Pose the query 3.157 - strabon.query(query, Format.XML, strabon.getSailRepoConnection(), resultsStream); 3.158 - 3.159 - //Check if the results of the query are the expected 3.160 - TupleQueryResult expectedResults = QueryResultIO.parse(Utils.class.getResourceAsStream(resultsFile), TupleQueryResultFormat.SPARQL); 3.161 - TupleQueryResult actualResults = QueryResultIO.parse((new ByteArrayInputStream(resultsStream.toByteArray())), TupleQueryResultFormat.SPARQL); 3.162 - 3.163 - List<String> eBindingNames = expectedResults.getBindingNames(); 3.164 - List<String> aBindingNames = actualResults.getBindingNames(); 3.165 - assertTrue("Results are not the expected.", aBindingNames.containsAll(aBindingNames) && eBindingNames.containsAll(aBindingNames)); 3.166 - 3.167 - //Sort each binding's values 3.168 - List<String> eBindingList = new ArrayList<String>(); 3.169 - List<String> aBindingList = new ArrayList<String>(); 3.170 - 3.171 - while(expectedResults.hasNext() && actualResults.hasNext()) 3.172 - { 3.173 - BindingSet eBinding = expectedResults.next(); 3.174 - BindingSet aBinding = actualResults.next(); 3.175 - 3.176 - String eBindingValues=""; 3.177 - String aBindingValues=""; 3.178 - for(String bindingName : eBindingNames) 3.179 - { 3.180 - eBindingValues+=eBinding.getValue(bindingName).stringValue(); 3.181 - aBindingValues+=aBinding.getValue(bindingName).stringValue(); 3.182 - } 3.183 - 3.184 - eBindingList.add(eBindingValues); 3.185 - aBindingList.add(aBindingValues); 3.186 - } 3.187 - 3.188 - assertFalse("Results are not the expected.", expectedResults.hasNext() || actualResults.hasNext()); 3.189 - 3.190 - //Sort bindings alphabetically 3.191 - Collections.sort(eBindingList); 3.192 - Collections.sort(aBindingList); 3.193 - 3.194 - //Check bindings one by one 3.195 - Iterator<String> eBindingListIterator = eBindingList.iterator(); 3.196 - Iterator<String> aBindingListIterator = aBindingList.iterator(); 3.197 - 3.198 - while(eBindingListIterator.hasNext() && aBindingListIterator.hasNext()) 3.199 - { 3.200 - assertEquals("Results are not the expected.", eBindingListIterator.next(), aBindingListIterator.next()); 3.201 - } 3.202 - 3.203 - actualResults.close(); 3.204 - expectedResults.close(); 3.205 - } 3.206 - 3.207 - public static void dropdb() throws SQLException 3.208 - { 3.209 - strabon.close(); 3.210 - 3.211 - //Drop the temp database 3.212 - conn.close(); 3.213 - String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; 3.214 - conn = DriverManager.getConnection(url, username, password); 3.215 - 3.216 - PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName); 3.217 - pst.executeUpdate(); 3.218 - pst.close(); 3.219 - conn.close(); 3.220 - } 3.221 -}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/testsuite/src/test/java/eu/earthobservatory/testsuite/bugs/StoreTest.java Thu Apr 18 13:27:06 2013 +0300 4.3 @@ -0,0 +1,20 @@ 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, 2013 Pyravlos Team 4.10 + * 4.11 + * http://www.strabon.di.uoa.gr/ 4.12 + */ 4.13 +package eu.earthobservatory.testsuite.bugs; 4.14 + 4.15 +import eu.earthobservatory.testsuite.utils.TemplateTest; 4.16 + 4.17 + 4.18 +/** 4.19 + * A simple store test. It tests if the input dataset is stored and retrieved correctly. 4.20 + * 4.21 + * @author Panayiotis Smeros <psmeros@di.uoa.gr 4.22 + */ 4.23 +public class StoreTest extends TemplateTest{}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/testsuite/src/test/java/eu/earthobservatory/testsuite/utils/TemplateTest.java Thu Apr 18 13:27:06 2013 +0300 5.3 @@ -0,0 +1,68 @@ 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, 2013 Pyravlos Team 5.10 + * 5.11 + * http://www.strabon.di.uoa.gr/ 5.12 + */ 5.13 +package eu.earthobservatory.testsuite.utils; 5.14 + 5.15 +import org.junit.After; 5.16 +import org.junit.Before; 5.17 +import org.junit.Test; 5.18 + 5.19 + 5.20 +/** 5.21 + * A template test. It: 5.22 + * 1) creates a database 5.23 + * 2) stores a dataset 5.24 + * 3) poses a query 5.25 + * 4) checks if the results of the query are the expected 5.26 + * 5) drops the database 5.27 + * 5.28 + * @author Panayiotis Smeros <psmeros@di.uoa.gr 5.29 + */ 5.30 +public abstract class TemplateTest 5.31 +{ 5.32 + private String datasetFile; 5.33 + private String queryFile; 5.34 + private String resultsFile; 5.35 + 5.36 + public TemplateTest(String datasetFile, String queryFile, String resultsFile) 5.37 + { 5.38 + this.datasetFile = datasetFile; 5.39 + this.queryFile = queryFile; 5.40 + this.resultsFile = resultsFile; 5.41 + } 5.42 + 5.43 + public TemplateTest() 5.44 + { 5.45 + String testname=this.getClass().getSimpleName(); 5.46 + String testpackage=this.getClass().getPackage().getName().substring(this.getClass().getPackage().getName().lastIndexOf('.')+1); 5.47 + 5.48 + this.datasetFile="/"+testpackage+"/"+testname+"/"+testname+".nt"; 5.49 + this.queryFile="/"+testpackage+"/"+testname+"/"+testname+".rq"; 5.50 + this.resultsFile="/"+testpackage+"/"+testname+"/"+testname+".srx"; 5.51 + } 5.52 + 5.53 + @Before 5.54 + public void before() throws Exception 5.55 + { 5.56 + Utils.createdb(); 5.57 + Utils.storeDataset(datasetFile); 5.58 + } 5.59 + 5.60 + @Test 5.61 + public void test() throws Exception 5.62 + { 5.63 + Utils.testQuery(queryFile, resultsFile); 5.64 + } 5.65 + 5.66 + @After 5.67 + public void after() throws Exception 5.68 + { 5.69 + Utils.dropdb(); 5.70 + } 5.71 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/testsuite/src/test/java/eu/earthobservatory/testsuite/utils/Utils.java Thu Apr 18 13:27:06 2013 +0300 6.3 @@ -0,0 +1,219 @@ 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, 2013 Pyravlos Team 6.10 + * 6.11 + * http://www.strabon.di.uoa.gr/ 6.12 + */ 6.13 +package eu.earthobservatory.testsuite.utils; 6.14 + 6.15 +import static org.junit.Assert.assertEquals; 6.16 +import static org.junit.Assert.assertFalse; 6.17 +import static org.junit.Assert.assertTrue; 6.18 +import java.io.ByteArrayInputStream; 6.19 +import java.io.ByteArrayOutputStream; 6.20 +import java.io.File; 6.21 +import java.io.IOException; 6.22 +import java.io.InputStream; 6.23 +import java.net.URISyntaxException; 6.24 +import java.sql.Connection; 6.25 +import java.sql.DriverManager; 6.26 +import java.sql.PreparedStatement; 6.27 +import java.sql.ResultSet; 6.28 +import java.sql.SQLException; 6.29 +import java.util.ArrayList; 6.30 +import java.util.Collections; 6.31 +import java.util.Iterator; 6.32 +import java.util.List; 6.33 +import java.util.Properties; 6.34 +import org.apache.commons.io.FileUtils; 6.35 +import org.openrdf.query.BindingSet; 6.36 +import org.openrdf.query.MalformedQueryException; 6.37 +import org.openrdf.query.QueryEvaluationException; 6.38 +import org.openrdf.query.TupleQueryResult; 6.39 +import org.openrdf.query.TupleQueryResultHandlerException; 6.40 +import org.openrdf.query.resultio.QueryResultIO; 6.41 +import org.openrdf.query.resultio.QueryResultParseException; 6.42 +import org.openrdf.query.resultio.TupleQueryResultFormat; 6.43 +import org.openrdf.query.resultio.UnsupportedQueryResultFormatException; 6.44 +import org.openrdf.repository.RepositoryException; 6.45 +import org.openrdf.rio.RDFHandlerException; 6.46 +import org.openrdf.rio.RDFParseException; 6.47 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 6.48 +import eu.earthobservatory.runtime.postgis.Strabon; 6.49 +import eu.earthobservatory.utils.Format; 6.50 + 6.51 +/** 6.52 + * A class with useful methods for the tests. 6.53 + * 6.54 + * @author Panayiotis Smeros <psmeros@di.uoa.gr> 6.55 + */ 6.56 +public class Utils 6.57 +{ 6.58 + private static final String dbPropertiesFile="/databases.properties"; 6.59 + 6.60 + private static String databaseTemplateName = null; 6.61 + private static String defaultUser = null; 6.62 + private static String serverName = null; 6.63 + private static String username = null; 6.64 + private static String password = null; 6.65 + private static String port = null; 6.66 + 6.67 + private static Connection conn = null; 6.68 + private static String databaseName = null; 6.69 + 6.70 + private static Strabon strabon = null; 6.71 + 6.72 + public static void createdb() throws Exception 6.73 + { 6.74 + String url=""; 6.75 + ArrayList<String> databases=new ArrayList<String>(); 6.76 + PreparedStatement pst = null; 6.77 + 6.78 + //Read properties 6.79 + Properties properties = new Properties(); 6.80 + InputStream propertiesStream = Utils.class.getResourceAsStream(dbPropertiesFile); 6.81 + properties.load(propertiesStream); 6.82 + 6.83 + if((databaseTemplateName = System.getProperty("postgis.databaseTemplateName"))==null) 6.84 + { 6.85 + databaseTemplateName = properties.getProperty("postgis.databaseTemplateName"); 6.86 + } 6.87 + 6.88 + if((defaultUser = System.getProperty("postgis.defaultUser"))==null) 6.89 + { 6.90 + defaultUser = properties.getProperty("postgis.defaultUser"); 6.91 + } 6.92 + 6.93 + if((serverName = System.getProperty("postgis.serverName"))==null) 6.94 + { 6.95 + serverName = properties.getProperty("postgis.serverName"); 6.96 + } 6.97 + 6.98 + if((username = System.getProperty("postgis.username"))==null) 6.99 + { 6.100 + username = properties.getProperty("postgis.username"); 6.101 + } 6.102 + 6.103 + if((password = System.getProperty("postgis.password"))==null) 6.104 + { 6.105 + password = properties.getProperty("postgis.password"); 6.106 + } 6.107 + 6.108 + if((port = System.getProperty("postgis.port"))==null) 6.109 + { 6.110 + port = properties.getProperty("postgis.port"); 6.111 + } 6.112 + 6.113 + //Connect to server and create the temp database 6.114 + url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; 6.115 + conn = DriverManager.getConnection(url, username, password); 6.116 + 6.117 + pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); 6.118 + ResultSet rs = pst.executeQuery(); 6.119 + 6.120 + while (rs.next()) 6.121 + { 6.122 + databases.add(rs.getString(1)); 6.123 + } 6.124 + rs.close(); 6.125 + pst.close(); 6.126 + 6.127 + databaseName="teststrabon"+(int)(Math.random()*10000); 6.128 + while(databases.contains(databaseName)) 6.129 + { 6.130 + databaseName+="0"; 6.131 + } 6.132 + 6.133 + pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName); 6.134 + pst.executeUpdate(); 6.135 + pst.close(); 6.136 + conn.close(); 6.137 + 6.138 + url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; 6.139 + conn = DriverManager.getConnection(url, username, password); 6.140 + 6.141 + strabon = new Strabon(databaseName, username, password, Integer.parseInt(port), serverName, true); 6.142 + } 6.143 + 6.144 + public static void storeDataset(String datasetFile) throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 6.145 + { 6.146 + if(datasetFile.endsWith(".nt")) 6.147 + strabon.storeInRepo(datasetFile, "NTRIPLES"); 6.148 + else if(datasetFile.endsWith(".nq")) 6.149 + strabon.storeInRepo(datasetFile, "NQUADS"); 6.150 + } 6.151 + 6.152 + public static void testQuery(String queryFile, String resultsFile) throws IOException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, URISyntaxException, QueryResultParseException, UnsupportedQueryResultFormatException 6.153 + { 6.154 + ByteArrayOutputStream resultsStream = new ByteArrayOutputStream(); 6.155 + String query = FileUtils.readFileToString(new File(Utils.class.getResource(queryFile).toURI())); 6.156 + 6.157 + //Pose the query 6.158 + strabon.query(query, Format.XML, strabon.getSailRepoConnection(), resultsStream); 6.159 + 6.160 + //Check if the results of the query are the expected 6.161 + TupleQueryResult expectedResults = QueryResultIO.parse(Utils.class.getResourceAsStream(resultsFile), TupleQueryResultFormat.SPARQL); 6.162 + TupleQueryResult actualResults = QueryResultIO.parse((new ByteArrayInputStream(resultsStream.toByteArray())), TupleQueryResultFormat.SPARQL); 6.163 + 6.164 + List<String> eBindingNames = expectedResults.getBindingNames(); 6.165 + List<String> aBindingNames = actualResults.getBindingNames(); 6.166 + assertTrue("Results are not the expected.", aBindingNames.containsAll(aBindingNames) && eBindingNames.containsAll(aBindingNames)); 6.167 + 6.168 + //Sort each binding's values 6.169 + List<String> eBindingList = new ArrayList<String>(); 6.170 + List<String> aBindingList = new ArrayList<String>(); 6.171 + 6.172 + while(expectedResults.hasNext() && actualResults.hasNext()) 6.173 + { 6.174 + BindingSet eBinding = expectedResults.next(); 6.175 + BindingSet aBinding = actualResults.next(); 6.176 + 6.177 + String eBindingValues=""; 6.178 + String aBindingValues=""; 6.179 + for(String bindingName : eBindingNames) 6.180 + { 6.181 + eBindingValues+=eBinding.getValue(bindingName).stringValue(); 6.182 + aBindingValues+=aBinding.getValue(bindingName).stringValue(); 6.183 + } 6.184 + 6.185 + eBindingList.add(eBindingValues); 6.186 + aBindingList.add(aBindingValues); 6.187 + } 6.188 + 6.189 + assertFalse("Results are not the expected.", expectedResults.hasNext() || actualResults.hasNext()); 6.190 + 6.191 + //Sort bindings alphabetically 6.192 + Collections.sort(eBindingList); 6.193 + Collections.sort(aBindingList); 6.194 + 6.195 + //Check bindings one by one 6.196 + Iterator<String> eBindingListIterator = eBindingList.iterator(); 6.197 + Iterator<String> aBindingListIterator = aBindingList.iterator(); 6.198 + 6.199 + while(eBindingListIterator.hasNext() && aBindingListIterator.hasNext()) 6.200 + { 6.201 + assertEquals("Results are not the expected.", eBindingListIterator.next(), aBindingListIterator.next()); 6.202 + } 6.203 + 6.204 + actualResults.close(); 6.205 + expectedResults.close(); 6.206 + } 6.207 + 6.208 + public static void dropdb() throws SQLException 6.209 + { 6.210 + strabon.close(); 6.211 + 6.212 + //Drop the temp database 6.213 + conn.close(); 6.214 + String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; 6.215 + conn = DriverManager.getConnection(url, username, password); 6.216 + 6.217 + PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName); 6.218 + pst.executeUpdate(); 6.219 + pst.close(); 6.220 + conn.close(); 6.221 + } 6.222 +}
7.1 --- a/testsuite/src/test/resources/StoreTest/StoreTest.nt Wed Apr 17 18:56:04 2013 +0300 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,9 +0,0 @@ 7.4 -<http://example.org/item1> <http://example.org/id> "1"^^<http://www.w3.org/2001/XMLSchema#int>. 7.5 -<http://example.org/item1> <http://example.org/value> "10"^^<http://www.w3.org/2001/XMLSchema#int>. 7.6 -<http://example.org/item1> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(1 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>. 7.7 -<http://example.org/item2> <http://example.org/id> "2"^^<http://www.w3.org/2001/XMLSchema#int>. 7.8 -<http://example.org/item2> <http://example.org/value> "20"^^<http://www.w3.org/2001/XMLSchema#int>. 7.9 -<http://example.org/item2> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(2 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>. 7.10 -<http://example.org/item3> <http://example.org/id> "3"^^<http://www.w3.org/2001/XMLSchema#int>. 7.11 -<http://example.org/item3> <http://example.org/value> "30"^^<http://www.w3.org/2001/XMLSchema#int>. 7.12 -<http://example.org/item3> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(3 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>.
8.1 --- a/testsuite/src/test/resources/StoreTest/StoreTest.rq Wed Apr 17 18:56:04 2013 +0300 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,2 +0,0 @@ 8.4 -SELECT * 8.5 -WHERE{?s ?p ?o} 8.6 \ No newline at end of file
9.1 --- a/testsuite/src/test/resources/StoreTest/StoreTest.srx Wed Apr 17 18:56:04 2013 +0300 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,109 +0,0 @@ 9.4 -<?xml version='1.0' encoding='UTF-8'?> 9.5 -<sparql xmlns='http://www.w3.org/2005/sparql-results#'> 9.6 - <head> 9.7 - <variable name='s'/> 9.8 - <variable name='p'/> 9.9 - <variable name='o'/> 9.10 - </head> 9.11 - <results> 9.12 - <result> 9.13 - <binding name='s'> 9.14 - <uri>http://example.org/item1</uri> 9.15 - </binding> 9.16 - <binding name='o'> 9.17 - <literal datatype='http://www.w3.org/2001/XMLSchema#int'>1</literal> 9.18 - </binding> 9.19 - <binding name='p'> 9.20 - <uri>http://example.org/id</uri> 9.21 - </binding> 9.22 - </result> 9.23 - <result> 9.24 - <binding name='s'> 9.25 - <uri>http://example.org/item1</uri> 9.26 - </binding> 9.27 - <binding name='o'> 9.28 - <literal datatype='http://www.w3.org/2001/XMLSchema#int'>10</literal> 9.29 - </binding> 9.30 - <binding name='p'> 9.31 - <uri>http://example.org/value</uri> 9.32 - </binding> 9.33 - </result> 9.34 - <result> 9.35 - <binding name='s'> 9.36 - <uri>http://example.org/item1</uri> 9.37 - </binding> 9.38 - <binding name='o'> 9.39 - <literal datatype='http://strdf.di.uoa.gr/ontology#WKT'>POINT(1 0)</literal> 9.40 - </binding> 9.41 - <binding name='p'> 9.42 - <uri>http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry</uri> 9.43 - </binding> 9.44 - </result> 9.45 - <result> 9.46 - <binding name='s'> 9.47 - <uri>http://example.org/item2</uri> 9.48 - </binding> 9.49 - <binding name='o'> 9.50 - <literal datatype='http://www.w3.org/2001/XMLSchema#int'>2</literal> 9.51 - </binding> 9.52 - <binding name='p'> 9.53 - <uri>http://example.org/id</uri> 9.54 - </binding> 9.55 - </result> 9.56 - <result> 9.57 - <binding name='s'> 9.58 - <uri>http://example.org/item2</uri> 9.59 - </binding> 9.60 - <binding name='o'> 9.61 - <literal datatype='http://www.w3.org/2001/XMLSchema#int'>20</literal> 9.62 - </binding> 9.63 - <binding name='p'> 9.64 - <uri>http://example.org/value</uri> 9.65 - </binding> 9.66 - </result> 9.67 - <result> 9.68 - <binding name='s'> 9.69 - <uri>http://example.org/item2</uri> 9.70 - </binding> 9.71 - <binding name='o'> 9.72 - <literal datatype='http://strdf.di.uoa.gr/ontology#WKT'>POINT(2 0)</literal> 9.73 - </binding> 9.74 - <binding name='p'> 9.75 - <uri>http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry</uri> 9.76 - </binding> 9.77 - </result> 9.78 - <result> 9.79 - <binding name='s'> 9.80 - <uri>http://example.org/item3</uri> 9.81 - </binding> 9.82 - <binding name='o'> 9.83 - <literal datatype='http://www.w3.org/2001/XMLSchema#int'>3</literal> 9.84 - </binding> 9.85 - <binding name='p'> 9.86 - <uri>http://example.org/id</uri> 9.87 - </binding> 9.88 - </result> 9.89 - <result> 9.90 - <binding name='s'> 9.91 - <uri>http://example.org/item3</uri> 9.92 - </binding> 9.93 - <binding name='o'> 9.94 - <literal datatype='http://www.w3.org/2001/XMLSchema#int'>30</literal> 9.95 - </binding> 9.96 - <binding name='p'> 9.97 - <uri>http://example.org/value</uri> 9.98 - </binding> 9.99 - </result> 9.100 - <result> 9.101 - <binding name='s'> 9.102 - <uri>http://example.org/item3</uri> 9.103 - </binding> 9.104 - <binding name='o'> 9.105 - <literal datatype='http://strdf.di.uoa.gr/ontology#WKT'>POINT(3 0)</literal> 9.106 - </binding> 9.107 - <binding name='p'> 9.108 - <uri>http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry</uri> 9.109 - </binding> 9.110 - </result> 9.111 - </results> 9.112 -</sparql> 9.113 \ No newline at end of file
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/testsuite/src/test/resources/bugs/StoreTest/StoreTest.nt Thu Apr 18 13:27:06 2013 +0300 10.3 @@ -0,0 +1,9 @@ 10.4 +<http://example.org/item1> <http://example.org/id> "1"^^<http://www.w3.org/2001/XMLSchema#int>. 10.5 +<http://example.org/item1> <http://example.org/value> "10"^^<http://www.w3.org/2001/XMLSchema#int>. 10.6 +<http://example.org/item1> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(1 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>. 10.7 +<http://example.org/item2> <http://example.org/id> "2"^^<http://www.w3.org/2001/XMLSchema#int>. 10.8 +<http://example.org/item2> <http://example.org/value> "20"^^<http://www.w3.org/2001/XMLSchema#int>. 10.9 +<http://example.org/item2> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(2 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>. 10.10 +<http://example.org/item3> <http://example.org/id> "3"^^<http://www.w3.org/2001/XMLSchema#int>. 10.11 +<http://example.org/item3> <http://example.org/value> "30"^^<http://www.w3.org/2001/XMLSchema#int>. 10.12 +<http://example.org/item3> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(3 0)"^^<http://strdf.di.uoa.gr/ontology#WKT>.
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/testsuite/src/test/resources/bugs/StoreTest/StoreTest.rq Thu Apr 18 13:27:06 2013 +0300 11.3 @@ -0,0 +1,2 @@ 11.4 +SELECT * 11.5 +WHERE{?s ?p ?o} 11.6 \ No newline at end of file
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/testsuite/src/test/resources/bugs/StoreTest/StoreTest.srx Thu Apr 18 13:27:06 2013 +0300 12.3 @@ -0,0 +1,109 @@ 12.4 +<?xml version='1.0' encoding='UTF-8'?> 12.5 +<sparql xmlns='http://www.w3.org/2005/sparql-results#'> 12.6 + <head> 12.7 + <variable name='s'/> 12.8 + <variable name='p'/> 12.9 + <variable name='o'/> 12.10 + </head> 12.11 + <results> 12.12 + <result> 12.13 + <binding name='s'> 12.14 + <uri>http://example.org/item1</uri> 12.15 + </binding> 12.16 + <binding name='o'> 12.17 + <literal datatype='http://www.w3.org/2001/XMLSchema#int'>1</literal> 12.18 + </binding> 12.19 + <binding name='p'> 12.20 + <uri>http://example.org/id</uri> 12.21 + </binding> 12.22 + </result> 12.23 + <result> 12.24 + <binding name='s'> 12.25 + <uri>http://example.org/item1</uri> 12.26 + </binding> 12.27 + <binding name='o'> 12.28 + <literal datatype='http://www.w3.org/2001/XMLSchema#int'>10</literal> 12.29 + </binding> 12.30 + <binding name='p'> 12.31 + <uri>http://example.org/value</uri> 12.32 + </binding> 12.33 + </result> 12.34 + <result> 12.35 + <binding name='s'> 12.36 + <uri>http://example.org/item1</uri> 12.37 + </binding> 12.38 + <binding name='o'> 12.39 + <literal datatype='http://strdf.di.uoa.gr/ontology#WKT'>POINT(1 0)</literal> 12.40 + </binding> 12.41 + <binding name='p'> 12.42 + <uri>http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry</uri> 12.43 + </binding> 12.44 + </result> 12.45 + <result> 12.46 + <binding name='s'> 12.47 + <uri>http://example.org/item2</uri> 12.48 + </binding> 12.49 + <binding name='o'> 12.50 + <literal datatype='http://www.w3.org/2001/XMLSchema#int'>2</literal> 12.51 + </binding> 12.52 + <binding name='p'> 12.53 + <uri>http://example.org/id</uri> 12.54 + </binding> 12.55 + </result> 12.56 + <result> 12.57 + <binding name='s'> 12.58 + <uri>http://example.org/item2</uri> 12.59 + </binding> 12.60 + <binding name='o'> 12.61 + <literal datatype='http://www.w3.org/2001/XMLSchema#int'>20</literal> 12.62 + </binding> 12.63 + <binding name='p'> 12.64 + <uri>http://example.org/value</uri> 12.65 + </binding> 12.66 + </result> 12.67 + <result> 12.68 + <binding name='s'> 12.69 + <uri>http://example.org/item2</uri> 12.70 + </binding> 12.71 + <binding name='o'> 12.72 + <literal datatype='http://strdf.di.uoa.gr/ontology#WKT'>POINT(2 0)</literal> 12.73 + </binding> 12.74 + <binding name='p'> 12.75 + <uri>http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry</uri> 12.76 + </binding> 12.77 + </result> 12.78 + <result> 12.79 + <binding name='s'> 12.80 + <uri>http://example.org/item3</uri> 12.81 + </binding> 12.82 + <binding name='o'> 12.83 + <literal datatype='http://www.w3.org/2001/XMLSchema#int'>3</literal> 12.84 + </binding> 12.85 + <binding name='p'> 12.86 + <uri>http://example.org/id</uri> 12.87 + </binding> 12.88 + </result> 12.89 + <result> 12.90 + <binding name='s'> 12.91 + <uri>http://example.org/item3</uri> 12.92 + </binding> 12.93 + <binding name='o'> 12.94 + <literal datatype='http://www.w3.org/2001/XMLSchema#int'>30</literal> 12.95 + </binding> 12.96 + <binding name='p'> 12.97 + <uri>http://example.org/value</uri> 12.98 + </binding> 12.99 + </result> 12.100 + <result> 12.101 + <binding name='s'> 12.102 + <uri>http://example.org/item3</uri> 12.103 + </binding> 12.104 + <binding name='o'> 12.105 + <literal datatype='http://strdf.di.uoa.gr/ontology#WKT'>POINT(3 0)</literal> 12.106 + </binding> 12.107 + <binding name='p'> 12.108 + <uri>http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry</uri> 12.109 + </binding> 12.110 + </result> 12.111 + </results> 12.112 +</sparql> 12.113 \ No newline at end of file