01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.structure.DatabaseSnapshot;
05: import liquibase.test.DatabaseTestTemplate;
06: import liquibase.test.SqlStatementDatabaseTest;
07: import liquibase.test.TestContext;
08: import static org.junit.Assert.*;
09: import org.junit.Test;
10:
11: public class DropPrimaryKeyStatementTest extends
12: AbstractSqlStatementTest {
13:
14: private static final String TABLE_NAME = "DropPKTest";
15: private static final String COLUMN_NAME = "id";
16: private static final String PK_NAME = "pk_dropPkTest";
17:
18: protected void setupDatabase(Database database) throws Exception {
19: dropAndCreateTable(new CreateTableStatement(null, TABLE_NAME)
20: .addColumn(
21: COLUMN_NAME,
22: "int",
23: new PrimaryKeyConstraint(PK_NAME)
24: .addColumns(COLUMN_NAME),
25: new NotNullConstraint()).addColumn("otherCol",
26: "varchar(50)"), database);
27:
28: dropAndCreateTable(new CreateTableStatement(
29: TestContext.ALT_SCHEMA, TABLE_NAME).addColumn(
30: COLUMN_NAME,
31: "int",
32: new PrimaryKeyConstraint(PK_NAME)
33: .addColumns(COLUMN_NAME),
34: new NotNullConstraint()).addColumn("otherCol",
35: "varchar(50)"), database);
36: }
37:
38: protected SqlStatement generateTestStatement() {
39: return new DropPrimaryKeyStatement(null, null, null);
40: }
41:
42: @Test
43: public void execute_defaultSchema() throws Exception {
44: new DatabaseTestTemplate()
45: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
46: null, new DropPrimaryKeyStatement(null,
47: TABLE_NAME, PK_NAME)) {
48:
49: protected void preExecuteAssert(
50: DatabaseSnapshot snapshot) {
51: assertTrue(snapshot.getTable(TABLE_NAME)
52: .getColumn(COLUMN_NAME).isPrimaryKey());
53: }
54:
55: protected void postExecuteAssert(
56: DatabaseSnapshot snapshot) {
57: assertFalse(snapshot.getTable(TABLE_NAME)
58: .getColumn(COLUMN_NAME).isPrimaryKey());
59: }
60:
61: });
62: }
63:
64: @Test
65: public void execute_altSchema() throws Exception {
66: new DatabaseTestTemplate()
67: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
68: TestContext.ALT_SCHEMA,
69: new DropPrimaryKeyStatement(
70: TestContext.ALT_SCHEMA, TABLE_NAME,
71: PK_NAME)) {
72:
73: protected void preExecuteAssert(
74: DatabaseSnapshot snapshot) {
75: assertTrue(snapshot.getTable(TABLE_NAME)
76: .getColumn(COLUMN_NAME).isPrimaryKey());
77: }
78:
79: protected void postExecuteAssert(
80: DatabaseSnapshot snapshot) {
81: assertFalse(snapshot.getTable(TABLE_NAME)
82: .getColumn(COLUMN_NAME).isPrimaryKey());
83: }
84:
85: });
86: }
87: }
|