01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.OracleDatabase;
05: import liquibase.database.sql.RawSqlStatement;
06: import liquibase.database.sql.SqlStatement;
07: import liquibase.test.DatabaseTest;
08: import liquibase.test.DatabaseTestTemplate;
09: import static org.junit.Assert.*;
10: import org.junit.Test;
11: import org.w3c.dom.Element;
12:
13: import javax.xml.parsers.DocumentBuilderFactory;
14:
15: public class CreateProcedureChangeTest extends AbstractChangeTest {
16:
17: @Test
18: public void getRefactoringName() throws Exception {
19: assertEquals("Create Procedure", new CreateProcedureChange()
20: .getChangeName());
21: }
22:
23: @Test
24: public void generateStatement() throws Exception {
25: new DatabaseTestTemplate()
26: .testOnAllDatabases(new DatabaseTest() {
27: public void performTest(Database database)
28: throws Exception {
29: CreateProcedureChange change = new CreateProcedureChange();
30: change
31: .setProcedureBody("CREATE PROC PROCBODY HERE");
32: change.setComments("Comments go here");
33:
34: SqlStatement[] sqlStatements = change
35: .generateStatements(database);
36: assertEquals(1, sqlStatements.length);
37: assertTrue(sqlStatements[0] instanceof RawSqlStatement);
38:
39: assertEquals("CREATE PROC PROCBODY HERE",
40: ((RawSqlStatement) sqlStatements[0])
41: .getSqlStatement(database));
42:
43: if (database instanceof OracleDatabase) {
44: assertEquals("\n/", sqlStatements[0]
45: .getEndDelimiter(database));
46: } else {
47: assertEquals(";", sqlStatements[0]
48: .getEndDelimiter(database));
49: }
50: }
51: });
52: }
53:
54: @Test
55: public void getConfirmationMessage() throws Exception {
56: CreateProcedureChange refactoring = new CreateProcedureChange();
57: assertEquals("Stored procedure created", refactoring
58: .getConfirmationMessage());
59: }
60:
61: @Test
62: public void createNode() throws Exception {
63: CreateProcedureChange refactoring = new CreateProcedureChange();
64: refactoring.setProcedureBody("CREATE PROC PROCBODY HERE");
65: refactoring.setComments("Comments go here");
66:
67: Element element = refactoring.createNode(DocumentBuilderFactory
68: .newInstance().newDocumentBuilder().newDocument());
69: assertEquals("createProcedure", element.getTagName());
70: assertEquals("CREATE PROC PROCBODY HERE", element
71: .getTextContent());
72: }
73: }
|