01: package liquibase.change;
02:
03: import liquibase.database.MockDatabase;
04: import liquibase.database.sql.AlterSequenceStatement;
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 AlterSequenceChange}
14: */
15: public class AlterSequenceChangeTest extends AbstractChangeTest {
16:
17: @Test
18: public void getRefactoringName() throws Exception {
19: assertEquals("Alter Sequence", new AlterSequenceChange()
20: .getChangeName());
21: }
22:
23: @Test
24: public void generateStatement() throws Exception {
25: AlterSequenceChange refactoring = new AlterSequenceChange();
26: refactoring.setSchemaName("SCHEMA_NAME");
27: refactoring.setSequenceName("SEQ_NAME");
28: refactoring.setMinValue(100);
29: refactoring.setMaxValue(1000);
30: refactoring.setIncrementBy(50);
31: refactoring.setOrdered(true);
32:
33: SqlStatement[] sqlStatements = refactoring
34: .generateStatements(new MockDatabase());
35:
36: assertEquals(1, sqlStatements.length);
37: assertTrue(sqlStatements[0] instanceof AlterSequenceStatement);
38: assertEquals("SCHEMA_NAME",
39: ((AlterSequenceStatement) sqlStatements[0])
40: .getSchemaName());
41: assertEquals("SEQ_NAME",
42: ((AlterSequenceStatement) sqlStatements[0])
43: .getSequenceName());
44: assertEquals(100, ((AlterSequenceStatement) sqlStatements[0])
45: .getMinValue());
46: assertEquals(1000, ((AlterSequenceStatement) sqlStatements[0])
47: .getMaxValue());
48: assertEquals(50, ((AlterSequenceStatement) sqlStatements[0])
49: .getIncrementBy());
50: assertEquals(true, ((AlterSequenceStatement) sqlStatements[0])
51: .getOrdered());
52:
53: }
54:
55: @Test
56: public void getConfirmationMessage() throws Exception {
57: AlterSequenceChange refactoring = new AlterSequenceChange();
58: refactoring.setSequenceName("SEQ_NAME");
59:
60: assertEquals("Sequence SEQ_NAME altered", refactoring
61: .getConfirmationMessage());
62: }
63:
64: @Test
65: public void createNode_nullValues() throws Exception {
66: AlterSequenceChange refactoring = new AlterSequenceChange();
67: refactoring.setSequenceName("SEQ_NAME");
68:
69: Element node = refactoring.createNode(DocumentBuilderFactory
70: .newInstance().newDocumentBuilder().newDocument());
71: assertEquals("alterSequence", node.getNodeName());
72: assertEquals("SEQ_NAME", node.getAttribute("sequenceName"));
73: assertFalse(node.hasAttribute("incrementBy"));
74: assertFalse(node.hasAttribute("maxValue"));
75: assertFalse(node.hasAttribute("minValue"));
76: assertFalse(node.hasAttribute("ordered"));
77: }
78:
79: @Test
80: public void createNode() throws Exception {
81: AlterSequenceChange refactoring = new AlterSequenceChange();
82: refactoring.setSchemaName("SCHEMA_NAME");
83: refactoring.setSequenceName("SEQ_NAME");
84: refactoring.setIncrementBy(1);
85: refactoring.setMaxValue(2);
86: refactoring.setMinValue(3);
87: refactoring.setOrdered(true);
88:
89: Element node = refactoring.createNode(DocumentBuilderFactory
90: .newInstance().newDocumentBuilder().newDocument());
91: assertEquals("alterSequence", node.getNodeName());
92: assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
93: assertEquals("SEQ_NAME", node.getAttribute("sequenceName"));
94: assertEquals("1", node.getAttribute("incrementBy"));
95: assertEquals("2", node.getAttribute("maxValue"));
96: assertEquals("3", node.getAttribute("minValue"));
97: assertEquals("true", node.getAttribute("ordered"));
98: }
99: }
|