Search in sources :

Example 11 with InstallationEntity

use of io.gravitee.rest.api.model.InstallationEntity 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)

Example 12 with InstallationEntity

use of io.gravitee.rest.api.model.InstallationEntity in project gravitee-management-rest-api by gravitee-io.

the class ProcessPromotionOperationHandlerTest method shouldHandlePromotionRequestIfCannotWritePayload.

@Test
public void shouldHandlePromotionRequestIfCannotWritePayload() throws JsonProcessingException {
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.PROMOTE_API.name());
    command.setId(COMMAND_ID);
    command.setInstallationId(INSTALLATION_ID);
    command.setOrganizationId(ORGANIZATION_ID);
    command.setEnvironmentId(ENVIRONMENT_ID);
    command.setPayload(new BridgePayload());
    final BridgeTarget bridgeTarget = new BridgeTarget();
    bridgeTarget.setEnvironmentId("source");
    command.setTarget(bridgeTarget);
    when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenReturn(getAPromotionEntity());
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    when(objectMapper.writeValueAsString(any())).thenThrow(JsonProcessingException.class);
    when(promotionService.createOrUpdate(any())).thenReturn(getAPromotionEntity());
    // When
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    // Then
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR) && reply.getMessage().equals("Problem while serializing promotion for environment [" + ENVIRONMENT_ID + "]"));
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 13 with InstallationEntity

use of io.gravitee.rest.api.model.InstallationEntity in project gravitee-management-rest-api by gravitee-io.

the class ProcessPromotionOperationHandlerTest method shouldHandlePromotionRequest.

@Test
public void shouldHandlePromotionRequest() throws JsonProcessingException {
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.PROMOTE_API.name());
    command.setId(COMMAND_ID);
    command.setInstallationId(INSTALLATION_ID);
    command.setOrganizationId(ORGANIZATION_ID);
    command.setEnvironmentId(ENVIRONMENT_ID);
    command.setPayload(new BridgePayload());
    final BridgeTarget bridgeTarget = new BridgeTarget();
    bridgeTarget.setEnvironmentId("source");
    command.setTarget(bridgeTarget);
    ArgumentCaptor<PromotionEntity> argument = ArgumentCaptor.forClass(PromotionEntity.class);
    when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenReturn(getAPromotionEntity());
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    verify(promotionService, times(1)).createOrUpdate(argument.capture());
    Assertions.assertThat(argument.getValue().getStatus()).isEqualTo(PromotionEntityStatus.ACCEPTED);
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> {
        BridgeSimpleReply simpleReply = (BridgeSimpleReply) reply;
        return (simpleReply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && simpleReply.getOrganizationId().equals(ORGANIZATION_ID) && simpleReply.getEnvironmentId().equals("source") && simpleReply.getInstallationId().equals(INSTALLATION_ID) && simpleReply.getCommandId().equals(COMMAND_ID));
    });
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 14 with InstallationEntity

use of io.gravitee.rest.api.model.InstallationEntity 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)

Example 15 with InstallationEntity

use of io.gravitee.rest.api.model.InstallationEntity in project gravitee-management-rest-api by gravitee-io.

the class HelloCommandProducerTest method produce.

@Test
public void produce() {
    final InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    installationEntity.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
    when(node.hostname()).thenReturn(HOSTNAME);
    when(installationService.getOrInitialize()).thenReturn(installationEntity);
    final HelloCommand command = new HelloCommand();
    final HelloPayload payload = new HelloPayload();
    payload.setNode(new io.gravitee.cockpit.api.command.Node());
    command.setPayload(payload);
    final TestObserver<HelloCommand> obs = cut.prepare(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(helloCommand -> {
        assertEquals(CUSTOM_VALUE, helloCommand.getPayload().getAdditionalInformation().get(CUSTOM_KEY));
        assertTrue(helloCommand.getPayload().getAdditionalInformation().containsKey("UI_URL"));
        assertTrue(helloCommand.getPayload().getAdditionalInformation().containsKey("API_URL"));
        assertEquals(HOSTNAME, helloCommand.getPayload().getNode().getHostname());
        assertEquals(GraviteeContext.getDefaultOrganization(), helloCommand.getPayload().getDefaultOrganizationId());
        assertEquals(GraviteeContext.getDefaultEnvironment(), helloCommand.getPayload().getDefaultEnvironmentId());
        assertEquals(INSTALLATION_ID, helloCommand.getPayload().getNode().getInstallationId());
        assertEquals(HOSTNAME, helloCommand.getPayload().getNode().getHostname());
        return true;
    });
}
Also used : InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) HelloCommand(io.gravitee.cockpit.api.command.hello.HelloCommand) HelloPayload(io.gravitee.cockpit.api.command.hello.HelloPayload) Test(org.junit.Test)

Aggregations

InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)19 Test (org.junit.Test)15 BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)5 BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)5 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)4 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)4 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)3 GoodbyeCommand (io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand)3 GoodbyeReply (io.gravitee.cockpit.api.command.goodbye.GoodbyeReply)3 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 InstallationCommand (io.gravitee.cockpit.api.command.installation.InstallationCommand)2 InstallationPayload (io.gravitee.cockpit.api.command.installation.InstallationPayload)2 InstallationReply (io.gravitee.cockpit.api.command.installation.InstallationReply)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)1 HelloCommand (io.gravitee.cockpit.api.command.hello.HelloCommand)1 HelloPayload (io.gravitee.cockpit.api.command.hello.HelloPayload)1