01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.RenameColumnStatement;
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.Document;
10: import org.w3c.dom.Element;
11:
12: import javax.xml.parsers.DocumentBuilderFactory;
13:
14: /**
15: * Tests for {@link RenameColumnChange}
16: */
17: public class RenameColumnChangeTest extends AbstractChangeTest {
18:
19: RenameColumnChange refactoring;
20:
21: @Before
22: public void setUp() throws Exception {
23: refactoring = new RenameColumnChange();
24:
25: refactoring.setSchemaName("SCHEMA_NAME");
26: refactoring.setTableName("TABLE_NAME");
27: refactoring.setOldColumnName("oldColName");
28: refactoring.setNewColumnName("newColName");
29: }
30:
31: @Test
32: public void getRefactoringName() throws Exception {
33: assertEquals("Rename Column", refactoring.getChangeName());
34: }
35:
36: @Test
37: public void generateStatement() throws Exception {
38: SqlStatement[] sqlStatements = refactoring
39: .generateStatements(new MockDatabase());
40: assertEquals(1, sqlStatements.length);
41: assertTrue(sqlStatements[0] instanceof RenameColumnStatement);
42: assertEquals("SCHEMA_NAME",
43: ((RenameColumnStatement) sqlStatements[0])
44: .getSchemaName());
45: assertEquals("TABLE_NAME",
46: ((RenameColumnStatement) sqlStatements[0])
47: .getTableName());
48: assertEquals("oldColName",
49: ((RenameColumnStatement) sqlStatements[0])
50: .getOldColumnName());
51: assertEquals("newColName",
52: ((RenameColumnStatement) sqlStatements[0])
53: .getNewColumnName());
54: }
55:
56: @Test
57: public void getConfirmationMessage() throws Exception {
58: assertEquals(
59: "Column TABLE_NAME.oldColName renamed to newColName",
60: refactoring.getConfirmationMessage());
61: }
62:
63: @Test
64: public void createNode() throws Exception {
65: Document document = DocumentBuilderFactory.newInstance()
66: .newDocumentBuilder().newDocument();
67:
68: Element node = refactoring.createNode(document);
69: assertEquals("renameColumn", node.getTagName());
70: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
71: assertEquals("TABLE_NAME", node.getAttribute("tableName"));
72: assertEquals("oldColName", node.getAttribute("oldColumnName"));
73: assertEquals("newColName", node.getAttribute("newColumnName"));
74: }
75: }
|