You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/02/21 15:12:08 UTC
svn commit: r510012 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests:
jdbc4/ClosedObjectTest.java jdbc4/_Suite.java jdbcapi/ClosedObjectTest.java
jdbcapi/_Suite.java jdbcapi/build.xml
Author: kahatlen
Date: Wed Feb 21 06:12:06 2007
New Revision: 510012
URL: http://svn.apache.org/viewvc?view=rev&rev=510012
Log:
DERBY-2324: convert StmtCloseFunTest to JUnit
Made ClosedObjectTest run under more JVMs.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java
- copied, changed from r509145, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClosedObjectTest.java
Removed:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClosedObjectTest.java
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java?view=diff&rev=510012&r1=510011&r2=510012
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java Wed Feb 21 06:12:06 2007
@@ -52,7 +52,6 @@
suite.addTest(BlobTest.suite());
suite.addTest(CallableStatementTest.suite());
suite.addTest(ClobTest.suite());
- suite.addTest(ClosedObjectTest.suite());
suite.addTest(ConnectionTest.suite());
suite.addTest(DataSourceTest.suite());
suite.addTest(JDBC40TranslationTest.suite());
Copied: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java (from r509145, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClosedObjectTest.java)
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java?view=diff&rev=510012&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClosedObjectTest.java&r1=509145&p2=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java&r2=510012
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClosedObjectTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClosedObjectTest.java Wed Feb 21 06:12:06 2007
@@ -1,5 +1,5 @@
/*
- * Derby - org.apache.derbyTesting.functionTests.tests.jdbc4.ClosedObjectTest
+ * Derby - org.apache.derbyTesting.functionTests.tests.jdbcapi.ClosedObjectTest
*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -18,19 +18,16 @@
*
*/
-package org.apache.derbyTesting.functionTests.tests.jdbc4;
+package org.apache.derbyTesting.functionTests.tests.jdbcapi;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.CallableStatement;
-import java.sql.SQLClientInfoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
-import java.util.Arrays;
import java.util.Properties;
import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;
@@ -42,6 +39,7 @@
import junit.framework.TestSuite;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.J2EEDataSource;
+import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.JDBCDataSource;
import org.apache.derbyTesting.junit.TestConfiguration;
@@ -103,9 +101,6 @@
} catch (InvocationTargetException ite) {
try {
throw ite.getCause();
- } catch (SQLFeatureNotSupportedException fnse) {
- // if we don't support the method, it is OK that we
- // throw this exception
} catch (SQLException sqle) {
decorator_.checkException(method_, sqle);
}
@@ -137,6 +132,11 @@
topSuite.addTest(dsDecorator);
fillDataSourceSuite(dsSuite, dsDecorator);
+ if (JDBC.vmSupportsJSR169()) {
+ // JSR169 doesn't support ConnectionPoolDataSource and XADataSource
+ return dsSuite;
+ }
+
TestSuite poolSuite = new TestSuite(
"ClosedObjectTest ConnectionPoolDataSource");
PoolDataSourceDecorator poolDecorator =
@@ -165,31 +165,31 @@
private static void fillDataSourceSuite(TestSuite suite,
DataSourceDecorator dsDecorator)
{
- TestSuite rsSuite = new TestSuite();
+ TestSuite rsSuite = new TestSuite("Closed ResultSet");
ResultSetObjectDecorator rsDecorator =
new ResultSetObjectDecorator(rsSuite, dsDecorator);
suite.addTest(rsDecorator);
fillObjectSuite(rsSuite, rsDecorator, ResultSet.class);
- TestSuite stmtSuite = new TestSuite();
+ TestSuite stmtSuite = new TestSuite("Closed Statement");
StatementObjectDecorator stmtDecorator =
new StatementObjectDecorator(stmtSuite, dsDecorator);
suite.addTest(stmtDecorator);
fillObjectSuite(stmtSuite, stmtDecorator, Statement.class);
- TestSuite psSuite = new TestSuite();
+ TestSuite psSuite = new TestSuite("Closed PreparedStatement");
PreparedStatementObjectDecorator psDecorator =
new PreparedStatementObjectDecorator(psSuite, dsDecorator);
suite.addTest(psDecorator);
fillObjectSuite(psSuite, psDecorator, PreparedStatement.class);
- TestSuite csSuite = new TestSuite();
+ TestSuite csSuite = new TestSuite("Closed CallableStatement");
CallableStatementObjectDecorator csDecorator =
new CallableStatementObjectDecorator(csSuite, dsDecorator);
suite.addTest(csDecorator);
fillObjectSuite(csSuite, csDecorator, CallableStatement.class);
- TestSuite connSuite = new TestSuite();
+ TestSuite connSuite = new TestSuite("Closed Connection");
ConnectionObjectDecorator connDecorator =
new ConnectionObjectDecorator(connSuite, dsDecorator);
suite.addTest(connDecorator);
@@ -208,8 +208,9 @@
ObjectDecorator decorator,
Class iface)
{
- for (Method m : iface.getMethods()) {
- ClosedObjectTest cot = new ClosedObjectTest(m, decorator);
+ Method[] methods = iface.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ ClosedObjectTest cot = new ClosedObjectTest(methods[i], decorator);
suite.addTest(cot);
}
}
@@ -316,13 +317,10 @@
* @return <code>true</code> if an exception is expected
*/
public boolean expectsException(Method method) {
- final String[] exceptionLessMethods = {
- "close",
- "isClosed",
- "isValid",
- };
- for (String name : exceptionLessMethods) {
- if (name.equals(method.getName())) return false;
+ String name = method.getName();
+ if (name.equals("close") || name.equals("isClosed")
+ || name.equals("isValid")) {
+ return false;
}
return true;
}
@@ -341,6 +339,13 @@
if (!expectsException(method)) {
throw sqle;
}
+
+ if (sqle.getSQLState().startsWith("0A")) {
+ // method is not supported, so we don't expect closed object
+ // exception
+ return;
+ }
+
checkSQLState(method, sqle);
}
@@ -637,12 +642,14 @@
protected void checkSQLState(Method method, SQLException sqle)
throws SQLException
{
- if (sqle instanceof SQLClientInfoException &&
- method.getName().equals("setClientInfo") &&
- Arrays.asList(method.getParameterTypes())
- .equals(Arrays.asList(new Class[] { Properties.class }))) {
- // setClientInfo(Properties) should throw
- // ClientInfoException, so this is OK
+ if (method.getName().equals("setClientInfo") &&
+ method.getParameterTypes().length == 1 &&
+ method.getParameterTypes()[0] == Properties.class) {
+ // setClientInfo(Properties) should throw SQLClientInfoException
+ if (!sqle.getClass().getName().equals(
+ "java.sql.SQLClientInfoException")) {
+ throw sqle;
+ }
} else if (sqle.getSQLState().equals("08003")) {
// expected, connection closed
} else {
@@ -718,6 +725,10 @@
*/
protected Connection newConnection_() throws SQLException {
DataSource ds = JDBCDataSource.getDataSource();
+ // make sure the database is created when running the test
+ // standalone
+ JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+ "create=true");
return ds.getConnection();
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?view=diff&rev=510012&r1=510011&r2=510012
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java Wed Feb 21 06:12:06 2007
@@ -83,6 +83,7 @@
suite.addTest(LobStreamsTest.suite());
suite.addTest(ResultSetJDBC30Test.suite());
suite.addTest(DatabaseMetaDataTest.suite());
+ suite.addTest(ClosedObjectTest.suite());
}
return suite;
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml?view=diff&rev=510012&r1=510011&r2=510012
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml Wed Feb 21 06:12:06 2007
@@ -122,6 +122,7 @@
<exclude name="${this.dir}/LobStreamsTest.java"/>
<exclude name="${this.dir}/XATest.java"/>
<exclude name="${this.dir}/ScrollResultSetTest.java"/>
+ <exclude name="${this.dir}/ClosedObjectTest.java"/>
<exclude name="${this.dir}/DatabaseMetaDataTest.java"/>
<exclude name="${this.dir}/_Suite.java"/>
</javac>
@@ -157,6 +158,7 @@
<include name="${this.dir}/LobStreamsTest.java"/>
<include name="${this.dir}/XATest.java"/>
<include name="${this.dir}/ScrollResultSetTest.java"/>
+ <include name="${this.dir}/ClosedObjectTest.java"/>
<include name="${this.dir}/DatabaseMetaDataTest.java"/>
</javac>
</target>