01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.CreateViewStatement;
05: import liquibase.database.sql.SqlStatement;
06: import liquibase.test.DatabaseTest;
07: import liquibase.test.DatabaseTestTemplate;
08: import static org.junit.Assert.*;
09: import org.junit.Test;
10: import org.w3c.dom.Element;
11:
12: import javax.xml.parsers.DocumentBuilderFactory;
13:
14: public class CreateViewChangeTest extends AbstractChangeTest {
15:
16: @Test
17: public void getRefactoringName() throws Exception {
18: assertEquals("Create View", new CreateViewChange()
19: .getChangeName());
20: }
21:
22: @Test
23: public void generateStatement() throws Exception {
24:
25: new DatabaseTestTemplate()
26: .testOnAllDatabases(new DatabaseTest() {
27: public void performTest(Database database)
28: throws Exception {
29: CreateViewChange change = new CreateViewChange();
30: change.setSchemaName("SCHEMA_NAME");
31: change.setViewName("VIEW_NAME");
32: change
33: .setSelectQuery("SELECT * FROM EXISTING_TABLE");
34:
35: SqlStatement[] sqlStatements = change
36: .generateStatements(database);
37: assertEquals(1, sqlStatements.length);
38: assertTrue(sqlStatements[0] instanceof CreateViewStatement);
39:
40: assertEquals(
41: "SCHEMA_NAME",
42: ((CreateViewStatement) sqlStatements[0])
43: .getSchemaName());
44: assertEquals(
45: "VIEW_NAME",
46: ((CreateViewStatement) sqlStatements[0])
47: .getViewName());
48: assertEquals(
49: "SELECT * FROM EXISTING_TABLE",
50: ((CreateViewStatement) sqlStatements[0])
51: .getSelectQuery());
52: }
53: });
54: }
55:
56: @Test
57: public void getConfirmationMessage() throws Exception {
58: CreateViewChange change = new CreateViewChange();
59: change.setViewName("VIEW_NAME");
60:
61: assertEquals("View VIEW_NAME created", change
62: .getConfirmationMessage());
63: }
64:
65: @Test
66: public void createNode() throws Exception {
67: CreateViewChange change = new CreateViewChange();
68: change.setSchemaName("SCHEMA_NAME");
69: change.setViewName("VIEW_NAME");
70: change.setSelectQuery("SELECT * FROM EXISTING_TABLE");
71:
72: Element node = change.createNode(DocumentBuilderFactory
73: .newInstance().newDocumentBuilder().newDocument());
74: assertEquals("createView", node.getTagName());
75: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
76: assertEquals("VIEW_NAME", node.getAttribute("viewName"));
77: assertEquals("SELECT * FROM EXISTING_TABLE", node
78: .getTextContent());
79: }
80: }
|