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 2006/09/22 14:18:16 UTC
svn commit: r448900 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/lang/SQLAuthorizationPropTest.java
junit/BaseJDBCTestCase.java junit/TestConfiguration.java
Author: kahatlen
Date: Fri Sep 22 05:18:15 2006
New Revision: 448900
URL: http://svn.apache.org/viewvc?view=rev&rev=448900
Log:
DERBY-1826: Add JUnit utility methods for database/server shutdown
Patch contributed by Deepa Remesh.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java?view=diff&rev=448900&r1=448899&r2=448900
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java Fri Sep 22 05:18:15 2006
@@ -34,7 +34,6 @@
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
-import org.apache.derbyTesting.functionTests.util.TestUtil;
public class SQLAuthorizationPropTest extends BaseJDBCTestCase {
@@ -116,7 +115,7 @@
// Shutdown the database for derby.database.sqlAuthorization property
// to take effect. This was set by DatabasePropertyTestSetup decorator.
try{
- TestUtil.getConnection("wombat", "shutdown=true");
+ getDefaultConnection("shutdown=true");
fail("FAIL: Failed to shutdown database");
} catch (SQLException sqle) {
assertSQLState(SQLStateConstants.SHUTDOWN_DATABASE, sqle);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?view=diff&rev=448900&r1=448899&r2=448900
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri Sep 22 05:18:15 2006
@@ -89,6 +89,8 @@
* <LI> getConnection()
* <LI> openDefaultConnection()
* <LI> openConnection(database)
+ * <LI> getDefaultConnection(String connAttrs)
+ * <LI> getConnection(String databaseName, String connAttrs)
* </UL>
* when getConnection() opens a new connection. Default
* action is to not modify the connection's state from
@@ -198,6 +200,40 @@
initializeConnection(conn);
return conn;
}
+
+ /**
+ * Get a connection to the default database using the specified connection
+ * attributes.
+ *
+ * @param connAttrs connection attributes
+ * @return connection to default database.
+ * @throws SQLException
+ */
+ public Connection getDefaultConnection(String connAttrs)
+ throws SQLException {
+ Connection conn = getTestConfiguration().
+ getDefaultConnection(connAttrs);
+ initializeConnection(conn);
+ return conn;
+ }
+
+ /**
+ * Get a connection to a database using the specified connection
+ * attributes.
+ *
+ * @param databaseName database to connect to
+ * @param connAttrs connection attributes
+ * @return connection to database
+ * @throws SQLException
+ */
+ public Connection getConnection(String databaseName, String connAttrs)
+ throws SQLException
+ {
+ Connection conn = getTestConfiguration().getConnection(databaseName,
+ connAttrs);
+ initializeConnection(conn);
+ return conn;
+ }
/**
* Run a SQL script through ij discarding the output
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=448900&r1=448899&r2=448900
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Fri Sep 22 05:18:15 2006
@@ -408,7 +408,7 @@
*/
public Connection openDefaultConnection()
throws SQLException {
- return openConnection(getDatabaseName());
+ return getDefaultConnection("create=true");
}
/**
@@ -421,26 +421,53 @@
* @return connection to database.
*/
public Connection openConnection (String databaseName) throws SQLException {
+ return getConnection(databaseName, "create=true");
+ }
+
+ /**
+ * Get a connection to the default database using the specified connection
+ * attributes.
+ *
+ * @param connAttrs connection attributes
+ * @return connection to database.
+ * @throws SQLException
+ */
+ public Connection getDefaultConnection(String connAttrs)
+ throws SQLException {
+ return getConnection(getDatabaseName(), connAttrs);
+ }
+
+ /**
+ * Get a connection to a database using the specified connection
+ * attributes.
+ *
+ * @param databaseName database to connect to
+ * @param connAttrs connection attributes
+ * @return connection to database.
+ * @throws SQLException
+ */
+ public Connection getConnection (String databaseName, String connAttrs)
+ throws SQLException {
Connection con = null;
JDBCClient client =getJDBCClient();
if (JDBC.vmSupportsJDBC2()) {
loadJDBCDriver(client.getJDBCDriverName());
if (!isSingleLegXA()) {
con = DriverManager.getConnection(
- getJDBCUrl(databaseName) + ";create=true",
+ getJDBCUrl(databaseName) + ";" + connAttrs,
getUserName(),
getUserPassword());
}
else {
Properties attrs =
- getDataSourcePropertiesForDatabase(databaseName);
+ getDataSourcePropertiesForDatabase(databaseName, connAttrs);
con = TestDataSourceFactory.getXADataSource(attrs).
getXAConnection (getUserName(),
getUserPassword()).getConnection();
}
} else {
//Use DataSource for JSR169
- Properties attrs = getDataSourcePropertiesForDatabase(databaseName);
+ Properties attrs = getDataSourcePropertiesForDatabase(databaseName, connAttrs);
con = TestDataSourceFactory.getDataSource(attrs).getConnection();
}
return con;
@@ -564,7 +591,7 @@
/**
* Generate properties which can be set on a
* <code>DataSource</code> in order to connect to the default
- * database.
+ * database. If the database does not exist, it will be created.
*
* @return a <code>Properties</code> object containing server
* name, port number, database name and other attributes needed to
@@ -572,22 +599,20 @@
*/
public static Properties getDefaultDataSourceProperties() {
return getDataSourcePropertiesForDatabase(
- getCurrent().getDatabaseName());
+ getCurrent().getDatabaseName(), "create=true");
}
/**
- * Generate properties which can be set on a
- * <code>DataSource</code> in order to connect to a given
- * database.
- *
+ * Generate properties which can be set on a <code>DataSource</code>
+ * in order to connect to a database using the specified connection
+ * attributes.
+ *
* @param databaseName database to connect to
- *
- * @return a <code>Properties</code> object containing server
- * name, port number, database name and other attributes needed to
- * connect to the database
+ * @param connAttrs connection attributes
+ * @return
*/
public static Properties getDataSourcePropertiesForDatabase
- (String databaseName)
+ (String databaseName, String connAttrs)
{
Properties attrs = new Properties();
if (!(getCurrent().getJDBCClient() == JDBCClient.EMBEDDED)) {
@@ -595,7 +620,7 @@
attrs.setProperty("portNumber", Integer.toString(getCurrent().getPort()));
}
attrs.setProperty("databaseName", databaseName);
- attrs.setProperty("connectionAttributes", "create=true");
+ attrs.setProperty("connectionAttributes", connAttrs);
return attrs;
}