MigraMongo { public MigraMongoStatus repair(String fromVersion, String toVersion) { final MigrationEntry migrationEntry = migrationHistoryService.findMigration(fromVersion, toVersion); if (migrationEntry == null) { return MigraMongoStatus .error( "No migration entry found for fromVersion '" + fromVersion + "' and toVersion '" + toVersion + "'"); } if (migrationEntry.getStatus() == MigrationStatus.OK) { return MigraMongoStatus .error( "Migration entry with fromVersion '" + fromVersion + "' and toVersion '" + toVersion + "' has already status '" + migrationEntry.getStatus() + "'. Nothing will be done"); } final MigrationStatus previousStatus = migrationEntry.getStatus(); final MigrationEntry correctedMigrationEntry = migrationHistoryService .setMigrationStatusToFinished(migrationEntry); final MigraMongoStatus status = MigraMongoStatus .ok( "Status of migrationEntry " + migrationEntry + " changed from '" + previousStatus + "' to '" + MigrationStatus.OK + "'"); status.addEntry(correctedMigrationEntry); return status; } 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 shouldNotRepairEntryThatDoesNotExist() throws Exception { final MigraMongoStatus status = migraMongo.repair("2", "3"); assertThat(status.status, is(MigrationStatus.ERROR)); assertThat(status.message, containsString("No migration entry found")); assertThat(status.migrationsApplied, hasSize(0)); }
@Test public void shouldRepairEntryInErrorStatus() throws Exception { mockEntry("4", "5", MigrationStatus.ERROR); final MigraMongoStatus status = migraMongo.repair("4", "5"); assertThat(status.status, is(MigrationStatus.OK)); assertThat( status.message, containsString("changed from '" + MigrationStatus.ERROR + "' to '" + MigrationStatus.OK + "'")); assertThat(status.migrationsApplied, hasSize(1)); }
@Test public void shouldRepairEntryInInProgressStatus() throws Exception { mockEntry("4", "5", MigrationStatus.IN_PROGRESS); final MigraMongoStatus status = migraMongo.repair("4", "5"); assertThat(status.status, is(MigrationStatus.OK)); assertThat( status.message, containsString("changed from '" + MigrationStatus.IN_PROGRESS + "' to '" + MigrationStatus.OK + "'")); assertThat(status.migrationsApplied, hasSize(1)); }
@Test public void shouldNotRepairEntryInOkStatus() throws Exception { mockEntry("4", "5", MigrationStatus.OK); final MigraMongoStatus status = migraMongo.repair("4", "5"); assertThat(status.status, is(MigrationStatus.ERROR)); assertThat(status.message, containsString("has already status '" + MigrationStatus.OK + "'")); assertThat(status.migrationsApplied, hasSize(0)); }