public class DerbyJUnitTest
extends junit.framework.TestCase
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
_databaseName |
private static boolean |
_debug |
private static java.lang.String[] |
_defaultClientSettings |
private static java.io.PrintStream |
_outputStream |
private static java.lang.String |
CREATE_PROPERTY |
static int |
DATABASE_URL |
static java.lang.String |
DEBUG_FLAG
If you set this startup property to true, you will get chatty output.
|
static java.lang.String |
DEFAULT_DATABASE_NAME |
static java.lang.String |
DEFAULT_PASSWORD |
static java.lang.String |
DEFAULT_USER_NAME |
private static java.lang.String[] |
DERBY_CLIENT |
static int |
DRIVER_NAME |
private static java.lang.String[] |
EMBEDDED_CLIENT |
static int |
FAILURE_EXIT |
static int |
FRAMEWORK_NAME |
private static java.lang.String |
FUNCTION |
protected static int |
JDBC_BOOLEAN |
static java.lang.String[][] |
LEGAL_CLIENTS |
private static java.lang.String |
PROCEDURE |
static int |
SUCCESS_EXIT |
private static java.lang.String |
TABLE |
private static java.lang.String |
TYPE |
Constructor and Description |
---|
DerbyJUnitTest()
Vacuous constructor for JUnit machinery.
|
Modifier and Type | Method and Description |
---|---|
static void |
alarm(java.lang.String text)
Print a message regardless of whether we are running in debug mode.
|
void |
assertColumnEquals(java.sql.ResultSet rs,
int columnNumber,
java.lang.Object[] expectedValues)
Assert the values in a ResultSet for a given column across all rows.
|
void |
assertColumnEquals(java.lang.String message,
java.sql.ResultSet rs,
int columnNumber,
java.lang.Object expectedValue)
Assert a column's value.
|
void |
assertRow(java.sql.ResultSet rs,
java.lang.Object[] expectedRow)
Assert the values of a whole row.
|
void |
assertScalar(java.sql.Connection conn,
java.lang.String queryText,
java.lang.Object expectedResult)
Assert a scalar result from a query.
|
protected static void |
close(java.sql.Connection conn)
Close a Connection.
|
protected static void |
close(java.sql.ResultSet rs)
Close a ResultSet.
|
protected static void |
close(java.sql.Statement statement)
Close a Statement.
|
void |
compareBytes(java.lang.String message,
java.lang.Object left,
java.lang.Object right)
Assert two byte arrays are equal, allowing nulls to be equal.
|
void |
compareDates(java.lang.String message,
java.lang.Object left,
java.lang.Object right)
Assert two Dates are equal, allowing nulls to be equal.
|
void |
compareObjects(java.lang.String message,
java.lang.Object left,
java.lang.Object right)
Assert two objects are equal, allowing nulls to be equal.
|
protected void |
createDB(java.lang.String databaseName)
Create an empty database.
|
protected static void |
dropFunction(java.sql.Connection conn,
java.lang.String name)
Drop a function regardless of whether it exists.
|
protected static void |
dropProcedure(java.sql.Connection conn,
java.lang.String name)
Drop a procedure regardless of whether it exists.
|
protected static void |
dropSchemaObject(java.sql.Connection conn,
java.lang.String genus,
java.lang.String objectName,
boolean restrict)
Drop a schema object regardless of whether it exists.
|
protected static void |
dropTable(java.sql.Connection conn,
java.lang.String name)
Drop a table regardless of whether it exists.
|
protected static void |
dropUDT(java.sql.Connection conn,
java.lang.String name)
Drop a UDT regardless of whether it exists.
|
protected static void |
execute(java.sql.Connection conn,
java.lang.String text)
Execute a SQL statement, given by the text argument.
|
protected static void |
executeDDL(java.sql.Connection conn,
java.lang.String text)
Execute DDL statement.
|
protected static boolean |
faultInDriver(java.lang.String[] clientSettings)
Load a client driver, given its particulars.
|
static java.lang.String[] |
getClientSettings()
Get the client we're using.
|
protected java.lang.Object |
getColumn(java.sql.ResultSet rs,
int param,
java.lang.Object value)
Read a column from a ResultSet given its column position
and an expected Java type.
|
protected java.lang.Object |
getColumn(java.sql.ResultSet rs,
java.lang.String columnName,
int jdbcType)
Read a column from a ResultSet given its column name and expected jdbc
type.
|
protected static java.sql.Connection |
getConnection()
Get a connection to a database, using the default client.
|
protected static java.sql.Connection |
getConnection(java.lang.String[] clientSettings,
java.lang.String databaseName,
java.util.Properties properties)
Get a connection to a database, using the specified client.
|
protected java.lang.Object |
getOutArg(java.sql.CallableStatement cs,
int arg,
int jdbcType)
Read an output argument from a CallableStatement given its 1-based
argument position and expected jdbc type.
|
private static java.lang.String |
makeDatabaseURL(java.lang.String[] clientSettings,
java.lang.String databaseName)
Cobble together a connection URL.
|
static boolean |
parseDebug()
Look for the system property which tells us whether to run
chattily.
|
protected static java.sql.PreparedStatement |
prepare(java.sql.Connection conn,
java.lang.String text)
Prepare a SQL statement, given by the text argument.
|
protected static java.sql.CallableStatement |
prepareCall(java.sql.Connection conn,
java.lang.String text)
Prepare a SQL call statement, given by the text argument.
|
static void |
println(java.lang.String text)
Debug code to print chatty informational messages.
|
static void |
printStackTrace(java.lang.Throwable t)
Print out a stack trace.
|
static void |
setClient(java.lang.String[] client)
Set the client we're going to use.
|
static void |
setDatabaseName(java.lang.String databaseName)
Set the database name.
|
static void |
setDebug(boolean value)
Force the debugging state.
|
protected void |
setParameter(java.sql.PreparedStatement ps,
int param,
int jdbcType,
java.lang.Object value)
Stuff a PreparedStatement parameter given its 1-based parameter position
and expected jdbc type.
|
protected void |
setParameter(java.sql.PreparedStatement ps,
int param,
java.lang.Object value)
Stuff a PreparedStatement parameter given its 1-based parameter position.
|
protected java.lang.String |
singleQuote(java.lang.String text)
Single quote a string.
|
protected static void |
truncateTable(java.sql.Connection conn,
java.lang.String name)
Scour out all the rows from a table.
|
boolean |
usingDerbyClient()
Return true if we're using the derby client
|
boolean |
usingEmbeddedClient()
Return true if we're using the embedded driver.
|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
public static final java.lang.String DEBUG_FLAG
public static final int SUCCESS_EXIT
public static final int FAILURE_EXIT
public static final java.lang.String DEFAULT_USER_NAME
public static final java.lang.String DEFAULT_PASSWORD
public static final java.lang.String DEFAULT_DATABASE_NAME
protected static final int JDBC_BOOLEAN
private static final java.lang.String TABLE
private static final java.lang.String FUNCTION
private static final java.lang.String PROCEDURE
private static final java.lang.String TYPE
private static final java.lang.String CREATE_PROPERTY
public static final int DATABASE_URL
public static final int DRIVER_NAME
public static final int FRAMEWORK_NAME
private static final java.lang.String[] DERBY_CLIENT
private static final java.lang.String[] EMBEDDED_CLIENT
public static final java.lang.String[][] LEGAL_CLIENTS
private static boolean _debug
private static java.io.PrintStream _outputStream
private static java.lang.String _databaseName
private static java.lang.String[] _defaultClientSettings
public boolean usingEmbeddedClient()
Return true if we're using the embedded driver.
public boolean usingDerbyClient()
Return true if we're using the derby client
public static java.lang.String[] getClientSettings()
Get the client we're using.
public static void setClient(java.lang.String[] client)
Set the client we're going to use.
public static void setDatabaseName(java.lang.String databaseName)
Set the database name.
public static void setDebug(boolean value)
Force the debugging state. Useful for debugging under the test harness.
public static boolean parseDebug()
Look for the system property which tells us whether to run chattily.
public static void println(java.lang.String text)
Debug code to print chatty informational messages.
public static void alarm(java.lang.String text)
Print a message regardless of whether we are running in debug mode.
public static void printStackTrace(java.lang.Throwable t)
Print out a stack trace.
protected static boolean faultInDriver(java.lang.String[] clientSettings)
Load a client driver, given its particulars.
protected static java.sql.Connection getConnection() throws java.lang.Exception
Get a connection to a database, using the default client.
java.lang.Exception
protected static java.sql.Connection getConnection(java.lang.String[] clientSettings, java.lang.String databaseName, java.util.Properties properties) throws java.lang.Exception
Get a connection to a database, using the specified client.
java.lang.Exception
private static java.lang.String makeDatabaseURL(java.lang.String[] clientSettings, java.lang.String databaseName)
Cobble together a connection URL.
protected void createDB(java.lang.String databaseName) throws java.lang.Exception
Create an empty database.
java.lang.Exception
protected static void executeDDL(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
Execute DDL statement.
java.sql.SQLException
protected static void execute(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
Execute a SQL statement, given by the text argument. This thin wrapper around the JDBC machinery logs the statement text when running in debug mode.
java.sql.SQLException
protected static java.sql.PreparedStatement prepare(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
Prepare a SQL statement, given by the text argument. This thin wrapper around the JDBC machinery logs the statement text when running in debug mode.
java.sql.SQLException
protected static java.sql.CallableStatement prepareCall(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException
Prepare a SQL call statement, given by the text argument. This thin wrapper around the JDBC machinery logs the statement text when running in debug mode.
java.sql.SQLException
protected static void truncateTable(java.sql.Connection conn, java.lang.String name) throws java.sql.SQLException
Scour out all the rows from a table.
java.sql.SQLException
protected static void dropTable(java.sql.Connection conn, java.lang.String name)
Drop a table regardless of whether it exists. If the table does not exist, don't log an error unless running in debug mode. This method is to be used for reinitializing a schema in case a previous test run failed to clean up after itself. Do not use this method if you need to verify that the table really exists.
protected static void dropFunction(java.sql.Connection conn, java.lang.String name)
Drop a function regardless of whether it exists. If the function does not exist, don't log an error unless running in debug mode. This method is to be used for reinitializing a schema in case a previous test run failed to clean up after itself. Do not use this method if you need to verify that the function really exists.
protected static void dropProcedure(java.sql.Connection conn, java.lang.String name)
Drop a procedure regardless of whether it exists. If the procedure does not exist, don't log an error unless running in debug mode. This method is to be used for reinitializing a schema in case a previous test run failed to clean up after itself. Do not use this method if you need to verify that the procedure really exists.
protected static void dropUDT(java.sql.Connection conn, java.lang.String name)
Drop a UDT regardless of whether it exists. If the UDT does not exist, don't log an error unless running in debug mode. This method is to be used for reinitializing a schema in case a previous test run failed to clean up after itself. Do not use this method if you need to verify that the UDT really exists.
protected static void dropSchemaObject(java.sql.Connection conn, java.lang.String genus, java.lang.String objectName, boolean restrict)
Drop a schema object regardless of whether it exists. If the object does not exist, don't log an error unless running in debug mode. This method is to be used for reinitializing a schema in case a previous test run failed to clean up after itself. Do not use this method if you need to verify that the object really exists.
protected static void close(java.sql.ResultSet rs)
Close a ResultSet. This method factors out the check for whether the ResultSet was created in the first place. This tidies up the caller's cleanup logic. If an error occurs, print it. Because this method swallows the exception after printing it, do not call this method if you want your test to halt on error.
protected static void close(java.sql.Statement statement)
Close a Statement. This method factors out the check for whether the Statement was created in the first place. This tidies up the caller's cleanup logic. If an error occurs, print it. Because this method swallows the exception after printing it, do not call this method if you want your test to halt on error.
protected static void close(java.sql.Connection conn)
Close a Connection. This method factors out the check for whether the Connection was created in the first place. This tidies up the caller's cleanup logic. If an error occurs, print it. Because this method swallows the exception after printing it, do not call this method if you want your test to halt on error.
protected java.lang.Object getColumn(java.sql.ResultSet rs, java.lang.String columnName, int jdbcType) throws java.lang.Exception
Read a column from a ResultSet given its column name and expected jdbc type. This method is useful if you are want to verify the getXXX() logic most naturally fitting the declared SQL type.
java.lang.Exception
protected java.lang.Object getColumn(java.sql.ResultSet rs, int param, java.lang.Object value) throws java.lang.Exception
Read a column from a ResultSet given its column position and an expected Java type. This method is useful when comparing ResultSets against expected values.
rs
- The ResultSet to read.param
- The column number (1-based)value
- An object whose type is what we expect the column to be.java.lang.Exception
protected java.lang.Object getOutArg(java.sql.CallableStatement cs, int arg, int jdbcType) throws java.lang.Exception
Read an output argument from a CallableStatement given its 1-based argument position and expected jdbc type. This is useful for exercising the getXXX() methods most natural to a declared SQL type.
java.lang.Exception
protected void setParameter(java.sql.PreparedStatement ps, int param, int jdbcType, java.lang.Object value) throws java.lang.Exception
Stuff a PreparedStatement parameter given its 1-based parameter position and expected jdbc type. This method is useful for testing the setXXX() methods most natural for a declared SQL type.
java.lang.Exception
protected void setParameter(java.sql.PreparedStatement ps, int param, java.lang.Object value) throws java.lang.Exception
Stuff a PreparedStatement parameter given its 1-based parameter position. The appropriate setXXX() method is determined by the Java type of the value being stuffed. This method is useful for testing setXXX() methods other than the most natural fit for the declared SQL type.
java.lang.Exception
protected java.lang.String singleQuote(java.lang.String text)
Single quote a string. This is a helper routine for use in generating SQL text.
public void assertRow(java.sql.ResultSet rs, java.lang.Object[] expectedRow) throws java.lang.Exception
Assert the values of a whole row.
java.lang.Exception
public void assertScalar(java.sql.Connection conn, java.lang.String queryText, java.lang.Object expectedResult) throws java.lang.Exception
Assert a scalar result from a query.
java.lang.Exception
public void assertColumnEquals(java.sql.ResultSet rs, int columnNumber, java.lang.Object[] expectedValues) throws java.lang.Exception
Assert the values in a ResultSet for a given column across all rows.
java.lang.Exception
public void assertColumnEquals(java.lang.String message, java.sql.ResultSet rs, int columnNumber, java.lang.Object expectedValue) throws java.lang.Exception
Assert a column's value.
java.lang.Exception
public void compareObjects(java.lang.String message, java.lang.Object left, java.lang.Object right) throws java.lang.Exception
Assert two objects are equal, allowing nulls to be equal.
java.lang.Exception
public void compareBytes(java.lang.String message, java.lang.Object left, java.lang.Object right) throws java.lang.Exception
Assert two byte arrays are equal, allowing nulls to be equal.
java.lang.Exception
public void compareDates(java.lang.String message, java.lang.Object left, java.lang.Object right) throws java.lang.Exception
Assert two Dates are equal, allowing nulls to be equal.
java.lang.Exception
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.