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 DropSequenceStatementTest extends AbstractSqlStatementTest {
13:
14: protected SqlStatement generateTestStatement() {
15: return new DropSequenceStatement(null, null);
16: }
17:
18: private static final String SEQ_NAME = "DROPTEST_SEQ";
19:
20: protected void setupDatabase(Database database) throws Exception {
21: dropAndCreateSequence(new CreateSequenceStatement(null,
22: SEQ_NAME), database);
23: dropAndCreateSequence(new CreateSequenceStatement(
24: TestContext.ALT_SCHEMA, SEQ_NAME), database);
25: }
26:
27: @Test
28: public void supportsDatabase() throws Exception {
29: new DatabaseTestTemplate()
30: .testOnAvailableDatabases(new DatabaseTest() {
31: public void performTest(Database database)
32: throws Exception {
33: if (database.supportsSequences()) {
34: assertTrue(generateTestStatement()
35: .supportsDatabase(database));
36: } else {
37: assertFalse(generateTestStatement()
38: .supportsDatabase(database));
39: }
40: }
41: });
42: }
43:
44: @Test
45: public void execute_noSchema() throws Exception {
46: new DatabaseTestTemplate()
47: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
48: null, new DropSequenceStatement(null, SEQ_NAME)) {
49: protected void preExecuteAssert(
50: DatabaseSnapshot snapshot) {
51: assertNotNull(snapshot.getSequence(SEQ_NAME));
52: }
53:
54: protected void postExecuteAssert(
55: DatabaseSnapshot snapshot) {
56: assertNull(snapshot.getSequence(SEQ_NAME));
57: }
58: });
59: }
60:
61: @Test
62: public void execute_withSchema() throws Exception {
63: new DatabaseTestTemplate()
64: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
65: TestContext.ALT_SCHEMA,
66: new DropSequenceStatement(
67: TestContext.ALT_SCHEMA, SEQ_NAME)) {
68: protected void preExecuteAssert(
69: DatabaseSnapshot snapshot) {
70: assertNotNull(snapshot.getSequence(SEQ_NAME));
71: }
72:
73: protected void postExecuteAssert(
74: DatabaseSnapshot snapshot) {
75: assertNull(snapshot.getSequence(SEQ_NAME));
76: }
77: });
78: }
79: }
|