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