@Test public void verify_example() throws Exception { when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(DateUtils.parseDateTime("2015-02-23T18:54:23+0100")); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-migrate_db.json")); }
@Test public void verify_example() throws Exception { when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(DateUtils.parseDateTime("2015-02-23T18:54:23+0100")); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-migrate_db.json")); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_includes_error_when_dbmigration_status_is_FAILED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(FAILED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); when(migrationState.getError()).thenReturn(new UnsupportedOperationException(SOME_THROWABLE_MSG)); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_FAILED, failedMsg(SOME_THROWABLE_MSG), SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_has_default_msg_when_dbmigration_status_is_SUCCEEDED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(SUCCEEDED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_SUCCEEDED, MESSAGE_STATUS_SUCCEEDED, SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_has_default_msg_when_dbmigration_status_is_FAILED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(FAILED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); when(migrationState.getError()).thenReturn(null); // no failure throwable caught underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_FAILED, failedMsg(DEFAULT_ERROR_MSG), SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_when_dbmigration_status_is_RUNNING(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_RUNNING, MESSAGE_STATUS_RUNNING, SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_includes_error_when_dbmigration_status_is_FAILED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(FAILED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); when(migrationState.getError()).thenReturn(new UnsupportedOperationException(SOME_THROWABLE_MSG)); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_FAILED, failedMsg(SOME_THROWABLE_MSG), SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void start_migration_and_return_state_from_databasemigration_when_dbmigration_status_is_NONE(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(NONE); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_REQUIRED, MESSAGE_MIGRATION_REQUIRED)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_when_dbmigration_status_is_RUNNING(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(RUNNING); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_RUNNING, MESSAGE_STATUS_RUNNING, SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_has_default_msg_when_dbmigration_status_is_SUCCEEDED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(SUCCEEDED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_SUCCEEDED, MESSAGE_STATUS_SUCCEEDED, SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void start_migration_and_return_state_from_databasemigration_when_dbmigration_status_is_NONE(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(NONE); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); underTest.handle(request, response); verify(databaseMigration).startIt(); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_RUNNING, MESSAGE_STATUS_RUNNING, SOME_DATE)); }
@Test @UseDataProvider("statusRequiringDbMigration") public void state_from_database_migration_and_msg_has_default_msg_when_dbmigration_status_is_FAILED(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(true); when(migrationState.getStatus()).thenReturn(FAILED); when(migrationState.getStartedAt()).thenReturn(SOME_DATE); when(migrationState.getError()).thenReturn(null); // no failure throwable caught underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_MIGRATION_FAILED, failedMsg(DEFAULT_ERROR_MSG), SOME_DATE)); }
if (status == DatabaseVersion.Status.UP_TO_DATE || status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) { write(json, databaseMigrationState); } else if (!database.getDialect().supportsMigration()) { writeNotSupportedResponse(json); } else {
@Test @UseDataProvider("statusRequiringDbMigration") public void state_is_NONE_with_specific_msg_when_db_requires_upgrade_but_dialect_does_not_support_migration(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(false); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_NOT_SUPPORTED, MESSAGE_NO_MIGRATION_ON_EMBEDDED_DATABASE)); }
if (status == DatabaseVersion.Status.UP_TO_DATE || status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) { write(json, migrationState); } else if (!database.getDialect().supportsMigration()) { writeNotSupportedResponse(json); } else {
@Test @UseDataProvider("statusRequiringDbMigration") public void state_is_NONE_with_specific_msg_when_db_requires_upgrade_but_dialect_does_not_support_migration(DatabaseVersion.Status status) throws Exception { when(databaseVersion.getStatus()).thenReturn(status); when(dialect.supportsMigration()).thenReturn(false); underTest.handle(request, response); assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_NOT_SUPPORTED, MESSAGE_NO_MIGRATION_ON_EMBEDDED_DATABASE)); }
if (status == DatabaseVersion.Status.UP_TO_DATE || status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) { write(json, databaseMigrationState); } else if (!database.getDialect().supportsMigration()) { writeNotSupportedResponse(json); } else {
if (status == DatabaseVersion.Status.UP_TO_DATE || status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) { write(json, migrationState); } else if (!database.getDialect().supportsMigration()) { writeNotSupportedResponse(json); } else {