MigraMongo { public MigraMongoStatus status(String fromVersion) { final Iterable<MigrationEntry> migrations = migrationHistoryService.findMigrations(fromVersion); for (MigrationRun migEntry : migrations) { if (migEntry.getStatus() == MigrationStatus.ERROR) { return MigraMongoStatus .error("At least one migration script threw an error. Check individual entries") .withEntries(toList(migrations)); } if (migEntry.getStatus() == MigrationStatus.IN_PROGRESS) { return MigraMongoStatus .inProgress("At least one migration script is in progress. Check individual entries") .withEntries(toList(migrations)); } } return MigraMongoStatus.ok().withEntries(toList(migrations)); } MigraMongo(
            MongoDatabase database,
            MigrationHistoryService migrationEntryService,
            LockService lockService,
            ScriptLookupService scriptLookupService); void setAsyncInitializerFunction(Runnable function); MigraMongoStatus dryRun(); MigraMongoStatus migrate(); MigraMongoStatus migrateAsync(); MigraMongoStatus status(String fromVersion); MigraMongoStatus repair(String fromVersion, String toVersion); MigraMongoStatus rerun(String fromVersion, String toVersion); List<MigrationEntry> getMigrationEntries(); void destroyLocks();  }
@Test public void shouldDeliverOkStatusWhenEverythingOk() throws Exception { when(migEntryService.findMigrations("1")) .thenReturn(Arrays.asList(createMigrationEntry("1", "2", MigrationStatus.OK))); final MigraMongoStatus status = migraMongo.status("1"); assertThat(status.status, is(MigrationStatus.OK)); assertThat(status.migrationsApplied, hasSize(1)); }
@Test public void shouldDeliverInProgressStatusWhenAtLeastOneEntryIsInProgress() throws Exception { when(migEntryService.findMigrations("1")) .thenReturn( Arrays .asList( createMigrationEntry("1", "2", MigrationStatus.OK), createMigrationEntry("1", "2", MigrationStatus.IN_PROGRESS), createMigrationEntry("1", "2", MigrationStatus.OK))); final MigraMongoStatus status = migraMongo.status("1"); assertThat(status.status, is(MigrationStatus.IN_PROGRESS)); assertThat(status.migrationsApplied, hasSize(3)); }
@Test public void shouldDeliverErrorStatusWhenAtLeastOneEntryIsInProgress() throws Exception { when(migEntryService.findMigrations("1")) .thenReturn( Arrays .asList( createMigrationEntry("1", "2", MigrationStatus.OK), createMigrationEntry("1", "2", MigrationStatus.ERROR), createMigrationEntry("1", "2", MigrationStatus.OK))); final MigraMongoStatus status = migraMongo.status("1"); assertThat(status.status, is(MigrationStatus.ERROR)); assertThat(status.migrationsApplied, hasSize(3)); }