01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.DropUniqueConstraintStatement;
05: import liquibase.database.sql.SqlStatement;
06: import static org.junit.Assert.*;
07: import org.junit.Before;
08: import org.junit.Test;
09: import org.w3c.dom.Element;
10:
11: import javax.xml.parsers.DocumentBuilderFactory;
12:
13: public class DropUniqueConstraintChangeTest extends AbstractChangeTest {
14: private DropUniqueConstraintChange change;
15:
16: @Before
17: public void setUp() throws Exception {
18: change = new DropUniqueConstraintChange();
19: change.setSchemaName("SCHEMA_NAME");
20: change.setTableName("TAB_NAME");
21: change.setConstraintName("UQ_CONSTRAINT");
22: }
23:
24: @Test
25: public void getRefactoringName() throws Exception {
26: assertEquals("Drop Unique Constraint", change.getChangeName());
27: }
28:
29: @Test
30: public void generateStatement() throws Exception {
31: SqlStatement[] sqlStatements = change
32: .generateStatements(new MockDatabase());
33: assertEquals(1, sqlStatements.length);
34: assertTrue(sqlStatements[0] instanceof DropUniqueConstraintStatement);
35: assertEquals("SCHEMA_NAME",
36: ((DropUniqueConstraintStatement) sqlStatements[0])
37: .getSchemaName());
38: assertEquals("TAB_NAME",
39: ((DropUniqueConstraintStatement) sqlStatements[0])
40: .getTableName());
41: assertEquals("UQ_CONSTRAINT",
42: ((DropUniqueConstraintStatement) sqlStatements[0])
43: .getConstraintName());
44: }
45:
46: @Test
47: public void getConfirmationMessage() throws Exception {
48: assertEquals(
49: "Unique constraint UQ_CONSTRAINT dropped from TAB_NAME",
50: change.getConfirmationMessage());
51: }
52:
53: @Test
54: public void createNode() throws Exception {
55: Element element = change.createNode(DocumentBuilderFactory
56: .newInstance().newDocumentBuilder().newDocument());
57: assertEquals("dropUniqueConstraint", element.getTagName());
58: assertEquals("SCHEMA_NAME", element.getAttribute("schemaName"));
59: assertEquals("TAB_NAME", element.getAttribute("tableName"));
60: assertEquals("UQ_CONSTRAINT", element
61: .getAttribute("constraintName"));
62: }
63:
64: @Test
65: public void createNode_noSchema() throws Exception {
66: change.setSchemaName(null);
67:
68: Element element = change.createNode(DocumentBuilderFactory
69: .newInstance().newDocumentBuilder().newDocument());
70: assertEquals("dropUniqueConstraint", element.getTagName());
71: assertEquals("TAB_NAME", element.getAttribute("tableName"));
72: assertEquals("UQ_CONSTRAINT", element
73: .getAttribute("constraintName"));
74: assertFalse(element.hasAttribute("schemaName"));
75: }
76: }
|