Search in sources :

Example 16 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class DiffGeneratorFactoryTest method getGenerator.

@Test
public void getGenerator() throws DatabaseException {
    DiffGenerator generator = DiffGeneratorFactory.getInstance().getGenerator(new H2Database(), new H2Database());
    assertNotNull(generator);
    assertTrue(generator instanceof StandardDiffGenerator);
}
Also used : StandardDiffGenerator(liquibase.diff.core.StandardDiffGenerator) H2Database(liquibase.database.core.H2Database) StandardDiffGenerator(liquibase.diff.core.StandardDiffGenerator) Test(org.junit.Test)

Example 17 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class ChangeLogParametersTest method setParameterValue_doubleSetButSecondWrongDatabase.

@Test
public void setParameterValue_doubleSetButSecondWrongDatabase() {
    ChangeLogParameters changeLogParameters = new ChangeLogParameters(new H2Database());
    changeLogParameters.set("doubleSet", "originalValue", new ContextExpression(), new Labels(), "baddb", true, null);
    changeLogParameters.set("doubleSet", "newValue");
    assertEquals("newValue", changeLogParameters.getValue("doubleSet", null));
}
Also used : ContextExpression(liquibase.ContextExpression) Labels(liquibase.Labels) H2Database(liquibase.database.core.H2Database) Test(org.junit.Test)

Example 18 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class ChangeLogParametersTest method setParameterValue_doubleSet_withDbms.

@Test
public void setParameterValue_doubleSet_withDbms() throws Exception {
    final DatabaseChangeLog changelog = new DatabaseChangeLog("com/example/changelog.txt");
    ChangeLogParameters h2Params = new ChangeLogParameters(new H2Database());
    ChangeLogParameters oracleParams = new ChangeLogParameters(new OracleDatabase());
    ChangeLogParameters mysqlParams = new ChangeLogParameters(new MySQLDatabase());
    h2Params.set("dbmsProperty", "h2 value", new ContextExpression(), new Labels(), "h2", false, changelog);
    h2Params.set("dbmsProperty", "oracle value", new ContextExpression(), new Labels(), "oracle", false, changelog);
    oracleParams.set("dbmsProperty", "h2 value", new ContextExpression(), new Labels(), "h2", false, changelog);
    oracleParams.set("dbmsProperty", "oracle value", new ContextExpression(), new Labels(), "oracle", false, changelog);
    mysqlParams.set("dbmsProperty", "h2 value", new ContextExpression(), new Labels(), "h2", false, changelog);
    mysqlParams.set("dbmsProperty", "oracle value", new ContextExpression(), new Labels(), "oracle", false, changelog);
    assertEquals("h2 value", h2Params.getValue("dbmsProperty", changelog));
    assertEquals("oracle value", oracleParams.getValue("dbmsProperty", changelog));
    assertNull(mysqlParams.getValue("dbmsProperty", changelog));
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) ContextExpression(liquibase.ContextExpression) MySQLDatabase(liquibase.database.core.MySQLDatabase) Labels(liquibase.Labels) H2Database(liquibase.database.core.H2Database) Test(org.junit.Test)

Example 19 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class ChangeLogParametersTest method getParameterValue_IgnoreLocalParameterAfterGlobalParameter.

@Test
public /**
 * db.changelog-master.xml
 * - table_1.xml (table.name=table_1 global=false)
 * - - include templates/common_columns_1.xml
 * - table_2.xml (table.name=table_2 global=false)
 * - - include templates/common_columns_2.xml
 * - - - include templates/common_columns_1.xml
 *
 *  Local parameters with the same name are ignore after the first global parameter with that same name.
 */
void getParameterValue_IgnoreLocalParameterAfterGlobalParameter() {
    ChangeLogParameters changeLogParameters = new ChangeLogParameters(new H2Database());
    DatabaseChangeLog master = new DatabaseChangeLog("db/db.changelog-master.xml");
    DatabaseChangeLog table_1 = new DatabaseChangeLog("db/changelog/table_1.xml");
    table_1.setParentChangeLog(master);
    changeLogParameters.set("table.name", "table_1", "junit", "junitLabel", "baddb, h2", true, table_1);
    DatabaseChangeLog common_columns_1_of_table_1 = new DatabaseChangeLog("db/templates/common_columns_1.xml");
    common_columns_1_of_table_1.setParentChangeLog(table_1);
    assertEquals("table_1", changeLogParameters.getValue("table.name", common_columns_1_of_table_1));
    assertEquals("table_1", changeLogParameters.getValue("table.name", table_1));
    DatabaseChangeLog table_2 = new DatabaseChangeLog("db/changelog/table_2.xml");
    table_2.setParentChangeLog(master);
    changeLogParameters.set("table.name", "table_2", "junit", "junitLabel", "baddb, h2", false, table_2);
    DatabaseChangeLog common_columns_2_of_table_2 = new DatabaseChangeLog("db/templates/common_columns_2.xml");
    common_columns_2_of_table_2.setParentChangeLog(table_2);
    DatabaseChangeLog common_columns_1_of_table_2 = new DatabaseChangeLog("db/templates/common_columns_1.xml");
    common_columns_1_of_table_2.setParentChangeLog(common_columns_2_of_table_2);
    // the local parameter value "table_2" is being ignored since there is already a global value defined
    assertEquals("should return first global value", "table_1", changeLogParameters.getValue("table.name", common_columns_1_of_table_2));
    assertEquals("should return first global value", "table_1", changeLogParameters.getValue("table.name", common_columns_2_of_table_2));
    assertEquals("should return first global value", "table_1", changeLogParameters.getValue("table.name", table_2));
}
Also used : H2Database(liquibase.database.core.H2Database) Test(org.junit.Test)

Example 20 with H2Database

use of liquibase.database.core.H2Database in project liquibase by liquibase.

the class ChangeLogParametersTest method getParameterValue_SamePropertyNonGlobalIn2InnerFiles.

@Test
public /**
 * root.xml
 *  -a.xml
 *  -b.xml
 *
 *  in a and b we define same prop with key 'aKey'. Expected when b is processed then bValue is taken no matter of Object instances
 */
void getParameterValue_SamePropertyNonGlobalIn2InnerFiles() {
    DatabaseChangeLog inner1 = new DatabaseChangeLog();
    inner1.setPhysicalFilePath("a");
    DatabaseChangeLog inner2 = new DatabaseChangeLog();
    inner2.setPhysicalFilePath("b");
    ChangeLogParameters changeLogParameters = new ChangeLogParameters(new H2Database());
    changeLogParameters.set("aKey", "aValue", "junit", "junitLabel", "baddb, h2", false, inner1);
    changeLogParameters.set("aKey", "bValue", "junit", "junitLabel", "baddb, h2", false, inner2);
    DatabaseChangeLog inner2SamePath = new DatabaseChangeLog();
    inner2SamePath.setPhysicalFilePath("b");
    Object aKey = changeLogParameters.getValue("aKey", inner2SamePath);
    assertEquals("bValue", aKey);
}
Also used : H2Database(liquibase.database.core.H2Database) Test(org.junit.Test)

Aggregations

H2Database (liquibase.database.core.H2Database)25 Test (org.junit.Test)23 Database (liquibase.database.Database)7 MySQLDatabase (liquibase.database.core.MySQLDatabase)7 OracleDatabase (liquibase.database.core.OracleDatabase)7 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)5 PostgresDatabase (liquibase.database.core.PostgresDatabase)5 Sql (liquibase.sql.Sql)5 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)5 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)4 DerbyDatabase (liquibase.database.core.DerbyDatabase)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)4 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)4 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)4 SybaseDatabase (liquibase.database.core.SybaseDatabase)4 CreateTableStatement (liquibase.statement.core.CreateTableStatement)4 ContextExpression (liquibase.ContextExpression)3 Labels (liquibase.Labels)3 ColumnConfig (liquibase.change.ColumnConfig)3 SqlGeneratorChain (liquibase.sqlgenerator.SqlGeneratorChain)3