use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class SqlGeneratorChainTest method generateSql_threeGenerators.
@Test
public void generateSql_threeGenerators() {
SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
generators.add(new MockSqlGenerator(2, "B1", "B2"));
generators.add(new MockSqlGenerator(1, "A1", "A2"));
generators.add(new MockSqlGenerator(3, "C1", "C2"));
SqlGeneratorChain chain = new SqlGeneratorChain(generators);
Sql[] sql = chain.generateSql(new MockSqlStatement(), new MockDatabase());
assertEquals(6, sql.length);
assertEquals("C1", sql[0].toSql());
assertEquals("C2", sql[1].toSql());
assertEquals("B1", sql[2].toSql());
assertEquals("B2", sql[3].toSql());
assertEquals("A1", sql[4].toSql());
assertEquals("A2", sql[5].toSql());
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class SqlGeneratorChainTest method validate_twoGenerators_firstHasErrors.
@Test
public void validate_twoGenerators_firstHasErrors() {
SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
generators.add(new MockSqlGenerator(2, "B1", "B2").addValidationError("E1"));
generators.add(new MockSqlGenerator(1, "A1", "A2"));
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 ValidatingVisitorTest method visit_successful.
@Test
public void visit_successful() throws Exception {
CreateTableChange change1 = new CreateTableChange();
change1.setTableName("table1");
ColumnConfig column1 = new ColumnConfig();
change1.addColumn(column1);
column1.setName("col1");
column1.setType("int");
CreateTableChange change2 = new CreateTableChange();
change2.setTableName("table2");
ColumnConfig column2 = new ColumnConfig();
change2.addColumn(column2);
column2.setName("col2");
column2.setType("int");
changeSet1.addChange(change1);
changeSet2.addChange(change2);
ValidatingVisitor handler = new ValidatingVisitor(new ArrayList<RanChangeSet>());
handler.visit(changeSet1, new DatabaseChangeLog(), new MockDatabase(), null);
handler.visit(changeSet2, new DatabaseChangeLog(), new MockDatabase(), null);
assertTrue(handler.validationPassed());
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class AddColumnChangeTest method generateStatements_singleColumn_uniqueConstraintName.
@Test
public void generateStatements_singleColumn_uniqueConstraintName() {
String myUniqueConstraintName = "my_unique_constraint";
AddColumnChange change = new AddColumnChange();
change.setTableName("my_table");
AddColumnConfig column = new AddColumnConfig();
column.setName("column1");
column.setType("integer");
ConstraintsConfig constraintsConfig = new ConstraintsConfig();
constraintsConfig.setUnique(true);
constraintsConfig.setUniqueConstraintName(myUniqueConstraintName);
column.setConstraints(constraintsConfig);
change.addColumn(column);
SqlStatement[] statements = change.generateStatements(new MockDatabase());
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof AddColumnStatement);
AddColumnStatement stmt = (AddColumnStatement) statements[0];
Assert.assertEquals(myUniqueConstraintName, stmt.getUniqueStatementName());
}
use of liquibase.database.core.MockDatabase in project liquibase by liquibase.
the class AddColumnChangeTest method generateStatements_singleColumn_null_uniqueConstraintName.
@Test
public void generateStatements_singleColumn_null_uniqueConstraintName() {
AddColumnChange change = new AddColumnChange();
change.setTableName("my_table");
AddColumnConfig column = new AddColumnConfig();
column.setName("column1");
column.setType("integer");
ConstraintsConfig constraintsConfig = new ConstraintsConfig();
constraintsConfig.setUnique(true);
column.setConstraints(constraintsConfig);
change.addColumn(column);
SqlStatement[] statements = change.generateStatements(new MockDatabase());
Assert.assertEquals(1, statements.length);
Assert.assertTrue(statements[0] instanceof AddColumnStatement);
AddColumnStatement stmt = (AddColumnStatement) statements[0];
Assert.assertNull(stmt.getUniqueStatementName());
}
Aggregations