01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.structure.DatabaseSnapshot;
05: import liquibase.test.DatabaseTest;
06: import liquibase.test.DatabaseTestTemplate;
07: import liquibase.test.SqlStatementDatabaseTest;
08: import liquibase.test.TestContext;
09: import static org.junit.Assert.*;
10: import org.junit.Test;
11:
12: public class UpdateStatementTest extends AbstractSqlStatementTest {
13:
14: private static final String TABLE_NAME = "UpdateTest";
15: private static final String COLUMN_NAME = "testCol";
16:
17: protected void setupDatabase(Database database) throws Exception {
18: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
19: .addColumn("id", "int").addColumn(COLUMN_NAME,
20: "varchar(50)"), database);
21:
22: dropAndCreateTable(new CreateTableStatement(
23: TestContext.ALT_SCHEMA, TABLE_NAME).addColumn("id",
24: "int").addColumn(COLUMN_NAME, "varchar(50)"), database);
25: }
26:
27: protected SqlStatement generateTestStatement() {
28: return new UpdateStatement(null, null);
29: }
30:
31: @Test
32: public void addNewColumnValue_nullValue() throws Exception {
33: new DatabaseTestTemplate()
34: .testOnAllDatabases(new DatabaseTest() {
35:
36: public void performTest(Database database) {
37: UpdateStatement statement = new UpdateStatement(
38: null, TABLE_NAME);
39: statement.addNewColumnValue(COLUMN_NAME, null);
40:
41: assertEquals("UPDATE "
42: + database.escapeTableName(null,
43: TABLE_NAME) + " SET "
44: + COLUMN_NAME + " = NULL", statement
45: .getSqlStatement(database));
46: }
47: });
48: }
49:
50: @Test
51: public void execute_altSchema() throws Exception {
52: new DatabaseTestTemplate()
53: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
54: TestContext.ALT_SCHEMA, new UpdateStatement(
55: TestContext.ALT_SCHEMA, TABLE_NAME)
56: .addNewColumnValue(COLUMN_NAME, null)) {
57: protected void preExecuteAssert(
58: DatabaseSnapshot snapshot) {
59: //nothing to test
60: }
61:
62: protected void postExecuteAssert(
63: DatabaseSnapshot snapshot) {
64: //nothing to test
65: }
66: });
67: }
68: }
|