jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1490055 - /jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java
Date Wed, 05 Jun 2013 22:46:14 GMT
Author: rvesse
Date: Wed Jun  5 22:46:14 2013
New Revision: 1490055

URL: http://svn.apache.org/r1490055
Log:
Expand test coverage for Jena connections

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java

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=1490055&r1=1490054&r2=1490055&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
Wed Jun  5 22:46:14 2013
@@ -30,10 +30,12 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLWarning;
 import java.sql.Statement;
 import java.sql.Time;
 import java.sql.Types;
 import java.util.HashMap;
+import java.util.Properties;
 
 import org.apache.jena.iri.IRIFactory;
 import org.apache.jena.jdbc.JdbcCompatibility;
@@ -1350,7 +1352,36 @@ public abstract class AbstractJenaConnec
     }
 
     /**
+     * Tests error cases for transactions
+     * @throws SQLException 
+     */
+    @Test(expected = SQLException.class)
+    public void connection_transaction_bad_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Trying to commit a transaction on a closed connection should be an
+        // error
+        conn.commit();
+    }
+    
+    /**
+     * Tests error cases for transactions
+     * @throws SQLException 
+     */
+    @Test(expected = SQLException.class)
+    public void connection_transaction_bad_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Trying to commit a transaction on a closed connection should be an
+        // error
+        conn.rollback();
+    }
+
+    /**
      * Test error cases for creating statements
+     * 
      * @throws SQLException
      */
     @Test(expected = SQLException.class)
@@ -1361,9 +1392,10 @@ public abstract class AbstractJenaConnec
         // Creating a statement after closing should be an error
         conn.createStatement();
     }
-    
+
     /**
      * Test error cases for creating statements
+     * 
      * @throws SQLException
      */
     @Test(expected = SQLException.class)
@@ -1372,17 +1404,32 @@ public abstract class AbstractJenaConnec
         conn.close();
 
         // Creating a statement after closing should be an error
-        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }");
+        conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     }
-    
+
     /**
      * Test error cases for creating statements
+     * 
      * @throws SQLException
      */
     @Test(expected = SQLException.class)
     public void connection_statement_bad_creation_03() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
+    }
+
+    /**
+     * Test error cases for creating statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_statement_bad_creation_04() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
         try {
             // Creating a SCOLL_SENSITIVE statement is not supported
             conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
@@ -1390,15 +1437,16 @@ public abstract class AbstractJenaConnec
             conn.close();
         }
     }
-    
+
     /**
      * Test error cases for creating statements
+     * 
      * @throws SQLException
      */
     @Test(expected = SQLException.class)
-    public void connection_statement_bad_creation_04() throws SQLException {
+    public void connection_statement_bad_creation_05() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             // Creating a CONCUR_UPDATABLE statement is not supported
             conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
@@ -1408,6 +1456,91 @@ public abstract class AbstractJenaConnec
     }
 
     /**
+     * Test error cases for creating prepared statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_prepared_statement_bad_creation_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }");
+    }
+
+    /**
+     * Test error cases for creating prepared statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_prepared_statement_bad_creation_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }", 1);
+    }
+
+    /**
+     * Test error cases for creating prepared statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_prepared_statement_bad_creation_03() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }", new int[0]);
+    }
+
+    /**
+     * Test error cases for creating prepared statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_prepared_statement_bad_creation_04() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }", new String[0]);
+    }
+
+    /**
+     * Test error cases for creating prepared statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_prepared_statement_bad_creation_05() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
+    }
+
+    /**
+     * Test error cases for creating prepared statements
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLException.class)
+    public void connection_prepared_statement_bad_creation_06() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        conn.close();
+
+        // Creating a statement after closing should be an error
+        conn.prepareStatement("SELECT * WHERE { ?s ?p ?o }", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
+                ResultSet.CLOSE_CURSORS_AT_COMMIT);
+    }
+
+    /**
      * Runs a batch of operations and checks the results results
      * 
      * @throws SQLException
@@ -1769,15 +1902,16 @@ public abstract class AbstractJenaConnec
 
         conn.close();
     }
-    
+
     /**
      * Tests error cases trying to set invalid options
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLFeatureNotSupportedException.class)
+    @Test(expected = SQLFeatureNotSupportedException.class)
     public void connection_bad_option_01() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             // Can't change catalog
             conn.setCatalog("test");
@@ -1785,15 +1919,16 @@ public abstract class AbstractJenaConnec
             conn.close();
         }
     }
-    
+
     /**
      * Tests error cases trying to set invalid options
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLException.class)
+    @Test(expected = SQLException.class)
     public void connection_bad_option_02() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             // Invalid holdability setting
             conn.setHoldability(-1);
@@ -1801,15 +1936,16 @@ public abstract class AbstractJenaConnec
             conn.close();
         }
     }
-    
+
     /**
      * Tests error cases trying to set invalid options
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLException.class)
+    @Test(expected = SQLException.class)
     public void connection_bad_option_03() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             // Invalid transaction isolation setting
             conn.setTransactionIsolation(-1);
@@ -1817,77 +1953,340 @@ public abstract class AbstractJenaConnec
             conn.close();
         }
     }
-    
+
     /**
      * Tests error cases around savepoints which are unsupported
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLFeatureNotSupportedException.class)
+    @Test(expected = SQLFeatureNotSupportedException.class)
     public void connection_bad_savepoints_01() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             conn.setSavepoint();
         } finally {
             conn.close();
         }
     }
-    
+
     /**
      * Tests error cases around savepoints which are unsupported
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLFeatureNotSupportedException.class)
+    @Test(expected = SQLFeatureNotSupportedException.class)
     public void connection_bad_savepoints_02() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             conn.setSavepoint("test");
         } finally {
             conn.close();
         }
     }
-    
+
     /**
      * Tests error cases around savepoints which are unsupported
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLFeatureNotSupportedException.class)
+    @Test(expected = SQLFeatureNotSupportedException.class)
     public void connection_bad_savepoints_03() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             conn.rollback(null);
         } finally {
             conn.close();
         }
     }
-    
+
     /**
      * Tests error cases around savepoints which are unsupported
+     * 
      * @throws SQLException
      */
-    @Test(expected=SQLFeatureNotSupportedException.class)
+    @Test(expected = SQLFeatureNotSupportedException.class)
     public void connection_bad_savepoints_04() throws SQLException {
         JenaConnection conn = this.getConnection();
-        
+
         try {
             conn.releaseSavepoint(null);
         } finally {
             conn.close();
         }
     }
+
+    /**
+     * Tests error cases around type maps which are unsupported
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void connection_bad_type_map_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
+        try {
+            conn.setTypeMap(new HashMap<String, Class<?>>());
+        } finally {
+            conn.close();
+        }
+    }
     
     /**
      * Tests error cases around type maps which are unsupported
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void connection_bad_type_map_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
+        try {
+            conn.getTypeMap();
+        } finally {
+            conn.close();
+        }
+    }
+
+    /**
+     * Tests error cases for unsupported call functionality
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void connection_bad_call_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
+        try {
+            conn.prepareCall("test");
+        } finally {
+            conn.close();
+        }
+    }
+
+    /**
+     * Tests error cases for unsupported call functionality
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void connection_bad_call_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
+        try {
+            conn.prepareCall("test", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+        } finally {
+            conn.close();
+        }
+    }
+
+    /**
+     * Tests error cases for unsupported call functionality
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void connection_bad_call_03() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
+        try {
+            conn.prepareCall("test", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        } finally {
+            conn.close();
+        }
+    }
+
+    /**
+     * Tests error cases for unsupported native sql functionality
+     * 
+     * @throws SQLException
+     */
+    @Test(expected = SQLFeatureNotSupportedException.class)
+    public void connection_bad_native_sql_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+
+        try {
+            conn.nativeSQL("test");
+        } finally {
+            conn.close();
+        }
+    }
+    
+    /**
+     * Tests usage of client info
+     * @throws SQLException
+     */
+    @Test
+    public void connection_client_info_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        // Check initially empty
+        Properties ps = conn.getClientInfo();
+        Assert.assertNotNull(ps);
+        Assert.assertEquals(0, ps.size());
+        
+        // Add a value and check it
+        conn.setClientInfo("key", "value");
+        ps = conn.getClientInfo();
+        Assert.assertNotNull(ps);
+        Assert.assertEquals(1, ps.size());
+        Assert.assertEquals("value", conn.getClientInfo("key"));
+        
+        // Replace values with a new set and check
+        Properties props = new Properties();
+        props.put("a", 1);
+        props.put("b", 2);
+        conn.setClientInfo(props);
+        ps = conn.getClientInfo();
+        Assert.assertNotNull(ps);
+        Assert.assertEquals(2, ps.size());
+        
+        conn.close();
+    }
+    
+    /**
+     * Tests usage of client info
+     * @throws SQLException
+     */
+    @Test
+    public void connection_client_info_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        // Add and retrieve a key
+        conn.setClientInfo("key", "value");
+        String value = conn.getClientInfo("key");
+        Assert.assertEquals("value", value);
+        
+        // Non-existent key should give null
+        Assert.assertNull(conn.getClientInfo("test"));
+     
+        conn.close();
+    }
+    
+    /**
+     * Check catalog retrieval
+     * @throws SQLException
+     */
+    @Test
+    public void connection_catalog_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        Assert.assertNotNull(conn.getCatalog());
+        
+        conn.close();
+    }
+    
+    /**
+     * Check warnings usage
+     * @throws SQLException
+     */
+    @Test
+    public void connection_warnings_01() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        Assert.assertNull(conn.getWarnings());
+        
+        conn.close();
+    }
+    
+    /**
+     * Check warnings usage
+     * @throws SQLException
+     */
+    @Test
+    public void connection_warnings_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        Assert.assertNull(conn.getWarnings());
+        conn.setWarning("Test");
+        Assert.assertNotNull(conn.getWarnings());
+        conn.clearWarnings();
+        Assert.assertNull(conn.getWarnings());
+        
+        conn.close();
+    }
+    
+    /**
+     * Check warnings usage
+     * @throws SQLException
+     */
+    @Test
+    public void connection_warnings_03() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        Assert.assertNull(conn.getWarnings());
+        conn.setWarning("Test", new Exception());
+        Assert.assertNotNull(conn.getWarnings());
+        conn.clearWarnings();
+        Assert.assertNull(conn.getWarnings());
+        
+        conn.close();
+    }
+    
+    /**
+     * Check warnings usage
+     * @throws SQLException
+     */
+    @Test
+    public void connection_warnings_04() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        Assert.assertNull(conn.getWarnings());
+        conn.setWarning(new SQLWarning());
+        Assert.assertNotNull(conn.getWarnings());
+        conn.clearWarnings();
+        Assert.assertNull(conn.getWarnings());
+        
+        conn.close();
+    }
+    
+    /**
+     * Check warnings usage
+     * @throws SQLException
+     */
+    @Test
+    public void connection_warnings_05() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        Assert.assertNull(conn.getWarnings());
+        conn.setWarning("A");
+        Assert.assertNotNull(conn.getWarnings());
+        conn.setWarning("B");
+        Assert.assertNotNull(conn.getWarnings());
+        Assert.assertNotNull(conn.getWarnings().getCause());
+        conn.clearWarnings();
+        Assert.assertNull(conn.getWarnings());
+        
+        conn.close();
+    }
+    
+    /**
+     * Tests error cases for unsupported wrapper features
      * @throws SQLException
      */
     @Test(expected=SQLFeatureNotSupportedException.class)
-    public void connection_bad_type_map_01() throws SQLException {
+    public void connection_bad_wrapper_01() throws SQLException {
         JenaConnection conn = this.getConnection();
         
         try {
-            conn.setTypeMap(new HashMap<String, Class<?>>());
+            conn.isWrapperFor(JenaConnection.class);
+        } finally {
+            conn.close();
+        }
+    }
+    
+    /**
+     * Tests error cases for unsupported wrapper features
+     * @throws SQLException
+     */
+    @Test(expected=SQLFeatureNotSupportedException.class)
+    public void connection_bad_wrapper_02() throws SQLException {
+        JenaConnection conn = this.getConnection();
+        
+        try {
+            conn.unwrap(JenaConnection.class);
         } finally {
             conn.close();
         }



Mime
View raw message