01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.SetNullableStatement;
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 DropNotNullConstraintChange}
14: */
15: public class DropNotNullConstraintChangeTest extends AbstractChangeTest {
16:
17: @Test
18: public void getRefactoringName() throws Exception {
19: assertEquals("Drop Not-Null Constraint",
20: new DropNotNullConstraintChange().getChangeName());
21: }
22:
23: @Test
24: public void generateStatement() throws Exception {
25: DropNotNullConstraintChange change = new DropNotNullConstraintChange();
26: change.setSchemaName("SCHEMA_NAME");
27: change.setTableName("TABLE_NAME");
28: change.setColumnName("COL_HERE");
29: change.setColumnDataType("varchar(200)");
30:
31: SqlStatement[] sqlStatements = change
32: .generateStatements(new MockDatabase());
33: assertEquals(1, sqlStatements.length);
34: assertTrue(sqlStatements[0] instanceof SetNullableStatement);
35: assertEquals("SCHEMA_NAME",
36: ((SetNullableStatement) sqlStatements[0])
37: .getSchemaName());
38: assertEquals("TABLE_NAME",
39: ((SetNullableStatement) sqlStatements[0])
40: .getTableName());
41: assertEquals("COL_HERE",
42: ((SetNullableStatement) sqlStatements[0])
43: .getColumnName());
44: assertEquals("varchar(200)",
45: ((SetNullableStatement) sqlStatements[0])
46: .getColumnDataType());
47: assertTrue(((SetNullableStatement) sqlStatements[0])
48: .isNullable());
49: }
50:
51: @Test
52: public void getConfirmationMessage() throws Exception {
53: DropNotNullConstraintChange change = new DropNotNullConstraintChange();
54: change.setTableName("TABLE_NAME");
55: change.setColumnName("COL_HERE");
56: assertEquals(
57: "Null constraint dropped from TABLE_NAME.COL_HERE",
58: change.getConfirmationMessage());
59:
60: }
61:
62: @Test
63: public void createNode() throws Exception {
64: DropNotNullConstraintChange change = new DropNotNullConstraintChange();
65: change.setTableName("TABLE_NAME");
66: change.setColumnName("COL_HERE");
67: Element node = change.createNode(DocumentBuilderFactory
68: .newInstance().newDocumentBuilder().newDocument());
69: assertEquals("dropNotNullConstraint", node.getTagName());
70: assertEquals("TABLE_NAME", node.getAttribute("tableName"));
71: assertEquals("COL_HERE", node.getAttribute("columnName"));
72: }
73: }
|