001: package liquibase.change;
002:
003: import liquibase.database.Database;
004: import liquibase.database.sql.CreateSequenceStatement;
005: import liquibase.database.sql.SqlStatement;
006: import liquibase.test.DatabaseTest;
007: import liquibase.test.DatabaseTestTemplate;
008: import static org.junit.Assert.*;
009: import org.junit.Test;
010: import org.w3c.dom.Element;
011:
012: import javax.xml.parsers.DocumentBuilderFactory;
013:
014: /**
015: * Tests for {@link CreateSequenceChange}
016: */
017: public class CreateSequenceChangeTest extends AbstractChangeTest {
018:
019: @Test
020: public void getRefactoringName() throws Exception {
021: assertEquals("Create Sequence", new CreateSequenceChange()
022: .getChangeName());
023: }
024:
025: @Test
026: public void generateStatement() throws Exception {
027: new DatabaseTestTemplate()
028: .testOnAllDatabases(new DatabaseTest() {
029: public void performTest(Database database)
030: throws Exception {
031: if (!database.supportsSequences()) {
032: return;
033: }
034:
035: CreateSequenceChange change = new CreateSequenceChange();
036: change.setSchemaName("SCHEMA_NAME");
037: change.setSequenceName("SEQ_NAME");
038: change.setIncrementBy(1);
039: change.setMinValue(2);
040: change.setMaxValue(3);
041: change.setOrdered(true);
042: change.setStartValue(4);
043:
044: SqlStatement[] sqlStatements = change
045: .generateStatements(database);
046: assertEquals(1, sqlStatements.length);
047: assertTrue(sqlStatements[0] instanceof CreateSequenceStatement);
048:
049: assertEquals(
050: "SCHEMA_NAME",
051: ((CreateSequenceStatement) sqlStatements[0])
052: .getSchemaName());
053: assertEquals(
054: "SEQ_NAME",
055: ((CreateSequenceStatement) sqlStatements[0])
056: .getSequenceName());
057: assertEquals(
058: 1,
059: ((CreateSequenceStatement) sqlStatements[0])
060: .getIncrementBy());
061: assertEquals(
062: 2,
063: ((CreateSequenceStatement) sqlStatements[0])
064: .getMinValue());
065: assertEquals(
066: 3,
067: ((CreateSequenceStatement) sqlStatements[0])
068: .getMaxValue());
069: assertEquals(
070: 4,
071: ((CreateSequenceStatement) sqlStatements[0])
072: .getStartValue());
073: assertEquals(
074: true,
075: ((CreateSequenceStatement) sqlStatements[0])
076: .getOrdered());
077: }
078: });
079: }
080:
081: @Test
082: public void getConfirmationMessage() throws Exception {
083: CreateSequenceChange change = new CreateSequenceChange();
084: change.setSequenceName("SEQ_NAME");
085:
086: assertEquals("Sequence SEQ_NAME created", change
087: .getConfirmationMessage());
088: }
089:
090: @Test
091: public void createNode() throws Exception {
092: CreateSequenceChange change = new CreateSequenceChange();
093: change.setSequenceName("SEQ_NAME");
094:
095: Element node = change.createNode(DocumentBuilderFactory
096: .newInstance().newDocumentBuilder().newDocument());
097: assertEquals("createSequence", node.getNodeName());
098: assertEquals("SEQ_NAME", node.getAttribute("sequenceName"));
099: assertFalse(node.hasAttribute("incrementBy"));
100: assertFalse(node.hasAttribute("maxValue"));
101: assertFalse(node.hasAttribute("minValue"));
102: assertFalse(node.hasAttribute("ordered"));
103: assertFalse(node.hasAttribute("startValue"));
104:
105: change.setIncrementBy(1);
106: change.setMaxValue(2);
107: change.setMinValue(3);
108: change.setOrdered(true);
109: change.setStartValue(4);
110:
111: node = change.createNode(DocumentBuilderFactory.newInstance()
112: .newDocumentBuilder().newDocument());
113: assertEquals("createSequence", node.getNodeName());
114: assertEquals("SEQ_NAME", node.getAttribute("sequenceName"));
115: assertEquals("1", node.getAttribute("incrementBy"));
116: assertEquals("2", node.getAttribute("maxValue"));
117: assertEquals("3", node.getAttribute("minValue"));
118: assertEquals("true", node.getAttribute("ordered"));
119: assertEquals("4", node.getAttribute("startValue"));
120: }
121: }
|