jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1463707 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/ jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/ jena-jdbc-core/src/test/java/org/apache/jena/jdbc/ jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/ jena-jdbc-c...
Date Tue, 02 Apr 2013 19:26:42 GMT
Author: rvesse
Date: Tue Apr  2 19:26:41 2013
New Revision: 1463707

URL: http://svn.apache.org/r1463707
Log:
Start fleshing out tests for result sets around marshalling nodes into Java primitive types

Added:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/AbstractDatasetResultSetTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/DebugDatasetConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestResultSets.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbDiskResultSets.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbMemResultSets.java
Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/   (props changed)
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/pom.xml
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/pom.xml
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java

Propchange: jena/Experimental/jena-jdbc/jena-jdbc-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Apr  2 19:26:41 2013
@@ -2,3 +2,4 @@
 .settings
 .project
 target
+test-output

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaJdbcResultSet.java
Tue Apr  2 19:26:41 2013
@@ -155,7 +155,7 @@ public abstract class JenaJdbcResultSet 
             this.setNull(true);
             return null;
         } else {
-            // Try to marshal into a boolean
+            // Try to marshal into a decimal
             this.setNull(false);
             return JenaJdbcNodeUtils.toDecimal(n);
         }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java
Tue Apr  2 19:26:41 2013
@@ -33,8 +33,6 @@ import com.hp.hpl.jena.query.ARQ;
 /**
  * Abstract tests for {@link JenaJdbcDriver} implementations
  * 
- * @author rvesse
- * 
  */
 public abstract class AbstractJenaJdbcDriverTests {
 

Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/results/AbstractResultSetTests.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,355 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.results;
+
+import java.math.BigDecimal;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Calendar;
+
+import org.apache.jena.jdbc.results.metadata.AskResultsMetadata;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.query.ARQ;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetFactory;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.vocabulary.XSD;
+
+/**
+ * Abstract tests for Jena JDBC {@link ResultSet} implementations
+ *
+ */
+public abstract class AbstractResultSetTests {
+
+    static {
+        // Init Log4j
+        BasicConfigurator.resetConfiguration();
+        BasicConfigurator.configure();
+        Logger.getRootLogger().setLevel(Level.INFO);
+
+        // Init ARQ
+        ARQ.init();
+    }
+    
+    private static Dataset empty, ds;
+    
+    /**
+     * Sets up the datasets used for the tests
+     */
+    @BeforeClass
+    public static void globalSetup() {
+        // Empty dataset
+        if (empty == null) {
+            empty = DatasetFactory.createMem();
+        }
+        
+        // Build a dataset that has one of every type we expect to
+        // commonly see
+        if (ds == null) {
+            ds = DatasetFactory.createMem();
+            
+            // Create model and our RDF terms
+            Model m = ModelFactory.createDefaultModel();
+            Resource subjUri = m.createResource("http://example/subject");
+            Resource subjBlank = m.createResource();
+            Property predUri = m.createProperty("http://example/predicate");
+            Resource objUri = m.createResource("http://example/object");
+            Resource objBlank = m.createResource();
+            Literal objSimpleLiteral = m.createLiteral("simple");
+            Literal objLangLiteral = m.createLiteral("simple", "en");
+            Literal objBoolean = m.createTypedLiteral(true);
+            Literal objByte = m.createTypedLiteral((byte)123);
+            Literal objDate = m.createTypedLiteral(Calendar.getInstance());
+            Literal objChar = m.createTypedLiteral('a');
+            Literal objDecimal = m.createTypedLiteral(new BigDecimal(123.4));
+            Literal objDouble = m.createTypedLiteral(123.4d);
+            Literal objFloat = m.createTypedLiteral(123.4f);
+            Literal objInteger = m.createTypedLiteral(1234);
+            Literal objLong = m.createTypedLiteral(1234l);
+            Literal objString = m.createTypedLiteral("typed");
+            Literal objCustom = m.createTypedLiteral("custom", TypeMapper.getInstance().getSafeTypeByName("http://example/customType"));
+            
+            m.add(new Statement[] {
+                    // Simple triples with URIs and Blank Nodes only
+                    m.createStatement(subjUri, predUri, objUri),
+                    m.createStatement(subjUri, predUri, objBlank),
+                    m.createStatement(subjBlank, predUri, objUri),
+                    m.createStatement(subjBlank, predUri, objBlank),
+                    // Simple triples with simple literals as objects
+                    m.createStatement(subjUri, predUri, objSimpleLiteral),
+                    m.createStatement(subjUri, predUri, objLangLiteral),
+                    // Triples with typed literals as objects
+                    m.createStatement(subjUri, predUri, objBoolean),
+                    m.createStatement(subjUri, predUri, objByte),
+                    m.createStatement(subjUri, predUri, objDate),
+                    m.createStatement(subjUri, predUri, objChar),
+                    m.createStatement(subjUri, predUri, objDecimal),
+                    m.createStatement(subjUri, predUri, objDouble),
+                    m.createStatement(subjUri, predUri, objFloat),
+                    m.createStatement(subjUri, predUri, objInteger),
+                    m.createStatement(subjUri, predUri, objLong),
+                    m.createStatement(subjUri, predUri, objString),
+                    m.createStatement(subjUri, predUri, objCustom)
+            });
+            ds.setDefaultModel(m);
+        }
+    }
+
+    protected abstract ResultSet createAskResult(Dataset ds, String query) throws SQLException;
+    
+    protected abstract ResultSet createSelectResults(Dataset ds, String query) throws SQLException;
+    
+    protected ResultSet createSelectResults(Model m, String query) throws SQLException {
+        Dataset ds = DatasetFactory.createMem();
+        ds.setDefaultModel(m);
+        return createSelectResults(ds, query);
+    }
+    
+    protected abstract ResultSet createConstructResults(Dataset ds, String query) throws
SQLException;
+    
+    protected ResultSet createConstructResults(Model m, String query) throws SQLException
{
+        Dataset ds = DatasetFactory.createMem();
+        ds.setDefaultModel(m);
+        return createConstructResults(ds, query);
+    }
+    
+    protected abstract ResultSet createDescribeResults(Dataset ds, String query) throws SQLException;
+    
+    protected ResultSet createDescribeResults(Model m, String query) throws SQLException
{
+        Dataset ds = DatasetFactory.createMem();
+        ds.setDefaultModel(m);
+        return createDescribeResults(ds, query);
+    }
+    
+    /**
+     * Test ASK results with a true result
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_ask_true() throws SQLException {
+        ResultSet rset = this.createAskResult(AbstractResultSetTests.empty, "ASK { }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Try to move to the result row
+        Assert.assertTrue(rset.next());
+        
+        // Check the boolean return value
+        Assert.assertTrue(rset.getBoolean(AskResultsMetadata.COLUMN_LABEL_ASK));
+        
+        // Check no further rows
+        Assert.assertFalse(rset.next());
+        Assert.assertTrue(rset.isAfterLast());
+        
+        // Close and clean up
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Test ASK results with a false result
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_ask_false() throws SQLException {
+        ResultSet rset = this.createAskResult(AbstractResultSetTests.empty, "ASK { FILTER(false)
}");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Try to move to the result row
+        Assert.assertTrue(rset.next());
+        
+        // Check the boolean return value
+        Assert.assertFalse(rset.getBoolean(AskResultsMetadata.COLUMN_LABEL_ASK));
+        
+        // Check no further rows
+        Assert.assertFalse(rset.next());
+        Assert.assertTrue(rset.isAfterLast());
+        
+        // Close and clean up
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to strings OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_strings() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT (STR(?o) AS ?str) { ?s ?p ?o
. FILTER(!ISBLANK(?o)) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("str"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to numerics OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_numerics() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(ISNUMERIC(?o))
}");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("o"));
+            // Use decimal since all numeric types should be promotable to decimal
+            Assert.assertNotEquals(0, rset.getBigDecimal("o"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to integers OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_integers() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.integer.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("o"));
+            Assert.assertNotEquals(0, rset.getInt("o"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to bytes OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_bytes() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.xbyte.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("o"));
+            Assert.assertNotEquals(0, rset.getByte("o"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to bytes OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_floats() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.xfloat.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("o"));
+            Assert.assertNotEquals(0, rset.getFloat("o"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to bytes OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_doubles() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.xdouble.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("o"));
+            Assert.assertNotEquals(0, rset.getDouble("o"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+    
+    /**
+     * Tests that SELECT result values can be marshalled to bytes OK
+     * @throws SQLException
+     */
+    @Test
+    public void test_results_select_longs() throws SQLException {
+        ResultSet rset = this.createSelectResults(ds, "SELECT ?o { ?s ?p ?o . FILTER(DATATYPE(?o)
= <" + XSD.xbyte.toString() + ">) }");
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertTrue(rset.isBeforeFirst());
+        
+        // Check all rows allow us to marshal strings OK
+        while (rset.next()) {
+            Assert.assertNotNull(rset.getString("o"));
+            Assert.assertNotEquals(0, rset.getLong("o"));
+            Assert.assertFalse(rset.wasNull());
+        }
+        
+        Assert.assertTrue(rset.isAfterLast());
+        rset.close();
+        Assert.assertTrue(rset.isClosed());
+    }
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */
+
+package org.apache.jena.jdbc.utils;
+
+import java.util.Iterator;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetAccessor;
+import com.hp.hpl.jena.query.DatasetAccessorFactory;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
+import com.hp.hpl.jena.sparql.core.Quad;
+
+/**
+ * Test utility methods
+ */
+public class TestUtils {
+
+    /**
+     * Copies one dataset to another
+     * 
+     * @param source
+     *            Source Dataset
+     * @param target
+     *            Target Dataset
+     */
+    public static void copyDataset(Dataset source, Dataset target) {
+        TestUtils.copyDataset(source, target, false);
+    }
+
+    /**
+     * Copies one dataset to another
+     * 
+     * @param source
+     *            Source Dataset
+     * @param target
+     *            Target Dataset
+     * @param copyDefaultAsQuads
+     *            Whether the default graph should be copied as quads (required
+     *            for TDB datasets)
+     * 
+     */
+    public static void copyDataset(Dataset source, Dataset target, boolean copyDefaultAsQuads)
{
+        // Copy the default graph
+        if (copyDefaultAsQuads) {
+            Iterator<Quad> quads = source.asDatasetGraph().find(Quad.defaultGraphIRI,
Node.ANY, Node.ANY, Node.ANY);
+            DatasetGraph targetDSG = target.asDatasetGraph();
+            while (quads.hasNext()) {
+                targetDSG.add(quads.next());
+            }
+        } else {
+            target.setDefaultModel(source.getDefaultModel());
+        }
+
+        // Copy named graphs
+        Iterator<String> uris = source.listNames();
+        while (uris.hasNext()) {
+            String uri = uris.next();
+            target.addNamedModel(uri, source.getNamedModel(uri));
+        }
+    }
+
+    /**
+     * Copies a dataset to a remote service that provides SPARQL 1.1 Graph Store
+     * protocol support
+     * 
+     * @param source
+     *            Source Dataset
+     * @param service
+     *            Remote Graph Store protocol service
+     */
+    public static void copyToRemoteDataset(Dataset source, String service) {
+        DatasetAccessor target = DatasetAccessorFactory.createHTTP(service);
+        target.putModel(source.getDefaultModel());
+        Iterator<String> uris = source.listNames();
+        while (uris.hasNext()) {
+            String uri = uris.next();
+            target.putModel(uri, source.getNamedModel(uri));
+        }
+    }
+
+}

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/pom.xml
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/pom.xml?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/pom.xml (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/pom.xml Tue Apr  2 19:26:41 2013
@@ -13,14 +13,14 @@
 	<properties>
 		<plugin.license.headerPath>${project.parent.basedir}</plugin.license.headerPath>
 	</properties>
-	
+
 	<dependencies>
 		<dependency>
 			<groupId>org.apache.jena</groupId>
 			<artifactId>jena-jdbc-core</artifactId>
 			<version>0.0.1-SNAPSHOT</version>
 		</dependency>
-		
+
 		<!-- Test Dependencies -->
 		<dependency>
 			<groupId>org.apache.jena</groupId>
@@ -36,4 +36,21 @@
 			<scope>test</scope>
 		</dependency>
 	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>2.4</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>test-jar</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
 </project>
\ No newline at end of file

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
Tue Apr  2 19:26:41 2013
@@ -36,7 +36,7 @@ import com.hp.hpl.jena.query.Dataset;
  */
 public class DatasetConnection extends JenaJdbcConnection {
     
-    private Dataset ds;
+    protected Dataset ds;
     private List<DatasetStatement> statements = new ArrayList<DatasetStatement>();
     private boolean readonly = false;
     

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/AbstractDatasetResultSetTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/AbstractDatasetResultSetTests.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/AbstractDatasetResultSetTests.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/AbstractDatasetResultSetTests.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */
+
+package org.apache.jena.jdbc.mem;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.jena.jdbc.results.AbstractResultSetTests;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.hp.hpl.jena.query.Dataset;
+
+/**
+ * Abstract
+ *
+ */
+public abstract class AbstractDatasetResultSetTests extends AbstractResultSetTests {
+
+    private static DebugDatasetConnection connection;
+
+    /**
+     * Sets up the tests by creating a fake connection for test use
+     * @throws SQLException
+     */
+    @BeforeClass
+    public static void setup() throws SQLException {
+        connection = new DebugDatasetConnection();
+    }
+
+    /**
+     * Cleans up after the tests by closing the fake connection
+     * @throws SQLException
+     */
+    @AfterClass
+    public static void teardown() throws SQLException {
+        connection.close();
+    }
+
+    /**
+     * Method which derived test classes must implement which they can use to turn
+     * the provided dataset (which will be a memory dataset) into the actual
+     * dataset they want to test against
+     * @param ds Dataset
+     * @return Prepared Dataset
+     * @throws SQLException Thrown if the dataset cannot be prepared
+     */
+    protected abstract Dataset prepareDataset(Dataset ds) throws SQLException;
+    
+    @Override
+    protected final ResultSet createAskResult(Dataset ds, String query) throws SQLException
{
+        connection.setJenaDataset(this.prepareDataset(ds));
+        Statement stmt = connection.createStatement();
+        return stmt.executeQuery(query);
+    }
+
+    @Override
+    protected final ResultSet createSelectResults(Dataset ds, String query) throws SQLException
{
+        connection.setJenaDataset(this.prepareDataset(ds));
+        Statement stmt = connection.createStatement();
+        return stmt.executeQuery(query);
+    }
+
+    @Override
+    protected final ResultSet createConstructResults(Dataset ds, String query) throws SQLException
{
+        connection.setJenaDataset(this.prepareDataset(ds));
+        Statement stmt = connection.createStatement();
+        return stmt.executeQuery(query);
+    }
+
+    @Override
+    protected final ResultSet createDescribeResults(Dataset ds, String query) throws SQLException
{
+        connection.setJenaDataset(this.prepareDataset(ds));
+        Statement stmt = connection.createStatement();
+        return stmt.executeQuery(query);
+    }
+
+}
\ No newline at end of file

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/DebugDatasetConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/DebugDatasetConnection.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/DebugDatasetConnection.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/DebugDatasetConnection.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */ 
+
+package org.apache.jena.jdbc.mem;
+
+import java.sql.SQLException;
+
+import org.apache.jena.jdbc.JenaJdbcConnection;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetFactory;
+
+/**
+ * A test only variant of {@link DatasetConnection} which allows the dataset to be changed
on the fly
+ *
+ */
+public class DebugDatasetConnection extends DatasetConnection {
+    
+    /**
+     * Creates a debug dataset connection
+     * @throws SQLException
+     */
+    public DebugDatasetConnection() throws SQLException {
+        this(DatasetFactory.createMem());
+    }
+
+    /**
+     * Creates a debug dataset connection
+     * @param ds Dataset
+     * @throws SQLException
+     */
+    public DebugDatasetConnection(Dataset ds) throws SQLException {
+        super(ds, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+    /**
+     * Sets the Jena dataset in use
+     * @param ds Dataset
+     */
+    public void setJenaDataset(Dataset ds) {
+        this.ds = ds;
+    }
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestResultSets.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestResultSets.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestResultSets.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestResultSets.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */ 
+
+package org.apache.jena.jdbc.mem;
+
+import java.sql.SQLException;
+
+import com.hp.hpl.jena.query.Dataset;
+
+/**
+ * Tests for result sets run against an in-memory dataset {@link DebugDatasetConnection}
+ *
+ */
+public class TestResultSets extends AbstractDatasetResultSetTests {
+
+    @Override
+    protected Dataset prepareDataset(Dataset ds) throws SQLException {
+        // No preparation necessary
+        return ds;
+    }
+}

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/pom.xml
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/pom.xml?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/pom.xml (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/pom.xml Tue Apr  2 19:26:41 2013
@@ -45,5 +45,12 @@
 			<classifier>tests</classifier>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.jena</groupId>
+			<artifactId>jena-jdbc-driver-mem</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+			<classifier>tests</classifier>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 </project>
\ No newline at end of file

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
Tue Apr  2 19:26:41 2013
@@ -19,16 +19,14 @@
 package org.apache.jena.jdbc.tdb;
 
 import java.sql.SQLException;
-import java.util.Iterator;
-
 import org.apache.jena.jdbc.AbstractJenaJdbcConnectionTests;
 import org.apache.jena.jdbc.JenaJdbcConnection;
 import org.apache.jena.jdbc.mem.DatasetConnection;
+import org.apache.jena.jdbc.utils.TestUtils;
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
 
 import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.sparql.core.Quad;
 import com.hp.hpl.jena.tdb.TDBFactory;
 
 /**
@@ -51,11 +49,7 @@ public class TestJenaJdbcTdbDiskConnecti
     @Override
     protected JenaJdbcConnection getConnection(Dataset ds) throws SQLException {
         Dataset tdb = TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath());
-        
-        Iterator<Quad> qs = ds.asDatasetGraph().find();
-        while (qs.hasNext()) {
-            tdb.asDatasetGraph().add(qs.next());
-        }
+        TestUtils.copyDataset(ds, tdb, true);
         return new DatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java?rev=1463707&r1=1463706&r2=1463707&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
Tue Apr  2 19:26:41 2013
@@ -19,14 +19,12 @@
 package org.apache.jena.jdbc.tdb;
 
 import java.sql.SQLException;
-import java.util.Iterator;
-
 import org.apache.jena.jdbc.AbstractJenaJdbcConnectionTests;
 import org.apache.jena.jdbc.JenaJdbcConnection;
 import org.apache.jena.jdbc.mem.DatasetConnection;
+import org.apache.jena.jdbc.utils.TestUtils;
 
 import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.sparql.core.Quad;
 import com.hp.hpl.jena.tdb.TDBFactory;
 
 /**
@@ -43,11 +41,7 @@ public class TestJenaJdbcTdbMemConnectio
     @Override
     protected JenaJdbcConnection getConnection(Dataset ds) throws SQLException {
         Dataset tdb = TDBFactory.createDataset();
-        
-        Iterator<Quad> qs = ds.asDatasetGraph().find();
-        while (qs.hasNext()) {
-            tdb.asDatasetGraph().add(qs.next());
-        }
+        TestUtils.copyDataset(ds, tdb, true);
         return new DatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbDiskResultSets.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbDiskResultSets.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbDiskResultSets.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbDiskResultSets.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */ 
+
+package org.apache.jena.jdbc.tdb;
+
+import java.sql.SQLException;
+
+import org.apache.jena.jdbc.mem.AbstractDatasetResultSetTests;
+import org.apache.jena.jdbc.utils.TestUtils;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.tdb.TDBFactory;
+
+/**
+ * Tests for result sets using a disk backed TDB dataset
+ *
+ */
+public class TestTdbDiskResultSets extends AbstractDatasetResultSetTests {
+
+    /**
+     * Temporary directory rule used to guarantee a unique temporary folder for each test
method
+     */
+    @Rule
+    public TemporaryFolder tempDir = new TemporaryFolder();
+
+    
+    @Override
+    protected Dataset prepareDataset(Dataset ds) throws SQLException {
+        Dataset tdb = TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath());
+        TestUtils.copyDataset(ds, tdb, true);
+        return tdb;
+    }
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbMemResultSets.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbMemResultSets.java?rev=1463707&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbMemResultSets.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestTdbMemResultSets.java
Tue Apr  2 19:26:41 2013
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */ 
+
+package org.apache.jena.jdbc.tdb;
+
+import java.sql.SQLException;
+
+import org.apache.jena.jdbc.mem.AbstractDatasetResultSetTests;
+import org.apache.jena.jdbc.utils.TestUtils;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.tdb.TDBFactory;
+
+/**
+ * Tests for result sets using a in-memory TDB dataset
+ *
+ */
+public class TestTdbMemResultSets extends AbstractDatasetResultSetTests {
+
+    @Override
+    protected Dataset prepareDataset(Dataset ds) throws SQLException {
+        Dataset tdb = TDBFactory.createDataset();
+        TestUtils.copyDataset(ds, tdb, true);
+        return tdb;
+    }
+}



Mime
View raw message