01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.DropPrimaryKeyStatement;
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: public class DropPrimaryKeyChangeTest extends AbstractChangeTest {
13: @Test
14: public void getRefactoringName() throws Exception {
15: assertEquals("Drop Primary Key", new DropPrimaryKeyChange()
16: .getChangeName());
17: }
18:
19: @Test
20: public void generateStatement() throws Exception {
21: DropPrimaryKeyChange change = new DropPrimaryKeyChange();
22: change.setSchemaName("SCHEMA_NAME");
23: change.setTableName("TABLE_NAME");
24: change.setConstraintName("PK_NAME");
25:
26: SqlStatement[] sqlStatements = change
27: .generateStatements(new MockDatabase());
28: assertEquals(1, sqlStatements.length);
29: assertTrue(sqlStatements[0] instanceof DropPrimaryKeyStatement);
30: assertEquals("SCHEMA_NAME",
31: ((DropPrimaryKeyStatement) sqlStatements[0])
32: .getSchemaName());
33: assertEquals("TABLE_NAME",
34: ((DropPrimaryKeyStatement) sqlStatements[0])
35: .getTableName());
36: assertEquals("PK_NAME",
37: ((DropPrimaryKeyStatement) sqlStatements[0])
38: .getConstraintName());
39: }
40:
41: @Test
42: public void getConfirmationMessage() throws Exception {
43: DropPrimaryKeyChange change = new DropPrimaryKeyChange();
44: change.setSchemaName("SCHEMA_NAME");
45: change.setTableName("TABLE_NAME");
46: change.setConstraintName("PK_NAME");
47: assertEquals("Primary key dropped from TABLE_NAME", change
48: .getConfirmationMessage());
49:
50: }
51:
52: @Test
53: public void createNode() throws Exception {
54: DropPrimaryKeyChange change = new DropPrimaryKeyChange();
55: change.setSchemaName("SCHEMA_NAME");
56: change.setTableName("TABLE_NAME");
57: change.setConstraintName("PK_NAME");
58: Element node = change.createNode(DocumentBuilderFactory
59: .newInstance().newDocumentBuilder().newDocument());
60: assertEquals("dropPrimaryKey", node.getTagName());
61: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
62: assertEquals("TABLE_NAME", node.getAttribute("tableName"));
63: assertEquals("PK_NAME", node.getAttribute("constraintName"));
64: }
65: }
|