View Javadoc

1   package liquibase.change.core;
2   
3   import liquibase.change.AbstractChangeTest;
4   import liquibase.database.core.MockDatabase;
5   import liquibase.statement.SqlStatement;
6   import liquibase.statement.core.DropTableStatement;
7   import static org.junit.Assert.*;
8   import org.junit.Before;
9   import org.junit.Test;
10  
11  /**
12   * Tests for {@link DropTableChange}
13   */
14  public class DropTableChangeTest extends AbstractChangeTest {
15      private DropTableChange change;
16  
17      @Before
18      public void setUp() throws Exception {
19          change = new DropTableChange();
20          change.setSchemaName("SCHEMA_NAME");
21          change.setTableName("TAB_NAME");
22          change.setCascadeConstraints(true);
23      }
24  
25      @Override
26      @Test
27      public void getRefactoringName() throws Exception {
28          assertEquals("Drop Table", change.getChangeMetaData().getDescription());
29      }
30  
31      @Override
32      @Test
33      public void generateStatement() throws Exception {
34          SqlStatement[] sqlStatements = change.generateStatements(new MockDatabase());
35          assertEquals(1, sqlStatements.length);
36          assertTrue(sqlStatements[0] instanceof DropTableStatement);
37          assertEquals("SCHEMA_NAME", ((DropTableStatement) sqlStatements[0]).getSchemaName());
38          assertEquals("TAB_NAME", ((DropTableStatement) sqlStatements[0]).getTableName());
39          assertTrue(((DropTableStatement) sqlStatements[0]).isCascadeConstraints());
40      }
41  
42      @Test
43      public void generateStatement_nullCascadeConstraints() throws Exception {
44          change.setCascadeConstraints(null);
45          SqlStatement[] sqlStatements = change.generateStatements(new MockDatabase());
46          assertFalse(((DropTableStatement) sqlStatements[0]).isCascadeConstraints());
47      }
48  
49      @Override
50      @Test
51      public void getConfirmationMessage() throws Exception {
52          assertEquals("Table TAB_NAME dropped", change.getConfirmationMessage());
53      }
54  }