Search in sources :

Example 1 with AlterSequenceStatement

use of liquibase.statement.core.AlterSequenceStatement in project liquibase by liquibase.

the class AlterSequenceGeneratorTest method testAlterSequenceCycleDatabase.

// @Test
// public void h2DatabaseSupportsSequenceMaxValue() throws Exception {
// 
// H2Database h2Database = new H2Database();
// h2Database.setConnection(mockedSupportedMinMaxSequenceConnection);
// 
// AlterSequenceStatement alterSequenceStatement = createSampleSqlStatement();
// alterSequenceStatement.setMaxValue(new BigInteger("1000"));
// 
// assertFalse(generatorUnderTest.validate(alterSequenceStatement, h2Database, new MockSqlGeneratorChain()).hasErrors());
// }
// @Test
// public void h2DatabaseDoesNotSupportsSequenceMaxValue() throws Exception {
// 
// H2Database h2Database = new H2Database();
// h2Database.setConnection(mockedUnsupportedMinMaxSequenceConnection);
// 
// AlterSequenceStatement alterSequenceStatement = createSampleSqlStatement();
// alterSequenceStatement.setMaxValue(new BigInteger("1000"));
// 
// assertTrue(generatorUnderTest.validate(alterSequenceStatement, h2Database, new MockSqlGeneratorChain()).hasErrors());
// }
// @Test
// public void h2DatabaseSupportsSequenceMinValue() throws Exception {
// 
// H2Database h2Database = new H2Database();
// h2Database.setConnection(mockedSupportedMinMaxSequenceConnection);
// 
// AlterSequenceStatement alterSequenceStatement = createSampleSqlStatement();
// alterSequenceStatement.setMinValue(new BigInteger("10"));
// 
// assertFalse(generatorUnderTest.validate(alterSequenceStatement, h2Database, new MockSqlGeneratorChain()).hasErrors());
// }
// 
// @Test
// public void h2DatabaseDoesNotSupportsSequenceMinValue() throws Exception {
// 
// H2Database h2Database = new H2Database();
// h2Database.setConnection(mockedUnsupportedMinMaxSequenceConnection);
// 
// AlterSequenceStatement alterSequenceStatement = createSampleSqlStatement();
// alterSequenceStatement.setMinValue(new BigInteger("10"));
// 
// assertTrue(generatorUnderTest.validate(alterSequenceStatement, h2Database, new MockSqlGeneratorChain()).hasErrors());
// }
@Test
public void testAlterSequenceCycleDatabase() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        AlterSequenceStatement statement = createSampleSqlStatement();
        statement.setCycle(false);
        Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
        if (database instanceof OracleDatabase) {
            assertEquals("ALTER SEQUENCE CATALOG_NAME.SEQUENCE_NAME NOCYCLE", generatedSql[0].toSql());
        } else if (database instanceof PostgresDatabase || database instanceof CockroachDatabase) {
            assertEquals("ALTER SEQUENCE SCHEMA_NAME.SEQUENCE_NAME NO CYCLE", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) CockroachDatabase(liquibase.database.core.CockroachDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) Database(liquibase.database.Database) CockroachDatabase(liquibase.database.core.CockroachDatabase) AlterSequenceStatement(liquibase.statement.core.AlterSequenceStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest)

Example 2 with AlterSequenceStatement

use of liquibase.statement.core.AlterSequenceStatement in project liquibase by liquibase.

the class AlterSequenceGeneratorTest method testAlterSequenceDatabase.

// @Before
// public void setUpMocks() throws DatabaseException {
// 
// mockedUnsupportedMinMaxSequenceConnection = mock(DatabaseConnection.class);
// when(mockedUnsupportedMinMaxSequenceConnection.getDatabaseMajorVersion()).thenReturn(1);
// when(mockedUnsupportedMinMaxSequenceConnection.getDatabaseMinorVersion()).thenReturn(3);
// when(mockedUnsupportedMinMaxSequenceConnection.getDatabaseProductVersion()).thenReturn("1.3.174 (2013-10-19)");
// 
// mockedSupportedMinMaxSequenceConnection = mock(DatabaseConnection.class);
// when(mockedSupportedMinMaxSequenceConnection.getDatabaseMajorVersion()).thenReturn(1);
// when(mockedSupportedMinMaxSequenceConnection.getDatabaseMinorVersion()).thenReturn(3);
// when(mockedSupportedMinMaxSequenceConnection.getDatabaseProductVersion()).thenReturn("1.3.175 (2014-01-18)");
// }
@Test
public void testAlterSequenceDatabase() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            AlterSequenceStatement statement = createSampleSqlStatement();
            statement.setCacheSize(BigInteger.valueOf(3000L));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("ALTER SEQUENCE CATALOG_NAME.SEQUENCE_NAME CACHE 3000", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) Database(liquibase.database.Database) CockroachDatabase(liquibase.database.core.CockroachDatabase) AlterSequenceStatement(liquibase.statement.core.AlterSequenceStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest)

Aggregations

Database (liquibase.database.Database)2 CockroachDatabase (liquibase.database.core.CockroachDatabase)2 OracleDatabase (liquibase.database.core.OracleDatabase)2 PostgresDatabase (liquibase.database.core.PostgresDatabase)2 Sql (liquibase.sql.Sql)2 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)2 AlterSequenceStatement (liquibase.statement.core.AlterSequenceStatement)2 Test (org.junit.Test)2