Search in sources :

Example 1 with BridgeCommand

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

the class BridgeCommandFactory method createListEnvironmentCommand.

public BridgeCommand createListEnvironmentCommand() {
    BridgeCommand listEnvironmentCommand = initBridgeCommand();
    BridgeTarget target = new BridgeTarget();
    target.setScopes(Collections.singletonList(BRIDGE_SCOPE_APIM));
    listEnvironmentCommand.setTarget(target);
    listEnvironmentCommand.setOperation(BridgeOperation.LIST_ENVIRONMENT.name());
    return listEnvironmentCommand;
}
Also used : BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand)

Example 2 with BridgeCommand

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

the class BridgeCommandFactory method initBridgeCommand.

private BridgeCommand initBridgeCommand() {
    BridgeCommand command = new BridgeCommand();
    command.setEnvironmentId(GraviteeContext.getCurrentEnvironment());
    command.setOrganizationId(GraviteeContext.getCurrentOrganization());
    command.setInstallationId(installationService.get().getId());
    return command;
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand)

Example 3 with BridgeCommand

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

the class BridgeCommandFactoryTest method shouldCreatePromoteApiCommand.

@Test
public void shouldCreatePromoteApiCommand() {
    PromotionEntity promotionEntity = new PromotionEntity();
    promotionEntity.setTargetEnvCockpitId("env#target");
    final BridgeCommand promoteApiCommand = bridgeCommandFactory.createPromoteApiCommand("env#target", "{ \"id\": \"test\"}");
    assertThat(promoteApiCommand).isNotNull();
    assertThat(promoteApiCommand.getEnvironmentId()).isEqualTo(ENVIRONMENT_ID);
    assertThat(promoteApiCommand.getOrganizationId()).isEqualTo(ORGANIZATION_ID);
    assertThat(promoteApiCommand.getInstallationId()).isEqualTo(INSTALLATION_ID);
    assertThat(promoteApiCommand.getOperation()).isEqualTo(BridgeOperation.PROMOTE_API.name());
    assertThat(promoteApiCommand.getPayload().getContent()).isEqualTo("{ \"id\": \"test\"}");
    final BridgeTarget bridgeTarget = promoteApiCommand.getTarget();
    assertThat(bridgeTarget.getEnvironmentId()).isEqualTo("env#target");
}
Also used : BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) Test(org.junit.Test)

Example 4 with BridgeCommand

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

the class ListEnvironmentOperationHandlerTest method shouldListEnvironments.

@Test
public void shouldListEnvironments() throws JsonProcessingException {
    // Given
    EnvironmentEntity envA = new EnvironmentEntity();
    envA.setId("my-env-A");
    envA.setOrganizationId(ORGANIZATION_ID);
    envA.setName("ENV A");
    EnvironmentEntity envB = new EnvironmentEntity();
    envB.setId("my-env-B");
    envB.setOrganizationId(ORGANIZATION_ID);
    envB.setName("ENV B");
    EnvironmentEntity envC_ERROR = new EnvironmentEntity();
    envC_ERROR.setId("my-env-C");
    envC_ERROR.setOrganizationId(ORGANIZATION_ID);
    envC_ERROR.setName("ENV C");
    when(environmentService.findByOrganization(ORGANIZATION_ID)).thenReturn(Arrays.asList(envA, envB, envC_ERROR));
    when(objectMapper.writeValueAsString(envA)).thenReturn("envA");
    when(objectMapper.writeValueAsString(envB)).thenReturn("envB");
    when(objectMapper.writeValueAsString(envC_ERROR)).thenThrow(new JsonProcessingException("") {
    });
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.LIST_ENVIRONMENT.name());
    command.setId(COMMAND_ID);
    command.setInstallationId(INSTALLATION_ID);
    command.setOrganizationId(ORGANIZATION_ID);
    command.setEnvironmentId(ENVIRONMENT_ID);
    // When
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    // Then
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> {
        if (reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && BridgeMultiReply.class.isInstance(reply)) {
            BridgeMultiReply multiReply = ((BridgeMultiReply) reply);
            if (multiReply.getReplies() != null && multiReply.getReplies().size() == 3) {
                for (BridgeSimpleReply simpleReply : multiReply.getReplies()) {
                    if (simpleReply.getEnvironmentId().equals(envA.getId()) && simpleReply.getCommandStatus() == CommandStatus.ERROR) {
                        return false;
                    }
                    if (simpleReply.getEnvironmentId().equals(envB.getId()) && simpleReply.getCommandStatus() == CommandStatus.ERROR) {
                        return false;
                    }
                    if (simpleReply.getEnvironmentId().equals(envC_ERROR.getId()) && simpleReply.getCommandStatus() == CommandStatus.SUCCEEDED) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    });
}
Also used : BridgeMultiReply(io.gravitee.cockpit.api.command.bridge.BridgeMultiReply) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 5 with BridgeCommand

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

the class PromoteApiOperationHandlerTest method shouldHandlePromotionRequestIfCannotReadPromotionEntity.

@Test
public void shouldHandlePromotionRequestIfCannotReadPromotionEntity() 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);
    when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenThrow(JsonMappingException.class);
    // 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 deserializing promotion request for environment [" + ENVIRONMENT_ID + "]"));
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) 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)

Aggregations

BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)20 BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)14 Test (org.junit.Test)13 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)12 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)9 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)4 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)3 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)2 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)1 PromotionTargetEntity (io.gravitee.rest.api.model.promotion.PromotionTargetEntity)1 CockpitCommandService (io.gravitee.rest.api.service.cockpit.command.CockpitCommandService)1 BridgeCommandFactory (io.gravitee.rest.api.service.cockpit.command.bridge.BridgeCommandFactory)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1