use of io.gravitee.cockpit.api.command.installation.InstallationReply in project gravitee-management-rest-api by gravitee-io.
the class InstallationCommandHandlerTest method handle.
@Test
public void handle() {
final InstallationEntity installation = new InstallationEntity();
installation.setId(INSTALLATION_ID);
installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
InstallationPayload installationPayload = new InstallationPayload();
InstallationCommand command = new InstallationCommand(installationPayload);
installationPayload.setId(INSTALLATION_ID);
installationPayload.setStatus("ACCEPTED");
when(installationService.getOrInitialize()).thenReturn(installation);
TestObserver<InstallationReply> 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, "ACCEPTED");
verify(installationService, times(1)).setAdditionalInformation(expectedAdditionalInfos);
}
use of io.gravitee.cockpit.api.command.installation.InstallationReply in project gravitee-management-rest-api by gravitee-io.
the class InstallationCommandHandler method handle.
@Override
public Single<InstallationReply> handle(InstallationCommand command) {
InstallationPayload installationPayload = command.getPayload();
final Map<String, String> additionalInformation = this.installationService.getOrInitialize().getAdditionalInformation();
additionalInformation.put(InstallationService.COCKPIT_INSTALLATION_STATUS, installationPayload.getStatus());
try {
this.installationService.setAdditionalInformation(additionalInformation);
logger.info("Installation status is [{}].", installationPayload.getStatus());
return Single.just(new InstallationReply(command.getId(), CommandStatus.SUCCEEDED));
} catch (Exception ex) {
logger.info("Error occurred when updating installation status.", ex);
return Single.just(new InstallationReply(command.getId(), CommandStatus.ERROR));
}
}
use of io.gravitee.cockpit.api.command.installation.InstallationReply in project gravitee-management-rest-api by gravitee-io.
the class InstallationCommandHandlerTest method handleWithException.
@Test
public void handleWithException() {
final InstallationEntity installation = new InstallationEntity();
installation.setId(INSTALLATION_ID);
installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
InstallationPayload installationPayload = new InstallationPayload();
InstallationCommand command = new InstallationCommand(installationPayload);
installationPayload.setId(INSTALLATION_ID);
installationPayload.setStatus("ACCEPTED");
when(installationService.getOrInitialize()).thenReturn(installation);
when(installationService.setAdditionalInformation(anyMap())).thenThrow(new TechnicalManagementException());
TestObserver<InstallationReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
Aggregations