01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.DropViewStatement;
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: public class DropViewChangeTest extends AbstractChangeTest {
13:
14: @Test
15: public void getRefactoringName() throws Exception {
16: assertEquals("Drop View", new DropViewChange().getChangeName());
17: }
18:
19: @Test
20: public void generateStatement() throws Exception {
21: DropViewChange change = new DropViewChange();
22: change.setSchemaName("SCHEMA_NAME");
23: change.setViewName("VIEW_NAME");
24:
25: SqlStatement[] sqlStatements = change
26: .generateStatements(new MockDatabase());
27: assertEquals(1, sqlStatements.length);
28: assertTrue(sqlStatements[0] instanceof DropViewStatement);
29: assertEquals("SCHEMA_NAME",
30: ((DropViewStatement) sqlStatements[0]).getSchemaName());
31: assertEquals("VIEW_NAME",
32: ((DropViewStatement) sqlStatements[0]).getViewName());
33: }
34:
35: @Test
36: public void getConfirmationMessage() throws Exception {
37: DropViewChange change = new DropViewChange();
38: change.setViewName("VIEW_NAME");
39:
40: assertEquals("View VIEW_NAME dropped", change
41: .getConfirmationMessage());
42: }
43:
44: @Test
45: public void createNode() throws Exception {
46: DropViewChange change = new DropViewChange();
47: change.setViewName("VIEW_NAME");
48:
49: Element node = change.createNode(DocumentBuilderFactory
50: .newInstance().newDocumentBuilder().newDocument());
51: assertEquals("dropView", node.getTagName());
52: assertFalse(node.hasAttribute("schemaName"));
53: assertEquals("VIEW_NAME", node.getAttribute("viewName"));
54: }
55:
56: @Test
57: public void createNode_withSchema() throws Exception {
58: DropViewChange change = new DropViewChange();
59: change.setSchemaName("SCHEMA_NAME");
60: change.setViewName("VIEW_NAME");
61:
62: Element node = change.createNode(DocumentBuilderFactory
63: .newInstance().newDocumentBuilder().newDocument());
64: assertEquals("dropView", node.getTagName());
65: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
66: assertEquals("VIEW_NAME", node.getAttribute("viewName"));
67: }
68:
69: }
|