MigraMongoJMX { @ManagedOperation public String history() { return toJson(migraMongo.getMigrationEntries()); } MigraMongoJMX(MigraMongo migraMongo); @ManagedOperation String migrate(); @ManagedOperation String migrateAsync(); @ManagedOperation String dryRun(); @ManagedOperation String status(String fromVersion); @ManagedOperation Boolean needsMigration(); @ManagedOperation String history(); @ManagedOperation void destroyLocks();  }
@Test public void shouldReturnAppliedMigrations() { final List<MigrationEntry> entries = Arrays .asList(createMigrationEntry("3.0", "4.0"), createMigrationEntry("4.0", "5.0")); when(migraMongo.getMigrationEntries()).thenReturn(entries); final String history = migraMongoJMX.history(); final List<MigrationEntry> entriesRetrieved = new Gson() .fromJson(history, new TypeToken<List<MigrationEntry>>() {}.getType()); assertThat(entriesRetrieved, hasSize(entries.size())); for (int i = 0; i < entries.size(); i++ ) { assertThat( entries.get(i), allOf( hasProperty("fromVersion", is(entriesRetrieved.get(i).getFromVersion())), hasProperty("toVersion", is(entriesRetrieved.get(i).getToVersion())))); } }
@Test public void shouldNotReturnAppliedMigrationsWhenNoneAvailable() { when(migraMongo.getMigrationEntries()).thenReturn(Collections.emptyList()); final String history = migraMongoJMX.history(); final List<MigrationEntry> entriesRetrieved = new Gson() .fromJson(history, new TypeToken<List<MigrationEntry>>() {}.getType()); assertThat(entriesRetrieved, hasSize(0)); }