Strabon
changeset 166:fe2a47b9de64
Add TemplateTests for monetdb
author | George Garbis <ggarbis@di.uoa.gr> |
---|---|
date | Fri May 18 15:55:07 2012 +0300 (2012-05-18) |
parents | 3b5c0610b747 |
children | 693894391629 |
files | .hgignore runtime/src/test/java/eu/earthobservatory/runtime/monetdb/TemplateTests.java |
line diff
1.1 --- a/.hgignore Fri May 18 15:47:31 2012 +0300 1.2 +++ b/.hgignore Fri May 18 15:55:07 2012 +0300 1.3 @@ -5,3 +5,5 @@ 1.4 pom.xml~ 1.5 ~$ 1.6 .extract$ 1.7 +runtime/src/test/java/eu/earthobservatory/runtime/generaldb/TempClass.java 1.8 +runtime/src/test/resources/ntriples/aggregate-tests.ntriples
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/monetdb/TemplateTests.java Fri May 18 15:55:07 2012 +0300 2.3 @@ -0,0 +1,121 @@ 2.4 +package eu.earthobservatory.runtime.monetdb; 2.5 + 2.6 +import java.io.IOException; 2.7 +import java.io.InputStream; 2.8 +import java.net.URL; 2.9 +import java.sql.DriverManager; 2.10 +import java.sql.ResultSet; 2.11 +import java.sql.SQLException; 2.12 +import java.sql.Statement; 2.13 +import java.util.Properties; 2.14 + 2.15 +import org.junit.AfterClass; 2.16 +import org.junit.BeforeClass; 2.17 +import org.openrdf.repository.RepositoryException; 2.18 +import org.openrdf.rio.RDFHandlerException; 2.19 +import org.openrdf.rio.RDFParseException; 2.20 + 2.21 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 2.22 +import eu.earthobservatory.runtime.generaldb.SimpleTests; 2.23 +import eu.earthobservatory.runtime.postgis.Strabon; 2.24 + 2.25 +/** 2.26 + * A set of simple tests on SPARQL query functionality 2.27 + * 2.28 + * @author George Garbis 2.29 + */ 2.30 + 2.31 +public class TemplateTests { 2.32 + 2.33 + public static Strabon strabon; 2.34 + 2.35 + public static java.sql.Connection conn = null; 2.36 + public static String databaseName = null; 2.37 + 2.38 + public static String jdbcDriver = null; 2.39 + public static String serverName = null; 2.40 + public static String username = null; 2.41 + public static String password = null; 2.42 + public static Integer port = null; 2.43 + 2.44 + @BeforeClass 2.45 + public static void beforeClass(String inputFile) throws SQLException, ClassNotFoundException, RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 2.46 + { 2.47 + // Read properties 2.48 + Properties properties = new Properties(); 2.49 + InputStream propertiesStream = SimpleTests.class.getResourceAsStream("/databases.properties"); 2.50 + properties.load(propertiesStream); 2.51 + 2.52 + serverName = properties.getProperty("monetdb.serverName"); 2.53 + databaseName = properties.getProperty("monetdb.databaseName"); 2.54 + port = Integer.parseInt(properties.getProperty("monetdb.port")); 2.55 + username = properties.getProperty("monetdb.username"); 2.56 + password = properties.getProperty("monetdb.password"); 2.57 + 2.58 + // Connect to database 2.59 + Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); 2.60 + String url = "jdbc:monetdb://"+serverName+":"+port+"/"+databaseName; 2.61 + conn = DriverManager.getConnection(url, username, password); 2.62 + 2.63 +// // Clean database 2.64 + Statement stmt = conn.createStatement(); 2.65 + ResultSet results = stmt.executeQuery("SELECT name FROM tables WHERE system=false AND name <> 'locked'"); 2.66 + while (results.next()) { 2.67 + String table_name = results.getString("name"); 2.68 + Statement stmt2 = conn.createStatement(); 2.69 + stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 2.70 + stmt2.close(); 2.71 + } 2.72 + stmt.close(); 2.73 + 2.74 + strabon = new Strabon(databaseName, username, password, port, serverName, true); 2.75 + 2.76 + loadTestData(inputFile); 2.77 + } 2.78 + 2.79 + @AfterClass 2.80 + public static void afterClass() throws SQLException 2.81 + { 2.82 + strabon.close(); 2.83 + } 2.84 + 2.85 + protected static void loadTestData(String inputFile) 2.86 + throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault 2.87 + { 2.88 + URL src = SimpleTests.class.getResource("/simple-tests.ntriples"); 2.89 + strabon.storeInRepo(src, "NTRIPLES"); 2.90 + } 2.91 + 2.92 +// /** 2.93 +// * @throws java.lang.Exception 2.94 +// */ 2.95 +// @Before 2.96 +// public void before() 2.97 +// throws Exception 2.98 +// { 2.99 +// 2.100 +// } 2.101 +// 2.102 +// /** 2.103 +// * @throws java.lang.Exception 2.104 +// */ 2.105 +// @After 2.106 +// public void after() 2.107 +// throws Exception 2.108 +// { 2.109 +// // Clean database 2.110 +// Statement stmt = conn.createStatement(); 2.111 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 2.112 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 2.113 +// "and table_name <> 'geometry_columns' and " + 2.114 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 2.115 +// while (results.next()) { 2.116 +// String table_name = results.getString("table_name"); 2.117 +// Statement stmt2 = conn.createStatement(); 2.118 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 2.119 +// stmt2.close(); 2.120 +// } 2.121 +// 2.122 +// stmt.close(); 2.123 +// } 2.124 +}