01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.DropIndexStatement;
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: /**
13: * Tests for {@link DropIndexChange}
14: */
15: public class DropIndexChangeTest extends AbstractChangeTest {
16:
17: @Test
18: public void getRefactoringName() throws Exception {
19: assertEquals("Drop Index", new DropIndexChange()
20: .getChangeName());
21: }
22:
23: @Test
24: public void generateStatement() throws Exception {
25: DropIndexChange refactoring = new DropIndexChange();
26: refactoring.setIndexName("IDX_NAME");
27: refactoring.setTableName("TABLE_NAME");
28: refactoring.setSchemaName("SCHEMA_NAME");
29:
30: SqlStatement[] sqlStatements = refactoring
31: .generateStatements(new MockDatabase());
32: assertEquals(1, sqlStatements.length);
33: assertTrue(sqlStatements[0] instanceof DropIndexStatement);
34: assertEquals("SCHEMA_NAME",
35: ((DropIndexStatement) sqlStatements[0])
36: .getTableSchemaName());
37: assertEquals("TABLE_NAME",
38: ((DropIndexStatement) sqlStatements[0]).getTableName());
39: assertEquals("IDX_NAME",
40: ((DropIndexStatement) sqlStatements[0]).getIndexName());
41: }
42:
43: @Test
44: public void getConfirmationMessage() throws Exception {
45: DropIndexChange refactoring = new DropIndexChange();
46: refactoring.setIndexName("IDX_NAME");
47: refactoring.setTableName("TABLE_NAME");
48:
49: assertEquals("Index IDX_NAME dropped from table TABLE_NAME",
50: refactoring.getConfirmationMessage());
51: }
52:
53: @Test
54: public void createNode() throws Exception {
55: DropIndexChange refactoring = new DropIndexChange();
56: refactoring.setIndexName("IDX_NAME");
57: Element element = refactoring.createNode(DocumentBuilderFactory
58: .newInstance().newDocumentBuilder().newDocument());
59:
60: assertEquals("dropIndex", element.getTagName());
61: assertEquals("IDX_NAME", element.getAttribute("indexName"));
62: }
63: }
|