01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropSequenceStatement;
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.Before;
10: import org.junit.Test;
11: import org.w3c.dom.Element;
12:
13: import javax.xml.parsers.DocumentBuilderFactory;
14:
15: /**
16: * Tests for {@link DropSequenceChange}
17: */
18: public class DropSequenceChangeTest extends AbstractChangeTest {
19:
20: private DropSequenceChange change;
21:
22: @Before
23: public void setUp() throws Exception {
24: change = new DropSequenceChange();
25: change.setSequenceName("SEQ_NAME");
26: }
27:
28: @Test
29: public void getRefactoringName() throws Exception {
30: assertEquals("Drop Sequence", new DropSequenceChange()
31: .getChangeName());
32: }
33:
34: @Test
35: public void generateStatement() throws Exception {
36:
37: new DatabaseTestTemplate()
38: .testOnAllDatabases(new DatabaseTest() {
39: public void performTest(Database database)
40: throws Exception {
41: if (!database.supportsSequences()) {
42: return;
43: }
44:
45: DropSequenceChange change = new DropSequenceChange();
46: change.setSchemaName("SCHEMA_NAME");
47: change.setSequenceName("SEQ_NAME");
48:
49: SqlStatement[] sqlStatements = change
50: .generateStatements(database);
51: assertEquals(1, sqlStatements.length);
52: assertTrue(sqlStatements[0] instanceof DropSequenceStatement);
53:
54: assertEquals(
55: "SCHEMA_NAME",
56: ((DropSequenceStatement) sqlStatements[0])
57: .getSchemaName());
58: assertEquals(
59: "SEQ_NAME",
60: ((DropSequenceStatement) sqlStatements[0])
61: .getSequenceName());
62:
63: }
64: });
65: }
66:
67: @Test
68: public void getConfirmationMessage() throws Exception {
69: assertEquals("Sequence SEQ_NAME dropped", change
70: .getConfirmationMessage());
71: }
72:
73: @Test
74: public void createNode() throws Exception {
75: Element element = change.createNode(DocumentBuilderFactory
76: .newInstance().newDocumentBuilder().newDocument());
77:
78: assertEquals("dropSequence", element.getTagName());
79: assertEquals("SEQ_NAME", element.getAttribute("sequenceName"));
80: }
81: }
|