# HG changeset patch # User Panayiotis Smeros # Date 1366280826 -10800 # Node ID bbba44d70ba515100481b5dfac71fab8e7efb4d8 # Parent 61bc2e9bf304c22a23f9701bcea5d11c5cc43c92 Re-organized packages. diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/java/eu/earthobservatory/runtime/postgis/StoreTest.java --- a/testsuite/src/test/java/eu/earthobservatory/runtime/postgis/StoreTest.java Wed Apr 17 18:56:04 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team - * - * http://www.strabon.di.uoa.gr/ - */ -package eu.earthobservatory.runtime.postgis; - - -/** - * A simple store test. It tests if the input dataset is stored and retrieved correctly. - * - * @author Panayiotis Smeros - */ -public class Utils -{ - private static final String dbPropertiesFile="/databases.properties"; - - private static String databaseTemplateName = null; - private static String defaultUser = null; - private static String serverName = null; - private static String username = null; - private static String password = null; - private static String port = null; - - private static Connection conn = null; - private static String databaseName = null; - - private static Strabon strabon = null; - - public static void createdb() throws Exception - { - String url=""; - ArrayList databases=new ArrayList(); - PreparedStatement pst = null; - - //Read properties - Properties properties = new Properties(); - InputStream propertiesStream = Utils.class.getResourceAsStream(dbPropertiesFile); - properties.load(propertiesStream); - - if((databaseTemplateName = System.getProperty("postgis.databaseTemplateName"))==null) - { - databaseTemplateName = properties.getProperty("postgis.databaseTemplateName"); - } - - if((defaultUser = System.getProperty("postgis.defaultUser"))==null) - { - defaultUser = properties.getProperty("postgis.defaultUser"); - } - - if((serverName = System.getProperty("postgis.serverName"))==null) - { - serverName = properties.getProperty("postgis.serverName"); - } - - if((username = System.getProperty("postgis.username"))==null) - { - username = properties.getProperty("postgis.username"); - } - - if((password = System.getProperty("postgis.password"))==null) - { - password = properties.getProperty("postgis.password"); - } - - if((port = System.getProperty("postgis.port"))==null) - { - port = properties.getProperty("postgis.port"); - } - - //Connect to server and create the temp database - url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; - conn = DriverManager.getConnection(url, username, password); - - pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); - ResultSet rs = pst.executeQuery(); - - while (rs.next()) - { - databases.add(rs.getString(1)); - } - rs.close(); - pst.close(); - - databaseName="teststrabon"+(int)(Math.random()*10000); - while(databases.contains(databaseName)) - { - databaseName+="0"; - } - - pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName); - pst.executeUpdate(); - pst.close(); - conn.close(); - - url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; - conn = DriverManager.getConnection(url, username, password); - - strabon = new Strabon(databaseName, username, password, Integer.parseInt(port), serverName, true); - } - - public static void storeDataset(String datasetFile) throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault - { - if(datasetFile.endsWith(".nt")) - strabon.storeInRepo(datasetFile, "NTRIPLES"); - else if(datasetFile.endsWith(".nq")) - strabon.storeInRepo(datasetFile, "NQUADS"); - } - - public static void testQuery(String queryFile, String resultsFile) throws IOException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, URISyntaxException, QueryResultParseException, UnsupportedQueryResultFormatException - { - ByteArrayOutputStream resultsStream = new ByteArrayOutputStream(); - String query = FileUtils.readFileToString(new File(Utils.class.getResource(queryFile).toURI())); - - //Pose the query - strabon.query(query, Format.XML, strabon.getSailRepoConnection(), resultsStream); - - //Check if the results of the query are the expected - TupleQueryResult expectedResults = QueryResultIO.parse(Utils.class.getResourceAsStream(resultsFile), TupleQueryResultFormat.SPARQL); - TupleQueryResult actualResults = QueryResultIO.parse((new ByteArrayInputStream(resultsStream.toByteArray())), TupleQueryResultFormat.SPARQL); - - List eBindingNames = expectedResults.getBindingNames(); - List aBindingNames = actualResults.getBindingNames(); - assertTrue("Results are not the expected.", aBindingNames.containsAll(aBindingNames) && eBindingNames.containsAll(aBindingNames)); - - //Sort each binding's values - List eBindingList = new ArrayList(); - List aBindingList = new ArrayList(); - - while(expectedResults.hasNext() && actualResults.hasNext()) - { - BindingSet eBinding = expectedResults.next(); - BindingSet aBinding = actualResults.next(); - - String eBindingValues=""; - String aBindingValues=""; - for(String bindingName : eBindingNames) - { - eBindingValues+=eBinding.getValue(bindingName).stringValue(); - aBindingValues+=aBinding.getValue(bindingName).stringValue(); - } - - eBindingList.add(eBindingValues); - aBindingList.add(aBindingValues); - } - - assertFalse("Results are not the expected.", expectedResults.hasNext() || actualResults.hasNext()); - - //Sort bindings alphabetically - Collections.sort(eBindingList); - Collections.sort(aBindingList); - - //Check bindings one by one - Iterator eBindingListIterator = eBindingList.iterator(); - Iterator aBindingListIterator = aBindingList.iterator(); - - while(eBindingListIterator.hasNext() && aBindingListIterator.hasNext()) - { - assertEquals("Results are not the expected.", eBindingListIterator.next(), aBindingListIterator.next()); - } - - actualResults.close(); - expectedResults.close(); - } - - public static void dropdb() throws SQLException - { - strabon.close(); - - //Drop the temp database - conn.close(); - String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; - conn = DriverManager.getConnection(url, username, password); - - PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName); - pst.executeUpdate(); - pst.close(); - conn.close(); - } -} diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/java/eu/earthobservatory/testsuite/bugs/StoreTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/java/eu/earthobservatory/testsuite/bugs/StoreTest.java Thu Apr 18 13:27:06 2013 +0300 @@ -0,0 +1,20 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team + * + * http://www.strabon.di.uoa.gr/ + */ +package eu.earthobservatory.testsuite.bugs; + +import eu.earthobservatory.testsuite.utils.TemplateTest; + + +/** + * A simple store test. It tests if the input dataset is stored and retrieved correctly. + * + * @author Panayiotis Smeros + */ +public class Utils +{ + private static final String dbPropertiesFile="/databases.properties"; + + private static String databaseTemplateName = null; + private static String defaultUser = null; + private static String serverName = null; + private static String username = null; + private static String password = null; + private static String port = null; + + private static Connection conn = null; + private static String databaseName = null; + + private static Strabon strabon = null; + + public static void createdb() throws Exception + { + String url=""; + ArrayList databases=new ArrayList(); + PreparedStatement pst = null; + + //Read properties + Properties properties = new Properties(); + InputStream propertiesStream = Utils.class.getResourceAsStream(dbPropertiesFile); + properties.load(propertiesStream); + + if((databaseTemplateName = System.getProperty("postgis.databaseTemplateName"))==null) + { + databaseTemplateName = properties.getProperty("postgis.databaseTemplateName"); + } + + if((defaultUser = System.getProperty("postgis.defaultUser"))==null) + { + defaultUser = properties.getProperty("postgis.defaultUser"); + } + + if((serverName = System.getProperty("postgis.serverName"))==null) + { + serverName = properties.getProperty("postgis.serverName"); + } + + if((username = System.getProperty("postgis.username"))==null) + { + username = properties.getProperty("postgis.username"); + } + + if((password = System.getProperty("postgis.password"))==null) + { + password = properties.getProperty("postgis.password"); + } + + if((port = System.getProperty("postgis.port"))==null) + { + port = properties.getProperty("postgis.port"); + } + + //Connect to server and create the temp database + url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; + conn = DriverManager.getConnection(url, username, password); + + pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); + ResultSet rs = pst.executeQuery(); + + while (rs.next()) + { + databases.add(rs.getString(1)); + } + rs.close(); + pst.close(); + + databaseName="teststrabon"+(int)(Math.random()*10000); + while(databases.contains(databaseName)) + { + databaseName+="0"; + } + + pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName); + pst.executeUpdate(); + pst.close(); + conn.close(); + + url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; + conn = DriverManager.getConnection(url, username, password); + + strabon = new Strabon(databaseName, username, password, Integer.parseInt(port), serverName, true); + } + + public static void storeDataset(String datasetFile) throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault + { + if(datasetFile.endsWith(".nt")) + strabon.storeInRepo(datasetFile, "NTRIPLES"); + else if(datasetFile.endsWith(".nq")) + strabon.storeInRepo(datasetFile, "NQUADS"); + } + + public static void testQuery(String queryFile, String resultsFile) throws IOException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, URISyntaxException, QueryResultParseException, UnsupportedQueryResultFormatException + { + ByteArrayOutputStream resultsStream = new ByteArrayOutputStream(); + String query = FileUtils.readFileToString(new File(Utils.class.getResource(queryFile).toURI())); + + //Pose the query + strabon.query(query, Format.XML, strabon.getSailRepoConnection(), resultsStream); + + //Check if the results of the query are the expected + TupleQueryResult expectedResults = QueryResultIO.parse(Utils.class.getResourceAsStream(resultsFile), TupleQueryResultFormat.SPARQL); + TupleQueryResult actualResults = QueryResultIO.parse((new ByteArrayInputStream(resultsStream.toByteArray())), TupleQueryResultFormat.SPARQL); + + List eBindingNames = expectedResults.getBindingNames(); + List aBindingNames = actualResults.getBindingNames(); + assertTrue("Results are not the expected.", aBindingNames.containsAll(aBindingNames) && eBindingNames.containsAll(aBindingNames)); + + //Sort each binding's values + List eBindingList = new ArrayList(); + List aBindingList = new ArrayList(); + + while(expectedResults.hasNext() && actualResults.hasNext()) + { + BindingSet eBinding = expectedResults.next(); + BindingSet aBinding = actualResults.next(); + + String eBindingValues=""; + String aBindingValues=""; + for(String bindingName : eBindingNames) + { + eBindingValues+=eBinding.getValue(bindingName).stringValue(); + aBindingValues+=aBinding.getValue(bindingName).stringValue(); + } + + eBindingList.add(eBindingValues); + aBindingList.add(aBindingValues); + } + + assertFalse("Results are not the expected.", expectedResults.hasNext() || actualResults.hasNext()); + + //Sort bindings alphabetically + Collections.sort(eBindingList); + Collections.sort(aBindingList); + + //Check bindings one by one + Iterator eBindingListIterator = eBindingList.iterator(); + Iterator aBindingListIterator = aBindingList.iterator(); + + while(eBindingListIterator.hasNext() && aBindingListIterator.hasNext()) + { + assertEquals("Results are not the expected.", eBindingListIterator.next(), aBindingListIterator.next()); + } + + actualResults.close(); + expectedResults.close(); + } + + public static void dropdb() throws SQLException + { + strabon.close(); + + //Drop the temp database + conn.close(); + String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; + conn = DriverManager.getConnection(url, username, password); + + PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName); + pst.executeUpdate(); + pst.close(); + conn.close(); + } +} diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/resources/StoreTest/StoreTest.nt --- a/testsuite/src/test/resources/StoreTest/StoreTest.nt Wed Apr 17 18:56:04 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ - "1"^^. - "10"^^. - "POINT(1 0)"^^. - "2"^^. - "20"^^. - "POINT(2 0)"^^. - "3"^^. - "30"^^. - "POINT(3 0)"^^. diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/resources/StoreTest/StoreTest.rq --- a/testsuite/src/test/resources/StoreTest/StoreTest.rq Wed Apr 17 18:56:04 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -SELECT * -WHERE{?s ?p ?o} \ No newline at end of file diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/resources/StoreTest/StoreTest.srx --- a/testsuite/src/test/resources/StoreTest/StoreTest.srx Wed Apr 17 18:56:04 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ - - - - - - - - - - - http://example.org/item1 - - - 1 - - - http://example.org/id - - - - - http://example.org/item1 - - - 10 - - - http://example.org/value - - - - - http://example.org/item1 - - - POINT(1 0) - - - http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry - - - - - http://example.org/item2 - - - 2 - - - http://example.org/id - - - - - http://example.org/item2 - - - 20 - - - http://example.org/value - - - - - http://example.org/item2 - - - POINT(2 0) - - - http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry - - - - - http://example.org/item3 - - - 3 - - - http://example.org/id - - - - - http://example.org/item3 - - - 30 - - - http://example.org/value - - - - - http://example.org/item3 - - - POINT(3 0) - - - http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry - - - - \ No newline at end of file diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/resources/bugs/StoreTest/StoreTest.nt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/resources/bugs/StoreTest/StoreTest.nt Thu Apr 18 13:27:06 2013 +0300 @@ -0,0 +1,9 @@ + "1"^^. + "10"^^. + "POINT(1 0)"^^. + "2"^^. + "20"^^. + "POINT(2 0)"^^. + "3"^^. + "30"^^. + "POINT(3 0)"^^. diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/resources/bugs/StoreTest/StoreTest.rq --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/resources/bugs/StoreTest/StoreTest.rq Thu Apr 18 13:27:06 2013 +0300 @@ -0,0 +1,2 @@ +SELECT * +WHERE{?s ?p ?o} \ No newline at end of file diff -r 61bc2e9bf304 -r bbba44d70ba5 testsuite/src/test/resources/bugs/StoreTest/StoreTest.srx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testsuite/src/test/resources/bugs/StoreTest/StoreTest.srx Thu Apr 18 13:27:06 2013 +0300 @@ -0,0 +1,109 @@ + + + + + + + + + + + http://example.org/item1 + + + 1 + + + http://example.org/id + + + + + http://example.org/item1 + + + 10 + + + http://example.org/value + + + + + http://example.org/item1 + + + POINT(1 0) + + + http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry + + + + + http://example.org/item2 + + + 2 + + + http://example.org/id + + + + + http://example.org/item2 + + + 20 + + + http://example.org/value + + + + + http://example.org/item2 + + + POINT(2 0) + + + http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry + + + + + http://example.org/item3 + + + 3 + + + http://example.org/id + + + + + http://example.org/item3 + + + 30 + + + http://example.org/value + + + + + http://example.org/item3 + + + POINT(3 0) + + + http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry + + + + \ No newline at end of file