use of io.gravitee.cockpit.api.command.goodbye.GoodbyeReply in project gravitee-management-rest-api by gravitee-io.
the class GoodbyeCommandHandlerTest method handleWithException.
@Test
public void handleWithException() {
final InstallationEntity installation = new InstallationEntity();
installation.setId(INSTALLATION_ID);
installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
GoodbyeCommand command = new GoodbyeCommand();
when(installationService.getOrInitialize()).thenReturn(installation);
when(installationService.setAdditionalInformation(anyMap())).thenThrow(new TechnicalManagementException());
when(promotionService.search(any(), any(), any())).thenReturn(new Page<>(emptyList(), 0, 0, 0));
TestObserver<GoodbyeReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
use of io.gravitee.cockpit.api.command.goodbye.GoodbyeReply in project gravitee-management-rest-api by gravitee-io.
the class GoodbyeCommandHandler method handle.
@Override
public Single<GoodbyeReply> handle(GoodbyeCommand command) {
final Map<String, String> additionalInformation = this.installationService.getOrInitialize().getAdditionalInformation();
additionalInformation.put(InstallationService.COCKPIT_INSTALLATION_STATUS, DELETED_STATUS);
rejectAllPromotionToValidate();
try {
this.installationService.setAdditionalInformation(additionalInformation);
logger.info("Installation status is [{}].", DELETED_STATUS);
return Single.just(new GoodbyeReply(command.getId(), CommandStatus.SUCCEEDED));
} catch (Exception ex) {
logger.info("Error occurred when deleting installation.", ex);
return Single.just(new GoodbyeReply(command.getId(), CommandStatus.ERROR));
}
}
use of io.gravitee.cockpit.api.command.goodbye.GoodbyeReply in project gravitee-management-rest-api by gravitee-io.
the class GoodbyeCommandHandlerTest method handle.
@Test
public void handle() {
final InstallationEntity installation = new InstallationEntity();
installation.setId(INSTALLATION_ID);
installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
GoodbyeCommand command = new GoodbyeCommand();
when(installationService.getOrInitialize()).thenReturn(installation);
when(promotionService.search(any(), any(), any())).thenReturn(new Page<>(emptyList(), 0, 0, 0));
TestObserver<GoodbyeReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
final HashMap<String, String> expectedAdditionalInfos = new HashMap<>();
expectedAdditionalInfos.put(CUSTOM_KEY, CUSTOM_VALUE);
expectedAdditionalInfos.put(InstallationService.COCKPIT_INSTALLATION_STATUS, DELETED_STATUS);
verify(installationService, times(1)).setAdditionalInformation(expectedAdditionalInfos);
}
use of io.gravitee.cockpit.api.command.goodbye.GoodbyeReply in project gravitee-management-rest-api by gravitee-io.
the class GoodbyeCommandHandlerTest method handleRejectAllPromotionToValidate.
@Test
public void handleRejectAllPromotionToValidate() {
final InstallationEntity installation = new InstallationEntity();
installation.setId(INSTALLATION_ID);
installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
GoodbyeCommand command = new GoodbyeCommand();
when(installationService.getOrInitialize()).thenReturn(installation);
PromotionEntity promotionEntity1 = getAPromotionEntity("promotion#1");
PromotionEntity promotionEntity2 = getAPromotionEntity("promotion#2");
when(promotionService.search(any(), any(), any())).thenReturn(new Page<>(List.of(promotionEntity1, promotionEntity2), 0, 0, 0));
TestObserver<GoodbyeReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
ArgumentCaptor<PromotionEntity> captor = ArgumentCaptor.forClass(PromotionEntity.class);
verify(promotionService, times(2)).createOrUpdate(captor.capture());
assertThat(captor.getAllValues()).extracting(PromotionEntity::getId, PromotionEntity::getStatus).containsExactlyInAnyOrder(tuple(promotionEntity1.getId(), PromotionEntityStatus.REJECTED), tuple(promotionEntity2.getId(), PromotionEntityStatus.REJECTED));
}
Aggregations