01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropForeignKeyConstraintStatement;
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 DropForeignKeyConstraintChangeTest extends
15: AbstractChangeTest {
16: @Test
17: public void getRefactoringName() throws Exception {
18: assertEquals("Drop Foreign Key Constraint",
19: new DropForeignKeyConstraintChange().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: DropForeignKeyConstraintChange change = new DropForeignKeyConstraintChange();
30: change.setBaseTableSchemaName("SCHEMA_NAME");
31: change.setBaseTableName("TABLE_NAME");
32: change.setConstraintName("FK_NAME");
33:
34: SqlStatement[] sqlStatements = change
35: .generateStatements(database);
36: assertEquals(1, sqlStatements.length);
37: assertTrue(sqlStatements[0] instanceof DropForeignKeyConstraintStatement);
38:
39: assertEquals(
40: "SCHEMA_NAME",
41: ((DropForeignKeyConstraintStatement) sqlStatements[0])
42: .getBaseTableSchemaName());
43: assertEquals(
44: "TABLE_NAME",
45: ((DropForeignKeyConstraintStatement) sqlStatements[0])
46: .getBaseTableName());
47: assertEquals(
48: "FK_NAME",
49: ((DropForeignKeyConstraintStatement) sqlStatements[0])
50: .getConstraintName());
51: }
52: });
53: }
54:
55: @Test
56: public void getConfirmationMessage() throws Exception {
57: DropForeignKeyConstraintChange change = new DropForeignKeyConstraintChange();
58: change.setBaseTableSchemaName("SCHEMA_NAME");
59: change.setBaseTableName("TABLE_NAME");
60: change.setConstraintName("FK_NAME");
61:
62: assertEquals("Foreign key FK_NAME dropped", change
63: .getConfirmationMessage());
64: }
65:
66: @Test
67: public void createNode() throws Exception {
68: DropForeignKeyConstraintChange change = new DropForeignKeyConstraintChange();
69: change.setBaseTableSchemaName("SCHEMA_NAME");
70: change.setBaseTableName("TABLE_NAME");
71: change.setConstraintName("FK_NAME");
72:
73: Element node = change.createNode(DocumentBuilderFactory
74: .newInstance().newDocumentBuilder().newDocument());
75: assertEquals("dropForeignKeyConstraint", node.getTagName());
76: assertEquals("SCHEMA_NAME", node
77: .getAttribute("baseTableSchemaName"));
78: assertEquals("TABLE_NAME", node.getAttribute("baseTableName"));
79: assertEquals("FK_NAME", node.getAttribute("constraintName"));
80: }
81: }
|