001: package liquibase.database.sql;
002:
003: import liquibase.database.*;
004: import liquibase.database.structure.DatabaseSnapshot;
005: import liquibase.exception.JDBCException;
006: import liquibase.test.DatabaseTestTemplate;
007: import liquibase.test.SqlStatementDatabaseTest;
008: import liquibase.test.TestContext;
009: import static org.junit.Assert.*;
010: import org.junit.Test;
011:
012: public class AlterSequenceStatementTest extends
013: AbstractSqlStatementTest {
014:
015: private static final String SEQ_NAME = "altertest_seq"
016: .toUpperCase();
017:
018: protected void setupDatabase(Database database) throws Exception {
019: dropAndCreateSequence(new CreateSequenceStatement(null,
020: SEQ_NAME), database);
021: dropAndCreateSequence(new CreateSequenceStatement(
022: TestContext.ALT_SCHEMA, SEQ_NAME), database);
023: }
024:
025: protected SqlStatement generateTestStatement() {
026: return new AlterSequenceStatement(null, null);
027: }
028:
029: @Test
030: public void supportsDatabase() throws Exception {
031: for (Database database : TestContext.getInstance()
032: .getAllDatabases()) {
033: if (database.supportsSequences()) {
034: assertTrue(generateTestStatement().supportsDatabase(
035: database));
036: } else {
037: assertFalse(generateTestStatement().supportsDatabase(
038: database));
039: }
040: }
041: }
042:
043: @Test
044: public void execute_incrementBy() throws Exception {
045: new DatabaseTestTemplate()
046: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
047: null,
048: new AlterSequenceStatement(null, SEQ_NAME)
049: .setIncrementBy(5)) {
050: protected boolean expectedException(
051: Database database, JDBCException exception) {
052: return database instanceof FirebirdDatabase
053: || database instanceof HsqlDatabase;
054: }
055:
056: protected void preExecuteAssert(
057: DatabaseSnapshot snapshot) {
058: assertNotNull(snapshot.getSequence(SEQ_NAME));
059: //todo: assert increment by is 1
060: }
061:
062: protected void postExecuteAssert(
063: DatabaseSnapshot snapshot) {
064: assertNotNull(snapshot.getSequence(SEQ_NAME));
065: //todo: assert increment by value
066: }
067: });
068: }
069:
070: @Test
071: public void execute_minValue() throws Exception {
072: new DatabaseTestTemplate()
073: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
074: null,
075: new AlterSequenceStatement(null, SEQ_NAME)
076: .setMinValue(0)) {
077: protected void preExecuteAssert(
078: DatabaseSnapshot snapshot) {
079: assertNotNull(snapshot.getSequence(SEQ_NAME));
080: //todo; assert minValue is 1
081: }
082:
083: protected void postExecuteAssert(
084: DatabaseSnapshot snapshot) {
085: assertNotNull(snapshot.getSequence(SEQ_NAME));
086: //todo: assert min valuevalue
087: }
088: });
089: }
090:
091: @Test
092: public void execute_maxValue() throws Exception {
093: new DatabaseTestTemplate()
094: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
095: null,
096: new AlterSequenceStatement(null, SEQ_NAME)
097: .setMaxValue(50)) {
098:
099: protected boolean expectedException(
100: Database database, JDBCException exception) {
101: return database instanceof FirebirdDatabase
102: || database instanceof HsqlDatabase;
103: }
104:
105: protected void preExecuteAssert(
106: DatabaseSnapshot snapshot) {
107: assertNotNull(snapshot.getSequence(SEQ_NAME));
108: //todo: assert initial max value
109: }
110:
111: protected void postExecuteAssert(
112: DatabaseSnapshot snapshot) {
113: assertNotNull(snapshot.getSequence(SEQ_NAME));
114: //todo: assert max value
115: }
116: });
117: }
118:
119: @Test
120: public void execute_order() throws Exception {
121: new DatabaseTestTemplate()
122: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
123: null,
124: new AlterSequenceStatement(null, SEQ_NAME)
125: .setOrdered(true)) {
126:
127: protected boolean expectedException(
128: Database database, JDBCException exception) {
129: return !(database instanceof OracleDatabase || database instanceof DB2Database);
130: }
131:
132: protected void preExecuteAssert(
133: DatabaseSnapshot snapshot) {
134: assertNotNull(snapshot.getSequence(SEQ_NAME));
135: //todo: assert order default
136: }
137:
138: protected void postExecuteAssert(
139: DatabaseSnapshot snapshot) {
140: assertNotNull(snapshot.getSequence(SEQ_NAME));
141: //todo: assert max value
142: }
143: });
144: }
145:
146: @Test
147: public void execute_schemaSet() throws Exception {
148: new DatabaseTestTemplate()
149: .testOnAvailableDatabases(new SqlStatementDatabaseTest(
150: TestContext.ALT_SCHEMA,
151: new AlterSequenceStatement(
152: TestContext.ALT_SCHEMA, SEQ_NAME)
153: .setIncrementBy(5)) {
154: protected boolean expectedException(
155: Database database, JDBCException exception) {
156: return database instanceof FirebirdDatabase
157: || database instanceof HsqlDatabase;
158: }
159:
160: protected void preExecuteAssert(
161: DatabaseSnapshot snapshot) {
162: assertNotNull(snapshot.getSequence(SEQ_NAME));
163: //todo: assert increment by is 1
164: }
165:
166: protected void postExecuteAssert(
167: DatabaseSnapshot snapshot) {
168: assertNotNull(snapshot.getSequence(SEQ_NAME));
169: //todo: assert increment by value
170: }
171: });
172: }
173:
174: }
|