Search in sources :

Example 1 with GoodbyeCommand

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

Example 2 with GoodbyeCommand

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

Example 3 with GoodbyeCommand

use of io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand 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));
}
Also used : GoodbyeCommand(io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) GoodbyeReply(io.gravitee.cockpit.api.command.goodbye.GoodbyeReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) Test(org.junit.Test)

Aggregations

GoodbyeCommand (io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand)3 GoodbyeReply (io.gravitee.cockpit.api.command.goodbye.GoodbyeReply)3 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)3 Test (org.junit.Test)3 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 HashMap (java.util.HashMap)1