Search in sources :

Example 1 with MockDatabase

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;
        }
    });
}
Also used : MockResourceAccessor(liquibase.sdk.resource.MockResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) LockService(liquibase.lockservice.LockService) LockServiceFactory(liquibase.lockservice.LockServiceFactory) ChangeLogParserFactory(liquibase.parser.ChangeLogParserFactory) Logger(liquibase.logging.Logger) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) LogFactory(liquibase.logging.LogFactory) MockResourceAccessor(liquibase.sdk.resource.MockResourceAccessor) ChangeLogIterator(liquibase.changelog.ChangeLogIterator) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) ChangeLogParser(liquibase.parser.ChangeLogParser) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) Before(org.junit.Before)

Example 2 with MockDatabase

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());
}
Also used : MockResourceAccessor(liquibase.sdk.resource.MockResourceAccessor) MockDatabase(liquibase.sdk.database.MockDatabase) Test(org.junit.Test)

Example 3 with MockDatabase

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());
}
Also used : ChangeSetVisitor(liquibase.changelog.visitor.ChangeSetVisitor) RuntimeEnvironment(liquibase.RuntimeEnvironment) JUnitResourceAccessor(liquibase.test.JUnitResourceAccessor) ArrayList(java.util.ArrayList) Contexts(liquibase.Contexts) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) ChangeLogIterator(liquibase.changelog.ChangeLogIterator) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) LabelExpression(liquibase.LabelExpression) MockDatabase(liquibase.sdk.database.MockDatabase) LiquibaseException(liquibase.exception.LiquibaseException) ChangeSetFilterResult(liquibase.changelog.filter.ChangeSetFilterResult) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 4 with MockDatabase

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;
}
Also used : SQLiteDatabase(liquibase.database.core.SQLiteDatabase) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DB2Database(liquibase.database.core.DB2Database) MockDatabase(liquibase.sdk.database.MockDatabase) ExampleCustomDatabase(liquibase.database.example.ExampleCustomDatabase) MockDatabase(liquibase.sdk.database.MockDatabase) ExampleCustomDatabase(liquibase.database.example.ExampleCustomDatabase)

Example 5 with MockDatabase

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());
}
Also used : MockDatabase(liquibase.sdk.database.MockDatabase) Test(org.junit.Test)

Aggregations

MockDatabase (liquibase.sdk.database.MockDatabase)7 Test (org.junit.Test)5 Database (liquibase.database.Database)4 ChangeLogIterator (liquibase.changelog.ChangeLogIterator)2 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 MockResourceAccessor (liquibase.sdk.resource.MockResourceAccessor)2 ArrayList (java.util.ArrayList)1 Contexts (liquibase.Contexts)1 LabelExpression (liquibase.LabelExpression)1 RuntimeEnvironment (liquibase.RuntimeEnvironment)1 ChangeSet (liquibase.changelog.ChangeSet)1 ChangeSetFilterResult (liquibase.changelog.filter.ChangeSetFilterResult)1 ChangeSetVisitor (liquibase.changelog.visitor.ChangeSetVisitor)1 DatabaseConnection (liquibase.database.DatabaseConnection)1 DatabaseFactory (liquibase.database.DatabaseFactory)1 DB2Database (liquibase.database.core.DB2Database)1 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)1 ExampleCustomDatabase (liquibase.database.example.ExampleCustomDatabase)1 LiquibaseException (liquibase.exception.LiquibaseException)1