01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.DropDefaultValueStatement;
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: public class DropDefaultValueChangeTest extends AbstractChangeTest {
13:
14: @Test
15: public void getRefactoringName() throws Exception {
16: assertEquals("Drop Default Value", new DropDefaultValueChange()
17: .getChangeName());
18: }
19:
20: @Test
21: public void generateStatement() throws Exception {
22: DropDefaultValueChange change = new DropDefaultValueChange();
23: change.setSchemaName("SCHEMA_NAME");
24: change.setTableName("TABLE_NAME");
25: change.setColumnName("COL_HERE");
26:
27: SqlStatement[] sqlStatements = change
28: .generateStatements(new MockDatabase());
29: assertEquals(1, sqlStatements.length);
30: assertTrue(sqlStatements[0] instanceof DropDefaultValueStatement);
31: assertEquals("SCHEMA_NAME",
32: ((DropDefaultValueStatement) sqlStatements[0])
33: .getSchemaName());
34: assertEquals("TABLE_NAME",
35: ((DropDefaultValueStatement) sqlStatements[0])
36: .getTableName());
37: assertEquals("COL_HERE",
38: ((DropDefaultValueStatement) sqlStatements[0])
39: .getColumnName());
40: }
41:
42: @Test
43: public void getConfirmationMessage() throws Exception {
44: DropDefaultValueChange change = new DropDefaultValueChange();
45: change.setTableName("TABLE_NAME");
46: change.setColumnName("COL_HERE");
47:
48: assertEquals("Default value dropped from TABLE_NAME.COL_HERE",
49: change.getConfirmationMessage());
50: }
51:
52: @Test
53: public void createNode() throws Exception {
54: DropDefaultValueChange change = new DropDefaultValueChange();
55: change.setTableName("TABLE_NAME");
56: change.setColumnName("COL_NAME");
57:
58: Element node = change.createNode(DocumentBuilderFactory
59: .newInstance().newDocumentBuilder().newDocument());
60: assertEquals("dropDefaultValue", node.getTagName());
61: assertFalse(node.hasAttribute("schemaName"));
62: assertEquals("TABLE_NAME", node.getAttribute("tableName"));
63: assertEquals("COL_NAME", node.getAttribute("columnName"));
64: }
65:
66: @Test
67: public void createNode_withSchema() throws Exception {
68: DropDefaultValueChange change = new DropDefaultValueChange();
69: change.setSchemaName("SCHEMA_NAME");
70: change.setTableName("TABLE_NAME");
71: change.setColumnName("COL_NAME");
72:
73: Element node = change.createNode(DocumentBuilderFactory
74: .newInstance().newDocumentBuilder().newDocument());
75: assertEquals("dropDefaultValue", node.getTagName());
76: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
77: assertEquals("TABLE_NAME", node.getAttribute("tableName"));
78: assertEquals("COL_NAME", node.getAttribute("columnName"));
79: }
80:
81: }
|