01: package liquibase.change;
02:
03: import liquibase.database.OracleDatabase;
04: import static org.junit.Assert.*;
05: import org.junit.Before;
06: import org.junit.Test;
07: import org.w3c.dom.Document;
08: import org.w3c.dom.Element;
09: import org.w3c.dom.NodeList;
10:
11: import javax.xml.parsers.DocumentBuilderFactory;
12:
13: /**
14: * Tests for {@link ModifyColumnChange}
15: */
16: public class ModifyColumnChangeTest extends AbstractChangeTest {
17:
18: ModifyColumnChange change;
19:
20: @Before
21: public void setUp() throws Exception {
22: change = new ModifyColumnChange();
23: change.setTableName("TABLE_NAME");
24:
25: ColumnConfig col1 = new ColumnConfig();
26: col1.setName("NAME");
27: col1.setType("integer(3)");
28:
29: change.addColumn(col1);
30: }
31:
32: @Test
33: public void getRefactoringName() throws Exception {
34: assertEquals("Modify Column", change.getChangeName());
35: }
36:
37: @Test
38: public void generateStatement() throws Exception {
39: OracleDatabase database = new OracleDatabase();
40: assertEquals("ALTER TABLE TABLE_NAME MODIFY (NAME integer(3))",
41: change.generateStatements(database)[0]
42: .getSqlStatement(database));
43: }
44:
45: @Test
46: public void getConfirmationMessage() throws Exception {
47: assertEquals("Columns NAME(integer(3)) of TABLE_NAME modified",
48: change.getConfirmationMessage());
49: }
50:
51: @Test
52: public void createNode() throws Exception {
53: Document document = DocumentBuilderFactory.newInstance()
54: .newDocumentBuilder().newDocument();
55:
56: Element node = change.createNode(document);
57: assertEquals("modifyColumn", node.getTagName());
58: assertEquals("TABLE_NAME", node.getAttribute("tableName"));
59:
60: NodeList columns = node.getElementsByTagName("column");
61: assertEquals(1, columns.getLength());
62: assertEquals("column", ((Element) columns.item(0)).getTagName());
63: assertEquals("NAME", ((Element) columns.item(0))
64: .getAttribute("name"));
65: assertEquals("integer(3)", ((Element) columns.item(0))
66: .getAttribute("type"));
67: }
68: }
|