Search in sources :

Example 6 with BridgeSimpleReply

use of io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply in project gravitee-management-rest-api by gravitee-io.

the class ProcessPromotionOperationHandler method handle.

@Override
public Single<BridgeReply> handle(BridgeCommand bridgeCommand) {
    BridgeSimpleReply reply = new BridgeSimpleReply();
    reply.setCommandId(bridgeCommand.getId());
    final PromotionEntity promotionEntity;
    try {
        promotionEntity = objectMapper.readValue(bridgeCommand.getPayload().getContent(), PromotionEntity.class);
    } catch (JsonProcessingException e) {
        logger.warn("Problem while deserializing promotion for environment {}", bridgeCommand.getEnvironmentId());
        reply.setCommandStatus(CommandStatus.ERROR);
        reply.setMessage("Problem while deserializing promotion for environment [" + bridgeCommand.getEnvironmentId() + "]");
        return Single.just(reply);
    }
    PromotionEntity promotion = promotionService.createOrUpdate(promotionEntity);
    reply.setCommandStatus(CommandStatus.SUCCEEDED);
    reply.setOrganizationId(bridgeCommand.getOrganizationId());
    reply.setEnvironmentId(bridgeCommand.getTarget().getEnvironmentId());
    reply.setInstallationId(installationService.get().getId());
    try {
        reply.setPayload(objectMapper.writeValueAsString(promotion));
    } catch (JsonProcessingException e) {
        logger.warn("Problem while serializing promotion for environment {}", promotion.getId());
        reply.setCommandStatus(CommandStatus.ERROR);
        reply.setMessage("Problem while serializing promotion for environment [" + bridgeCommand.getEnvironmentId() + "]");
        return Single.just(reply);
    }
    return Single.just(reply);
}
Also used : BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with BridgeSimpleReply

use of io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply in project gravitee-management-rest-api by gravitee-io.

the class PromoteApiOperationHandlerTest 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("target");
    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.TO_BE_VALIDATED);
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> {
        BridgeSimpleReply simpleReply = (BridgeSimpleReply) reply;
        return (simpleReply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && simpleReply.getOrganizationId().equals(ORGANIZATION_ID) && simpleReply.getEnvironmentId().equals("target") && 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 8 with BridgeSimpleReply

use of io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply 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 9 with BridgeSimpleReply

use of io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply in project gravitee-management-rest-api by gravitee-io.

the class CockpitServiceTest method shouldProcessPromotion.

@Test
public void shouldProcessPromotion() {
    BridgeReply reply = new BridgeSimpleReply();
    reply.setCommandStatus(CommandStatus.SUCCEEDED);
    when(cockpitCommandService.send(any())).thenReturn(reply);
    final PromotionEntity promotionEntity = new PromotionEntity();
    final CockpitReply<PromotionEntity> result = cockpitService.processPromotion(promotionEntity);
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(CockpitReplyStatus.SUCCEEDED);
    final PromotionEntity entity = result.getReply();
    assertThat(entity).isNotNull();
}
Also used : BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Aggregations

BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)9 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)6 Test (org.junit.Test)6 BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)3 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)3 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)3 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)3 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)2 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)2 PromotionTargetEntity (io.gravitee.rest.api.model.promotion.PromotionTargetEntity)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 List (java.util.List)1