use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class MarkChangeSetRanGeneratorTest method generateSqlSecondRunUpdatesLabelsContextsComments.
/**
* Ensure that upon running an update on a changeset that has been run before, we still update the labels,
* contexts and comments columns in the DBCL table.
*/
@Test
public void generateSqlSecondRunUpdatesLabelsContextsComments() {
String changeSetContextExpression = "changeSetContext1 AND changeSetContext2";
DatabaseChangeLog rootChangeLog = new DatabaseChangeLog();
rootChangeLog.setContexts(new ContextExpression("rootContext1 OR (rootContext2) AND (rootContext3)"));
DatabaseChangeLog childChangeLog = new DatabaseChangeLog();
childChangeLog.setContexts(new ContextExpression("childChangeLogContext1, childChangeLogContext2 AND childChangeLogContext3"));
childChangeLog.setIncludeContexts(new ContextExpression("includeContext1, includeContext2 AND includeContext3"));
childChangeLog.setParentChangeLog(rootChangeLog);
ChangeSet changeSet = new ChangeSet("1", "a", false, false, "c", changeSetContextExpression, null, childChangeLog);
changeSet.setComments("comment12345");
changeSet.setLabels(new Labels("newlabel123"));
Sql[] sqls = new MarkChangeSetRanGenerator().generateSql(new MarkChangeSetRanStatement(changeSet, ChangeSet.ExecType.RERAN), new MockDatabase(), new MockSqlGeneratorChain());
String sql = sqls[0].toSql();
assertTrue(sql.contains("COMMENTS = 'comment12345'"));
assertTrue(sql.contains("CONTEXTS = '(childChangeLogContext1, childChangeLogContext2 AND childChangeLogContext3) AND (includeContext1, includeContext2 AND includeContext3) AND (rootContext1 OR (rootContext2) AND (rootContext3)) AND (changeSetContext1 AND changeSetContext2)'"));
assertTrue(sql.contains("LABELS = 'newlabel123'"));
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class MarkChangeSetRanGeneratorTest method generateSqlWithComplexContext.
@Test
public void generateSqlWithComplexContext() {
String changeSetContextExpression = "changeSetContext1 AND changeSetContext2";
DatabaseChangeLog rootChangeLog = new DatabaseChangeLog();
rootChangeLog.setContexts(new ContextExpression("rootContext1 OR (rootContext2) AND (rootContext3)"));
DatabaseChangeLog childChangeLog = new DatabaseChangeLog();
childChangeLog.setContexts(new ContextExpression("childChangeLogContext1, childChangeLogContext2 AND childChangeLogContext3"));
childChangeLog.setIncludeContexts(new ContextExpression("includeContext1, includeContext2 AND includeContext3"));
childChangeLog.setParentChangeLog(rootChangeLog);
ChangeSet changeSet = new ChangeSet("1", "a", false, false, "c", changeSetContextExpression, null, childChangeLog);
Sql[] sqls = new MarkChangeSetRanGenerator().generateSql(new MarkChangeSetRanStatement(changeSet, ChangeSet.ExecType.EXECUTED), new MockDatabase(), new MockSqlGeneratorChain());
assertTrue(sqls[0].toSql(), sqls[0].toSql().contains("(childChangeLogContext1, childChangeLogContext2 AND childChangeLogContext3) AND " + "(includeContext1, includeContext2 AND includeContext3) AND " + "(rootContext1 OR (rootContext2) AND (rootContext3)) AND " + "(changeSetContext1 AND changeSetContext2)"));
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class TestContext method getAllDatabases.
public Set<Database> getAllDatabases() {
if (allDatabases == null) {
allDatabases = new HashSet<Database>();
allDatabases.addAll(DatabaseFactory.getInstance().getImplementedDatabases());
List<Database> toRemove = new ArrayList<Database>();
for (Database database : allDatabases) {
if (// todo: re-enable sqlite testing
(database instanceof SQLiteDatabase) || (database instanceof MockDatabase)) {
toRemove.add(database);
}
database.setCanCacheLiquibaseTableInfo(false);
}
allDatabases.removeAll(toRemove);
}
return allDatabases;
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class SqlGeneratorChainTest method validate_oneGenerators_hasErrors.
@Test
public void validate_oneGenerators_hasErrors() {
SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
generators.add(new MockSqlGenerator(1, "A1", "A2").addValidationError("E1"));
SqlGeneratorChain chain = new SqlGeneratorChain(generators);
ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase());
assertTrue(validationErrors.hasErrors());
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class SqlGeneratorChainTest method validate_twoGenerators_noErrors.
@Test
public void validate_twoGenerators_noErrors() {
SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
generators.add(new MockSqlGenerator(2, "B1", "B2"));
generators.add(new MockSqlGenerator(1, "A1", "A2"));
SqlGeneratorChain chain = new SqlGeneratorChain(generators);
ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase());
assertFalse(validationErrors.hasErrors());
}
Aggregations