Search in sources :

Example 1 with InstallationPayload

use of io.gravitee.cockpit.api.command.installation.InstallationPayload 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);
}
Also used : InstallationCommand(io.gravitee.cockpit.api.command.installation.InstallationCommand) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) HashMap(java.util.HashMap) InstallationPayload(io.gravitee.cockpit.api.command.installation.InstallationPayload) InstallationReply(io.gravitee.cockpit.api.command.installation.InstallationReply) Test(org.junit.Test)

Example 2 with InstallationPayload

use of io.gravitee.cockpit.api.command.installation.InstallationPayload 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));
    }
}
Also used : InstallationPayload(io.gravitee.cockpit.api.command.installation.InstallationPayload) InstallationReply(io.gravitee.cockpit.api.command.installation.InstallationReply)

Example 3 with InstallationPayload

use of io.gravitee.cockpit.api.command.installation.InstallationPayload 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));
}
Also used : InstallationCommand(io.gravitee.cockpit.api.command.installation.InstallationCommand) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) InstallationPayload(io.gravitee.cockpit.api.command.installation.InstallationPayload) InstallationReply(io.gravitee.cockpit.api.command.installation.InstallationReply) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Test(org.junit.Test)

Aggregations

InstallationPayload (io.gravitee.cockpit.api.command.installation.InstallationPayload)3 InstallationReply (io.gravitee.cockpit.api.command.installation.InstallationReply)3 InstallationCommand (io.gravitee.cockpit.api.command.installation.InstallationCommand)2 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)2 Test (org.junit.Test)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 HashMap (java.util.HashMap)1