01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.RenameViewStatement;
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: public class RenameViewChangeTest extends AbstractChangeTest {
14:
15: private RenameViewChange refactoring;
16:
17: @Before
18: public void setUp() throws Exception {
19: refactoring = new RenameViewChange();
20: }
21:
22: @Test
23: public void getRefactoringName() throws Exception {
24: assertEquals("Rename View", refactoring.getChangeName());
25: }
26:
27: @Test
28: public void generateStatement() throws Exception {
29: RenameViewChange refactoring = new RenameViewChange();
30: refactoring.setSchemaName("SCHEMA_NAME");
31: refactoring.setOldViewName("OLD_NAME");
32: refactoring.setNewViewName("NEW_NAME");
33:
34: SqlStatement[] sqlStatements = refactoring
35: .generateStatements(new MockDatabase());
36: assertEquals(1, sqlStatements.length);
37: assertTrue(sqlStatements[0] instanceof RenameViewStatement);
38: assertEquals("SCHEMA_NAME",
39: ((RenameViewStatement) sqlStatements[0])
40: .getSchemaName());
41: assertEquals("OLD_NAME",
42: ((RenameViewStatement) sqlStatements[0])
43: .getOldViewName());
44: assertEquals("NEW_NAME",
45: ((RenameViewStatement) sqlStatements[0])
46: .getNewViewName());
47: }
48:
49: @Test
50: public void getConfirmationMessage() throws Exception {
51: refactoring.setOldViewName("OLD_NAME");
52: refactoring.setNewViewName("NEW_NAME");
53:
54: assertEquals("View OLD_NAME renamed to NEW_NAME", refactoring
55: .getConfirmationMessage());
56: }
57:
58: @Test
59: public void createNode() throws Exception {
60: refactoring.setSchemaName("SCHEMA_NAME");
61: refactoring.setOldViewName("OLD_NAME");
62: refactoring.setNewViewName("NEW_NAME");
63:
64: Element node = refactoring.createNode(DocumentBuilderFactory
65: .newInstance().newDocumentBuilder().newDocument());
66: assertEquals("renameView", node.getTagName());
67: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
68: assertEquals("OLD_NAME", node.getAttribute("oldViewName"));
69: assertEquals("NEW_NAME", node.getAttribute("newViewName"));
70: }
71: }
|