|
BrokenEvent nanotests | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.brokenevent.nanotests.DbAssert
public final class DbAssert
Helper class for DataBase-related asserts.
These methods can be used directly:
DbAssert.assertQueryNotNull(...)
, however, they read better if they
are referenced through static import:
import static com.brokenevent.nanotests.DbAssert.*; ... assertQueryNotNull(...);
Constructor Summary | |
---|---|
protected |
DbAssert()
Protect constructor since it is a static only class |
Method Summary | ||
---|---|---|
static void |
assertLastRow(java.lang.String table,
java.lang.String id,
java.lang.String field,
boolean expected)
Asserts that the value from the last row of the table equals given value. |
|
static void |
assertLastRow(java.lang.String table,
java.lang.String id,
java.lang.String field,
java.util.Date expected)
Asserts that the value from the last row of the table equals given value. |
|
static void |
assertLastRow(java.lang.String table,
java.lang.String id,
java.lang.String field,
int expected)
Asserts that the value from the last row of the table equals given value. |
|
static void |
assertLastRow(java.lang.String table,
java.lang.String id,
java.lang.String field,
java.lang.String expected)
Asserts that the value from the last row of the table equals given value. |
|
static void |
assertQueryNotNull(java.lang.String sql)
Asserts that query result is not empty. |
|
static void |
assertQueryNull(java.lang.String sql)
Asserts that query result is empty. |
|
static void |
assertRow(java.lang.String table,
java.lang.String id,
int idValue,
java.lang.String field,
boolean expected)
Asserts that the value from one of the rows of the table equals the expected. |
|
static void |
assertRow(java.lang.String table,
java.lang.String id,
int idValue,
java.lang.String field,
int expected)
Asserts that the value from one of the rows of the table equals the expected. |
|
static void |
assertRow(java.lang.String table,
java.lang.String id,
int idValue,
java.lang.String field,
java.lang.String expected)
Asserts that the value from one of the rows of the table equals the expected. |
|
static void |
assertRow(java.lang.String table,
java.lang.String id,
java.lang.String idValue,
java.lang.String field,
boolean expected)
Asserts that the value from one of the rows of the table equals the expected. |
|
static void |
assertRow(java.lang.String table,
java.lang.String id,
java.lang.String idValue,
java.lang.String field,
int expected)
Asserts that the value from one of the rows of the table equals the expected. |
|
static void |
assertRow(java.lang.String table,
java.lang.String id,
java.lang.String idValue,
java.lang.String field,
java.lang.String expected)
Asserts that the value from one of the rows of the table equals the expected. |
|
static void |
execute(java.lang.String sql)
Helper method to execute non-query statement with the existing connection. |
|
static int |
getLastIdNum(java.lang.String table,
java.lang.String id)
Helper method to get the last ID from the table where ID field is numeric. |
|
static java.lang.String |
getLastIdStr(java.lang.String table,
java.lang.String id)
Helper method to get the last ID from the table where ID field is string. |
|
static void |
initDbAssert(java.lang.String connectionString,
java.lang.String login,
java.lang.String password,
java.lang.String driverClassName)
Initialize DbAssert before usage. |
|
static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
query(java.lang.String sql)
Helper method to execute query with the existing connection. |
|
static java.util.Map<java.lang.String,java.lang.Object> |
querySingle(java.lang.String sql)
Helper method to execute query with a single-row result with the existing connection. |
|
static
|
querySingleColumn(java.lang.String sql)
Helper method to execute query with a single-column result with the existing connection. |
|
static void |
shutdownDbAssert()
Shutdown db connection. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected DbAssert()
Method Detail |
---|
public static void initDbAssert(java.lang.String connectionString, java.lang.String login, java.lang.String password, java.lang.String driverClassName)
org.junit.Before
or org.junit.BeforeClass
method of the testcase.
connectionString
- jdbc connection stringlogin
- database loginpassword
- database passworddriverClassName
- driver classnamepublic static void shutdownDbAssert()
org.junit.After
or org.junit.AfterClass
method of the testcase.
public static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> query(java.lang.String sql)
sql
- query text
public static java.util.Map<java.lang.String,java.lang.Object> querySingle(java.lang.String sql)
sql
- query text
public static <T> java.util.List<T> querySingleColumn(java.lang.String sql)
sql
- query text
public static void execute(java.lang.String sql)
sql
- query textpublic static void assertQueryNotNull(java.lang.String sql)
AssertionError
is thrown.
sql
- SQL query textpublic static void assertQueryNull(java.lang.String sql)
AssertionError
is thrown.
sql
- SQL query textpublic static void assertLastRow(java.lang.String table, java.lang.String id, java.lang.String field, java.lang.String expected)
AssertionError
is thrown.SELECT MAX(id) FROM tableBeware to use this assertion when running multiple tests interconnected with a single table at once. Some tests can fail due to thread operations intersection.
table
- table name to query fromid
- table primary key field namefield
- field name to assert value fromexpected
- expected valuepublic static void assertLastRow(java.lang.String table, java.lang.String id, java.lang.String field, int expected)
AssertionError
is thrown.SELECT MAX(id) FROM tableBeware to use this assertion when running multiple tests interconnected with a single table at once. Some tests can fail due to thread operations intersection.
table
- table name to query fromid
- table primary key field namefield
- field name to assert value fromexpected
- expected valuepublic static void assertLastRow(java.lang.String table, java.lang.String id, java.lang.String field, java.util.Date expected)
AssertionError
is thrown.SELECT MAX(id) FROM tableBeware to use this assertion when running multiple tests interconnected with a single table at once. Some tests can fail due to thread operations intersection.
table
- table name to query fromid
- table primary key field namefield
- field name to assert value fromexpected
- expected valuepublic static void assertLastRow(java.lang.String table, java.lang.String id, java.lang.String field, boolean expected)
AssertionError
is thrown.SELECT MAX(id) FROM tableBeware to use this assertion when running multiple tests interconnected with a single table at once. Some tests can fail due to thread operations intersection.
table
- table name to query fromid
- table primary key field namefield
- field name to assert value fromexpected
- expected valuepublic static int getLastIdNum(java.lang.String table, java.lang.String id)
SELECT MAX(id) FROM table
table
- table name to query fromid
- table primary key field name
public static java.lang.String getLastIdStr(java.lang.String table, java.lang.String id)
SELECT MAX(id) FROM table
table
- table name to query fromid
- table primary key field name
public static void assertRow(java.lang.String table, java.lang.String id, java.lang.String idValue, java.lang.String field, java.lang.String expected)
AssertionError
is thrown.
table
- table name to query fromid
- table primary key field name (or other field to use in WHERE clause)idValue
- value of the primary key field (or other field to use on comparison of the WHERE clause)field
- field name to assert value fromexpected
- expected valuepublic static void assertRow(java.lang.String table, java.lang.String id, java.lang.String idValue, java.lang.String field, int expected)
AssertionError
is thrown.
table
- table name to query fromid
- table primary key field name (or other field to use in WHERE clause)idValue
- value of the primary key field (or other field to use on comparison of the WHERE clause)field
- field name to assert value fromexpected
- expected valuepublic static void assertRow(java.lang.String table, java.lang.String id, java.lang.String idValue, java.lang.String field, boolean expected)
AssertionError
is thrown.
table
- table name to query fromid
- table primary key field name (or other field to use in WHERE clause)idValue
- value of the primary key field (or other field to use on comparison of the WHERE clause)field
- field name to assert value fromexpected
- expected valuepublic static void assertRow(java.lang.String table, java.lang.String id, int idValue, java.lang.String field, java.lang.String expected)
AssertionError
is thrown.
table
- table name to query fromid
- table primary key field name (or other field to use in WHERE clause)idValue
- value of the primary key field (or other field to use on comparison of the WHERE clause)field
- field name to assert value fromexpected
- expected valuepublic static void assertRow(java.lang.String table, java.lang.String id, int idValue, java.lang.String field, int expected)
AssertionError
is thrown.
table
- table name to query fromid
- table primary key field name (or other field to use in WHERE clause)idValue
- value of the primary key field (or other field to use on comparison of the WHERE clause)field
- field name to assert value fromexpected
- expected valuepublic static void assertRow(java.lang.String table, java.lang.String id, int idValue, java.lang.String field, boolean expected)
AssertionError
is thrown.
table
- table name to query fromid
- table primary key field name (or other field to use in WHERE clause)idValue
- value of the primary key field (or other field to use on comparison of the WHERE clause)field
- field name to assert value fromexpected
- expected value
|
BrokenEvent nanotests | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |