Author: djd
Date: Thu Mar 15 12:13:27 2007
New Revision: 518728
URL: http://svn.apache.org/viewvc?view=rev&rev=518728
Log:
Add test utility method to clear (set to null) a string Java bean property for a data source.
Use this in AuthenticationTest to simplify data source creation and ensure data sources created
are based off the current configuration.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java?view=diff&rev=518728&r1=518727&r2=518728
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
Thu Mar 15 12:13:27 2007
@@ -845,44 +845,24 @@
}
public void assertConnectionFail(String dbName) throws SQLException {
- // this method needs to create DataSources without relying on
- // the JDBC methods, because those use a default user/pwd
- // (APP, APP).
+
+ // Get the default data source but clear the user and
+ // password set by the configuration.
+ DataSource ds = JDBCDataSource.getDataSource(dbName);
+
+ // Reset to no user/password though client requires
+ // a valid name, so reset to the default
if (usingDerbyNetClient())
- {
- ClientDataSource ds = new ClientDataSource();
- ds.setDatabaseName(dbName);
- try {
- ds.getConnection();
- fail("expected connection to fail");
- } catch (SQLException e) {
- assertSQLState("08004", e);
- }
- }
- else if (usingEmbedded())
- {
- if (JDBC.vmSupportsJSR169())
- {
- EmbeddedSimpleDataSource ds = new EmbeddedSimpleDataSource();
- ds.setDatabaseName(dbName);
- try {
- ds.getConnection();
- fail("expected connection to fail");
- } catch (SQLException e) {
- assertSQLState("08004", e);
- }
- }
- else
- {
- EmbeddedDataSource ds = new EmbeddedDataSource();
- ds.setDatabaseName(dbName);
- try {
- ds.getConnection();
- fail("expected connection to fail");
- } catch (SQLException e) {
- assertSQLState("08004", e);
- }
- }
- }
+ JDBCDataSource.setBeanProperty(ds, "user", "APP");
+ else
+ JDBCDataSource.clearStringBeanProperty(ds, "user");
+ JDBCDataSource.clearStringBeanProperty(ds, "password");
+
+ try {
+ ds.getConnection();
+ fail("expected connection to fail");
+ } catch (SQLException e) {
+ assertSQLState("08004", e);
+ }
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=518728&r1=518727&r2=518728
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Thu
Mar 15 12:13:27 2007
@@ -173,6 +173,23 @@
}
}
+ /**
+ * Clear a String Java bean property by setting it to null.
+ * @param ds ds DataSource to have property cleared
+ * @param property name of property.
+ */
+ public static void clearStringBeanProperty(Object ds, String property)
+ {
+ String setterName = getSetterName(property);
+ try {
+ Method setter = ds.getClass().getMethod(setterName,
+ new Class[] {String.class});
+ setter.invoke(ds, new Object[] {null});
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
private static String getSetterName(String attribute) {
return "set" + Character.toUpperCase(attribute.charAt(0))
+ attribute.substring(1);
|