use of liquibase.sdk.database.MockDatabase in project liquibase by liquibase.
the class LiquibaseTest method before.
// private TestLiquibase testLiquibase;
// private DatabaseConnection connectionForConstructor;
@Before
public void before() throws Exception {
// if (connectionForConstructor != null) {
// reset(connectionForConstructor);
// }
// connectionForConstructor = createMock(DatabaseConnection.class);
// connectionForConstructor.setAutoCommit(false);
// expectLastCall().atLeastOnce();
//
// DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
// expect(metaData.getDatabaseProductName()).andReturn("Oracle");
// replay(metaData);
//
//// expect(connectionForConstructor.getMetaData()).andReturn(metaData);
// replay(connectionForConstructor);
//
// testLiquibase = new TestLiquibase();
mockResourceAccessor = new MockResourceAccessor();
mockDatabase = mock(Database.class);
mockLockService = mock(LockService.class);
mockLockServiceFactory = mock(LockServiceFactory.class);
mockChangeLogParserFactory = mock(ChangeLogParserFactory.class);
mockChangeLogParser = mock(ChangeLogParser.class);
mockChangeLog = mock(DatabaseChangeLog.class);
mockChangeLogIterator = mock(ChangeLogIterator.class);
mockLogger = mock(Logger.class);
LockServiceFactory.setInstance(mockLockServiceFactory);
when(mockLockServiceFactory.getLockService(any(Database.class))).thenReturn(mockLockService);
ChangeLogParserFactory.setInstance(mockChangeLogParserFactory);
when(mockChangeLogParserFactory.getParser(anyString(), Mockito.isA(ResourceAccessor.class))).thenReturn(mockChangeLogParser);
when(mockChangeLogParser.parse(anyString(), any(ChangeLogParameters.class), Mockito.isA(ResourceAccessor.class))).thenReturn(mockChangeLog);
LogFactory.setInstance(new LogFactory() {
@Override
public Logger getLog(String name) {
return mockLogger;
}
});
}
use of liquibase.sdk.database.MockDatabase in project liquibase by liquibase.
the class LiquibaseTest method constructor.
@Test
public void constructor() throws Exception {
//going to test log setup
LogFactory.reset();
MockResourceAccessor resourceAccessor = this.mockResourceAccessor;
MockDatabase database = new MockDatabase();
Liquibase liquibase = new Liquibase("com/example/test.xml", resourceAccessor, database);
assertNotNull(liquibase.getLog());
assertEquals("com/example/test.xml", liquibase.getChangeLogFile());
assertSame(resourceAccessor, liquibase.getResourceAccessor());
assertNotNull(liquibase.getChangeLogParameters());
assertEquals("Standard database changelog parameters were not set", "DATABASECHANGELOGLOCK", liquibase.getChangeLogParameters().getValue("database.databaseChangeLogLockTableName", null));
assertSame(database, liquibase.getDatabase());
}
use of liquibase.sdk.database.MockDatabase in project liquibase by liquibase.
the class XMLChangeLogSAXParserTest method testIgnoreDuplicateChangeSets.
@Test
public void testIgnoreDuplicateChangeSets() throws ChangeLogParseException, Exception {
XMLChangeLogSAXParser xmlParser = new XMLChangeLogSAXParser();
DatabaseChangeLog changeLog = xmlParser.parse("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/master.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
final List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
new ChangeLogIterator(changeLog).run(new ChangeSetVisitor() {
@Override
public Direction getDirection() {
return Direction.FORWARD;
}
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
changeSets.add(changeSet);
}
}, new RuntimeEnvironment(new MockDatabase(), new Contexts(), new LabelExpression()));
Assert.assertEquals(8, changeSets.size());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(0).toString());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(1).toString());
Assert.assertEquals(1, changeSets.get(1).getContexts().getContexts().size());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(2).toString());
Assert.assertEquals(1, changeSets.get(2).getLabels().getLabels().size());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(3).toString());
Assert.assertEquals(2, changeSets.get(3).getLabels().getLabels().size());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(4).toString());
Assert.assertEquals(1, changeSets.get(4).getDbmsSet().size());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog1.xml::1::testuser", changeSets.get(5).toString());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog3.xml::1::testuser", changeSets.get(6).toString());
Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog2.xml::1::testuser", changeSets.get(7).toString());
}
use of liquibase.sdk.database.MockDatabase in project liquibase by liquibase.
the class DatabaseTestContext 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 || database instanceof ExampleCustomDatabase) {
toRemove.add(database);
}
}
allDatabases.removeAll(toRemove);
}
return allDatabases;
}
use of liquibase.sdk.database.MockDatabase in project liquibase by liquibase.
the class LiquibaseTest method constructor_changelogPathsStandardize.
@Test
public void constructor_changelogPathsStandardize() throws Exception {
Liquibase liquibase = new Liquibase("path\\with\\windows\\separators.xml", mockResourceAccessor, new MockDatabase());
assertEquals("path/with/windows/separators.xml", liquibase.getChangeLogFile());
liquibase = new Liquibase("path/with/unix/separators.xml", mockResourceAccessor, new MockDatabase());
assertEquals("path/with/unix/separators.xml", liquibase.getChangeLogFile());
liquibase = new Liquibase("/absolute/path/remains.xml", mockResourceAccessor, new MockDatabase());
assertEquals("/absolute/path/remains.xml", liquibase.getChangeLogFile());
}
Aggregations