You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/06/06 02:01:53 UTC

svn commit: r1490089 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/ jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/ jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/ jena-jdbc...

Author: rvesse
Date: Thu Jun  6 00:01:52 2013
New Revision: 1490089

URL: http://svn.apache.org/r1490089
Log:
Expand test coverage for JDBC statements

Added:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/statements/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/statements/TestMemStatements.java
Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TS_JdbcDriverMem.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java?rev=1490089&r1=1490088&r2=1490089&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaStatement.java Thu Jun  6 00:01:52 2013
@@ -162,7 +162,7 @@ public abstract class JenaStatement impl
 
     @Override
     public void cancel() throws SQLException {
-
+        throw new SQLFeatureNotSupportedException();
     }
 
     @Override

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java?rev=1490089&r1=1490088&r2=1490089&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java Thu Jun  6 00:01:52 2013
@@ -41,6 +41,9 @@ import org.apache.jena.iri.IRIFactory;
 import org.apache.jena.jdbc.JdbcCompatibility;
 import org.apache.jena.jdbc.connections.JenaConnection;
 import org.apache.jena.jdbc.preprocessing.Echo;
+import org.apache.jena.jdbc.results.AskResults;
+import org.apache.jena.jdbc.results.SelectResults;
+import org.apache.jena.jdbc.results.TripleIteratorResults;
 import org.apache.jena.jdbc.results.metadata.AskResultsMetadata;
 import org.apache.jena.jdbc.results.metadata.TripleResultsMetadata;
 import org.apache.jena.jdbc.statements.JenaPreparedStatement;
@@ -1756,6 +1759,191 @@ public abstract class AbstractJenaConnec
     }
 
     /**
+     * Runs a batch of operations and checks the results results
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void connection_statement_batch_04() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        Statement stmt = conn.createStatement();
+
+        // Create and execute a batch
+        stmt.addBatch("SELECT * WHERE { ?s ?p ?o }");
+        stmt.addBatch("ASK WHERE { }");
+        int[] batchResults = stmt.executeBatch();
+        Assert.assertEquals(2, batchResults.length);
+        Assert.assertEquals(batchResults[0], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[1], Statement.SUCCESS_NO_INFO);
+
+        // Closing the statement should clean up any open result sets even if we
+        // haven't retrieved them yet
+        stmt.close();
+        Assert.assertTrue(stmt.isClosed());
+
+        // Clean up
+        conn.close();
+        Assert.assertTrue(conn.isClosed());
+    }
+
+    /**
+     * Runs a batch of operations and checks the results results
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void connection_statement_batch_05() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        Statement stmt = conn.createStatement();
+
+        // Create and execute a batch
+        stmt.addBatch("SELECT * WHERE { ?s ?p ?o }");
+        stmt.addBatch("ASK WHERE { }");
+        stmt.addBatch("CONSTRUCT WHERE { ?s ?p ?o }");
+        int[] batchResults = stmt.executeBatch();
+        Assert.assertEquals(3, batchResults.length);
+        Assert.assertEquals(batchResults[0], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[1], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[2], Statement.SUCCESS_NO_INFO);
+
+        // Get first result set
+        ResultSet rset = stmt.getResultSet();
+        Assert.assertTrue(rset instanceof SelectResults);
+        checkSelectMetadata(rset, 3);
+
+        // Grab the next result set leaving this one open
+        Assert.assertTrue(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
+        Assert.assertFalse(rset.isClosed());
+        ResultSet rset2 = stmt.getResultSet();
+        Assert.assertTrue(rset2 instanceof AskResults);
+        checkAskMetadata(rset2);
+
+        // Closing the statement should clean up any open result sets even if we
+        // haven't retrieved them yet or have previously moved past them but
+        // left them open
+        stmt.close();
+        Assert.assertTrue(stmt.isClosed());
+        Assert.assertTrue(rset.isClosed());
+        Assert.assertTrue(rset2.isClosed());
+
+        // Clean up
+        conn.close();
+        Assert.assertTrue(conn.isClosed());
+    }
+    
+    /**
+     * Runs a batch of operations and checks the results results
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void connection_statement_batch_06() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        Statement stmt = conn.createStatement();
+
+        // Create and execute a batch
+        stmt.addBatch("SELECT * WHERE { ?s ?p ?o }");
+        stmt.addBatch("ASK WHERE { }");
+        stmt.addBatch("CONSTRUCT WHERE { ?s ?p ?o }");
+        int[] batchResults = stmt.executeBatch();
+        Assert.assertEquals(3, batchResults.length);
+        Assert.assertEquals(batchResults[0], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[1], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[2], Statement.SUCCESS_NO_INFO);
+
+        // Get first result set
+        ResultSet rset = stmt.getResultSet();
+        Assert.assertTrue(rset instanceof SelectResults);
+        checkSelectMetadata(rset, 3);
+
+        // Close this and grab the next result set
+        Assert.assertTrue(stmt.getMoreResults(Statement.CLOSE_CURRENT_RESULT));
+        Assert.assertTrue(rset.isClosed());
+        ResultSet rset2 = stmt.getResultSet();
+        Assert.assertTrue(rset2 instanceof AskResults);
+        checkAskMetadata(rset2);
+
+        // Closing the statement should clean up any open result sets even if we
+        // haven't retrieved them yet or have previously moved past them but
+        // left them open
+        stmt.close();
+        Assert.assertTrue(stmt.isClosed());
+        Assert.assertTrue(rset2.isClosed());
+
+        // Clean up
+        conn.close();
+        Assert.assertTrue(conn.isClosed());
+    }
+    
+    /**
+     * Runs a batch of operations and checks the results results
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void connection_statement_batch_07() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        Statement stmt = conn.createStatement();
+
+        // Create and execute a batch
+        stmt.addBatch("SELECT * WHERE { ?s ?p ?o }");
+        stmt.addBatch("ASK WHERE { }");
+        stmt.addBatch("CONSTRUCT WHERE { ?s ?p ?o }");
+        stmt.addBatch("DESCRIBE <http://example>");
+        int[] batchResults = stmt.executeBatch();
+        Assert.assertEquals(4, batchResults.length);
+        Assert.assertEquals(batchResults[0], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[1], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[2], Statement.SUCCESS_NO_INFO);
+        Assert.assertEquals(batchResults[3], Statement.SUCCESS_NO_INFO);
+
+        // Get first result set
+        ResultSet rset = stmt.getResultSet();
+        Assert.assertTrue(rset instanceof SelectResults);
+        checkSelectMetadata(rset, 3);
+
+        // Leave open and grab the next result set
+        Assert.assertTrue(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
+        Assert.assertFalse(rset.isClosed());
+        ResultSet rset2 = stmt.getResultSet();
+        Assert.assertTrue(rset2 instanceof AskResults);
+        checkAskMetadata(rset2);
+        
+        // Leave open and grab the next result set
+        Assert.assertTrue(stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT));
+        Assert.assertFalse(rset.isClosed());
+        Assert.assertFalse(rset2.isClosed());
+        ResultSet rset3 = stmt.getResultSet();
+        Assert.assertTrue(rset3 instanceof TripleIteratorResults);
+        checkConstructDescribeMetadata(rset3);
+        
+        // Grab next result set closing all previous
+        Assert.assertTrue(stmt.getMoreResults(Statement.CLOSE_ALL_RESULTS));
+        Assert.assertTrue(rset.isClosed());
+        Assert.assertTrue(rset2.isClosed());
+        Assert.assertTrue(rset3.isClosed());
+        ResultSet rset4 = stmt.getResultSet();
+        Assert.assertFalse(rset4.isClosed());
+        checkConstructDescribeMetadata(rset4);
+
+        // Closing the statement should clean up any open result sets even if we
+        // haven't retrieved them yet or have previously moved past them but
+        // left them open
+        stmt.close();
+        Assert.assertTrue(stmt.isClosed());
+        Assert.assertTrue(rset.isClosed());
+        Assert.assertTrue(rset2.isClosed());
+
+        // Clean up
+        conn.close();
+        Assert.assertTrue(conn.isClosed());
+    }
+
+    /**
      * Tests pre-processor management operations
      * 
      * @throws SQLException

Added: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java?rev=1490089&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java Thu Jun  6 00:01:52 2013
@@ -0,0 +1,243 @@
+/**
+ * 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.statements;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import org.apache.jena.jdbc.connections.JenaConnection;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for statement, note many tests are included at a higher level in the
+ * {@link AbstractJenaStatementTests} and this includes tests only for statement
+ * specific stuff that has to be tested within this package
+ * 
+ */
+public abstract class AbstractJenaStatementTests {
+
+    /**
+     * Method that derived classes must implement to provide a connection to an
+     * empty dataset for testing
+     * 
+     * @return
+     * @throws SQLException
+     */
+    protected abstract JenaConnection getConnection() throws SQLException;
+
+    /**
+     * Test error case when trying to create statement with null connection
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void statement_bad_creation_01() throws SQLException {
+        new DatasetStatement(null);
+    }
+
+    /**
+     * Tests error cases for unsupported wrapper features
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void statement_bad_wrapper_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+
+        try {
+            stmt.isWrapperFor(JenaStatement.class);
+        } finally {
+            stmt.close();
+            conn.close();
+        }
+    }
+
+    /**
+     * Tests error cases for unsupported wrapper features
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void statement_bad_wrapper_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+
+        try {
+            stmt.unwrap(JenaStatement.class);
+        } finally {
+            stmt.close();
+            conn.close();
+        }
+    }
+
+    /**
+     * Tests error case for unsupported cancel feature
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void statement_bad_cancel_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+
+        try {
+            stmt.cancel();
+        } finally {
+            stmt.close();
+            conn.close();
+        }
+    }
+
+    /**
+     * Check warnings usage
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void statement_warnings_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+
+        Assert.assertNull(stmt.getWarnings());
+
+        stmt.close();
+        conn.close();
+    }
+
+    /**
+     * Check warnings usage
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void statement_warnings_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        JenaStatement stmt = (JenaStatement) conn.createStatement();
+
+        Assert.assertNull(stmt.getWarnings());
+        stmt.setWarning("Test");
+        Assert.assertNotNull(stmt.getWarnings());
+        stmt.clearWarnings();
+        Assert.assertNull(stmt.getWarnings());
+
+        stmt.close();
+        conn.close();
+    }
+
+    /**
+     * Check warnings usage
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void statement_warnings_03() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        JenaStatement stmt = (JenaStatement) conn.createStatement();
+
+        Assert.assertNull(stmt.getWarnings());
+        stmt.setWarning("Test", new Exception());
+        Assert.assertNotNull(stmt.getWarnings());
+        stmt.clearWarnings();
+        Assert.assertNull(stmt.getWarnings());
+
+        stmt.close();
+        conn.close();
+    }
+
+    /**
+     * Check warnings usage
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void statement_warnings_04() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        JenaStatement stmt = (JenaStatement) conn.createStatement();
+
+        Assert.assertNull(stmt.getWarnings());
+        stmt.setWarning(new SQLWarning());
+        Assert.assertNotNull(stmt.getWarnings());
+        stmt.clearWarnings();
+        Assert.assertNull(stmt.getWarnings());
+
+        stmt.close();
+        conn.close();
+    }
+
+    /**
+     * Check warnings usage
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void statement_warnings_05() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        JenaStatement stmt = (JenaStatement) conn.createStatement();
+
+        Assert.assertNull(stmt.getWarnings());
+        stmt.setWarning("A");
+        Assert.assertNotNull(stmt.getWarnings());
+        stmt.setWarning("B");
+        Assert.assertNotNull(stmt.getWarnings());
+        Assert.assertNotNull(stmt.getWarnings().getNextWarning());
+        stmt.clearWarnings();
+        Assert.assertNull(stmt.getWarnings());
+
+        stmt.close();
+        conn.close();
+    }
+
+    /**
+     * Tests for fetch direction settings
+     * 
+     * @throws SQLException
+     */
+    @Test
+    public void statement_fetch_direction_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+
+        Assert.assertEquals(ResultSet.FETCH_FORWARD, stmt.getFetchDirection());
+        conn.close();
+    }
+
+    /**
+     * Tests for fetch direction settings
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void statement_fetch_direction_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+
+        try {
+            // Only FETCH_FORWARD is supported
+            stmt.setFetchDirection(ResultSet.FETCH_REVERSE);
+        } finally {
+            stmt.close();
+            conn.close();
+        }
+    }
+}

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TS_JdbcDriverMem.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TS_JdbcDriverMem.java?rev=1490089&r1=1490088&r2=1490089&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TS_JdbcDriverMem.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TS_JdbcDriverMem.java Thu Jun  6 00:01:52 2013
@@ -21,6 +21,7 @@ package org.apache.jena.jdbc.mem;
 import org.apache.jena.jdbc.mem.connections.TestDatasetConnection;
 import org.apache.jena.jdbc.mem.metadata.TestDatasetConnectionMetadata;
 import org.apache.jena.jdbc.mem.results.TestResultSets;
+import org.apache.jena.jdbc.mem.statements.TestMemStatements;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
@@ -34,6 +35,7 @@ import org.junit.runners.Suite;
     TestMemDriverWithLogging.class,
     TestDatasetConnection.class,
     TestDatasetConnectionMetadata.class,
+    TestMemStatements.class,
     TestResultSets.class
 })
 public class TS_JdbcDriverMem {

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/statements/TestMemStatements.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/statements/TestMemStatements.java?rev=1490089&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/statements/TestMemStatements.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/statements/TestMemStatements.java Thu Jun  6 00:01:52 2013
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2013 YarcData LLC All Rights Reserved.
+ */ 
+
+package org.apache.jena.jdbc.mem.statements;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.jena.jdbc.JdbcCompatibility;
+import org.apache.jena.jdbc.connections.JenaConnection;
+import org.apache.jena.jdbc.mem.connections.MemConnection;
+import org.apache.jena.jdbc.statements.AbstractJenaStatementTests;
+
+import com.hp.hpl.jena.query.DatasetFactory;
+
+/**
+ * Tests for statements produced by {@link MemConnection} instances
+ * @author rvesse
+ *
+ */
+public class TestMemStatements extends AbstractJenaStatementTests {
+
+    @Override
+    protected JenaConnection getConnection() throws SQLException {
+        return new MemConnection(DatasetFactory.createMem(), JenaConnection.DEFAULT_HOLDABILITY, false, Connection.TRANSACTION_NONE, JdbcCompatibility.DEFAULT);
+    }
+
+}