01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.RenameTableStatement;
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.Element;
10:
11: import javax.xml.parsers.DocumentBuilderFactory;
12:
13: /**
14: * Tests for {@link RenameTableChange}
15: */
16: public class RenameTableChangeTest extends AbstractChangeTest {
17:
18: private RenameTableChange refactoring;
19:
20: @Before
21: public void setUp() throws Exception {
22: refactoring = new RenameTableChange();
23: }
24:
25: @Test
26: public void getRefactoringName() throws Exception {
27: assertEquals("Rename Table", refactoring.getChangeName());
28: }
29:
30: @Test
31: public void generateStatement() throws Exception {
32: RenameTableChange refactoring = new RenameTableChange();
33: refactoring.setSchemaName("SCHEMA_NAME");
34: refactoring.setOldTableName("OLD_NAME");
35: refactoring.setNewTableName("NEW_NAME");
36:
37: SqlStatement[] sqlStatements = refactoring
38: .generateStatements(new MockDatabase());
39: assertEquals(1, sqlStatements.length);
40: assertTrue(sqlStatements[0] instanceof RenameTableStatement);
41: assertEquals("SCHEMA_NAME",
42: ((RenameTableStatement) sqlStatements[0])
43: .getSchemaName());
44: assertEquals("OLD_NAME",
45: ((RenameTableStatement) sqlStatements[0])
46: .getOldTableName());
47: assertEquals("NEW_NAME",
48: ((RenameTableStatement) sqlStatements[0])
49: .getNewTableName());
50: }
51:
52: @Test
53: public void getConfirmationMessage() throws Exception {
54: refactoring.setOldTableName("OLD_NAME");
55: refactoring.setNewTableName("NEW_NAME");
56:
57: assertEquals("Table OLD_NAME renamed to NEW_NAME", refactoring
58: .getConfirmationMessage());
59: }
60:
61: @Test
62: public void createNode() throws Exception {
63: refactoring.setSchemaName("SCHEMA_NAME");
64: refactoring.setOldTableName("OLD_NAME");
65: refactoring.setNewTableName("NEW_NAME");
66:
67: Element node = refactoring.createNode(DocumentBuilderFactory
68: .newInstance().newDocumentBuilder().newDocument());
69: assertEquals("renameTable", node.getTagName());
70: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
71: assertEquals("OLD_NAME", node.getAttribute("oldTableName"));
72: assertEquals("NEW_NAME", node.getAttribute("newTableName"));
73: }
74: }
|