01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.DropTableStatement;
05: import liquibase.database.sql.SqlStatement;
06: import static org.junit.Assert.*;
07: import org.junit.Before;
08: import org.junit.Test;
09: import org.w3c.dom.Element;
10:
11: import javax.xml.parsers.DocumentBuilderFactory;
12:
13: /**
14: * Tests for {@link DropTableChange}
15: */
16: public class DropTableChangeTest extends AbstractChangeTest {
17: private DropTableChange change;
18:
19: @Before
20: public void setUp() throws Exception {
21: change = new DropTableChange();
22: change.setSchemaName("SCHEMA_NAME");
23: change.setTableName("TAB_NAME");
24: change.setCascadeConstraints(true);
25: }
26:
27: @Test
28: public void getRefactoringName() throws Exception {
29: assertEquals("Drop Table", change.getChangeName());
30: }
31:
32: @Test
33: public void generateStatement() throws Exception {
34: SqlStatement[] sqlStatements = change
35: .generateStatements(new MockDatabase());
36: assertEquals(1, sqlStatements.length);
37: assertTrue(sqlStatements[0] instanceof DropTableStatement);
38: assertEquals("SCHEMA_NAME",
39: ((DropTableStatement) sqlStatements[0]).getSchemaName());
40: assertEquals("TAB_NAME",
41: ((DropTableStatement) sqlStatements[0]).getTableName());
42: assertTrue(((DropTableStatement) sqlStatements[0])
43: .isCascadeConstraints());
44: }
45:
46: @Test
47: public void generateStatement_nullCascadeConstraints()
48: throws Exception {
49: change.setCascadeConstraints(null);
50: SqlStatement[] sqlStatements = change
51: .generateStatements(new MockDatabase());
52: assertFalse(((DropTableStatement) sqlStatements[0])
53: .isCascadeConstraints());
54: }
55:
56: @Test
57: public void getConfirmationMessage() throws Exception {
58: assertEquals("Table TAB_NAME dropped", change
59: .getConfirmationMessage());
60: }
61:
62: @Test
63: public void createNode() throws Exception {
64: Element element = change.createNode(DocumentBuilderFactory
65: .newInstance().newDocumentBuilder().newDocument());
66: assertEquals("dropTable", element.getTagName());
67: assertEquals("TAB_NAME", element.getAttribute("tableName"));
68: assertEquals("true", element.getAttribute("cascadeConstraints"));
69: }
70:
71: @Test
72: public void createNode_withSchema() throws Exception {
73: Element element = change.createNode(DocumentBuilderFactory
74: .newInstance().newDocumentBuilder().newDocument());
75: assertEquals("dropTable", element.getTagName());
76: assertEquals("TAB_NAME", element.getAttribute("tableName"));
77: assertEquals("true", element.getAttribute("cascadeConstraints"));
78: assertTrue(element.hasAttribute("schemaName"));
79: }
80:
81: @Test
82: public void createNode_nullConstraint() throws Exception {
83: change.setCascadeConstraints(null);
84: Element element = change.createNode(DocumentBuilderFactory
85: .newInstance().newDocumentBuilder().newDocument());
86: assertEquals("dropTable", element.getTagName());
87: assertFalse(element.hasAttribute("cascadeConstraints"));
88: }
89: }
|