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/07 00:41:03 UTC
svn commit: r1490465 - in
/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc:
connections/AbstractJenaConnectionTests.java
statements/AbstractJenaStatementTests.java
Author: rvesse
Date: Thu Jun 6 22:40:57 2013
New Revision: 1490465
URL: http://svn.apache.org/r1490465
Log:
More prepared statement tests
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/connections/AbstractJenaConnectionTests.java
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.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=1490465&r1=1490464&r2=1490465&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 22:40:57 2013
@@ -968,6 +968,120 @@ public abstract class AbstractJenaConnec
// Setting null is illegal
stmt.setObject(1, null);
}
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_28() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setBigDecimal(1, BigDecimal.valueOf(1234, 1));
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("123.4"));
+ }
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_29() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setBoolean(1, true);
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("true"));
+ }
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_30() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setByte(1, (byte) 123);
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("123"));
+ Assert.assertTrue(pss.toString().contains(XSDDatatype.XSDbyte.getURI()));
+ }
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_31() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setFloat(1, 12.3f);
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("12.3"));
+ Assert.assertTrue(pss.toString().contains(XSDDatatype.XSDfloat.getURI()));
+ }
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_32() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setDouble(1, 12.3d);
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("12.3"));
+ }
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_33() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setInt(1, 123);
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("123"));
+ }
+
+ /**
+ * Tests that the various set methods of {@link JenaPreparedStatement}
+ * function correctly
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void connection_prepared_statement_setters_34() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ JenaPreparedStatement stmt = (JenaPreparedStatement) conn.prepareStatement("SELECT * WHERE { ?s ?p ? }");
+
+ stmt.setLong(1, 123l);
+ ParameterizedSparqlString pss = stmt.getParameterizedString();
+ Assert.assertTrue(pss.toString().contains("123"));
+ }
/**
* Runs a SELECT query on a non-empty database with max rows set and checks
Modified: 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=1490465&r1=1490464&r2=1490465&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/statements/AbstractJenaStatementTests.java Thu Jun 6 22:40:57 2013
@@ -29,6 +29,7 @@ import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.Statement;
+import java.sql.Types;
import org.apache.jena.jdbc.connections.JenaConnection;
import org.junit.Assert;
@@ -1043,7 +1044,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1061,7 +1062,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1079,7 +1080,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1097,7 +1098,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1115,7 +1116,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1127,13 +1128,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setBlob(1, (Blob)null);
+ stmt.setBlob(1, (Blob) null);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1145,13 +1146,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setBlob(1, (InputStream)null);
+ stmt.setBlob(1, (InputStream) null);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1163,13 +1164,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setBlob(1, (InputStream)null, 0l);
+ stmt.setBlob(1, (InputStream) null, 0l);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1187,7 +1188,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1205,7 +1206,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1223,7 +1224,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1241,7 +1242,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1253,13 +1254,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setClob(1, (Clob)null);
+ stmt.setClob(1, (Clob) null);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1271,13 +1272,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setClob(1, (Reader)null);
+ stmt.setClob(1, (Reader) null);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1289,13 +1290,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setClob(1, (Reader)null, 0l);
+ stmt.setClob(1, (Reader) null, 0l);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1313,7 +1314,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1331,7 +1332,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1349,7 +1350,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1367,7 +1368,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1379,13 +1380,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setNClob(1, (NClob)null);
+ stmt.setNClob(1, (NClob) null);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1397,13 +1398,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setNClob(1, (Reader)null);
+ stmt.setNClob(1, (Reader) null);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1415,13 +1416,13 @@ public abstract class AbstractJenaStatem
PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
try {
- stmt.setNClob(1, (Reader)null, 0l);
+ stmt.setNClob(1, (Reader) null, 0l);
} finally {
stmt.close();
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1439,7 +1440,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1457,7 +1458,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1476,7 +1477,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1494,7 +1495,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1512,7 +1513,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1530,7 +1531,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1548,7 +1549,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1566,7 +1567,7 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
@@ -1584,12 +1585,13 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
/**
* Tests for unsupported setters on prepared statements
*
* @throws SQLException
*/
+ @SuppressWarnings("deprecation")
@Test(expected = SQLFeatureNotSupportedException.class)
public void prepared_statement_unsupported_setters_34() throws SQLException {
JenaConnection conn = this.getConnection();
@@ -1602,5 +1604,61 @@ public abstract class AbstractJenaStatem
conn.close();
}
}
-
+
+ /**
+ * Tests error cases for setters on prepared statements
+ *
+ * @throws SQLException
+ */
+ @Test(expected = SQLException.class)
+ public void prepared_statement_bad_setters_01() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
+
+ try {
+ // Should error since parameters use a one based index
+ stmt.setBoolean(0, true);
+ } finally {
+ stmt.close();
+ conn.close();
+ }
+ }
+
+ /**
+ * Tests error cases for setters on prepared statements
+ *
+ * @throws SQLException
+ */
+ @Test(expected = SQLException.class)
+ public void prepared_statement_bad_setters_02() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
+
+ try {
+ // Should error since parameters use a one based index
+ stmt.setBoolean(2, true);
+ } finally {
+ stmt.close();
+ conn.close();
+ }
+ }
+
+ /**
+ * Tests error cases for setters on prepared statements
+ *
+ * @throws SQLException
+ */
+ @Test(expected = SQLException.class)
+ public void prepared_statement_bad_setters_03() throws SQLException {
+ JenaConnection conn = this.getConnection();
+ PreparedStatement stmt = conn.prepareStatement("SELECT * WHERE { ? ?p ?o }");
+
+ try {
+ // No RDF equivalent of the given SQL Type
+ stmt.setObject(1, null, Types.BLOB);
+ } finally {
+ stmt.close();
+ conn.close();
+ }
+ }
}