Search in sources :

Example 16 with BridgeCommand

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

the class ListEnvironmentOperationHandlerTest method shouldNotListEnvironments.

@Test
public void shouldNotListEnvironments() {
    // Given
    when(environmentService.findByOrganization(ORGANIZATION_ID)).thenThrow(new TechnicalManagementException());
    BridgeCommand command = new BridgeCommand();
    command.setOrganizationId(ORGANIZATION_ID);
    // 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("No environment available for organization: " + ORGANIZATION_ID));
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 17 with BridgeCommand

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

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

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

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

the class BridgeCommandFactoryTest method shouldCreateListEnvironmentsCommand.

@Test
public void shouldCreateListEnvironmentsCommand() {
    // When
    final BridgeCommand listEnvironmentCommand = bridgeCommandFactory.createListEnvironmentCommand();
    // Then
    assertThat(listEnvironmentCommand).isNotNull();
    assertThat(listEnvironmentCommand.getEnvironmentId()).isEqualTo(ENVIRONMENT_ID);
    assertThat(listEnvironmentCommand.getOrganizationId()).isEqualTo(ORGANIZATION_ID);
    assertThat(listEnvironmentCommand.getInstallationId()).isEqualTo(INSTALLATION_ID);
    assertThat(listEnvironmentCommand.getOperation()).isEqualTo(BridgeOperation.LIST_ENVIRONMENT.name());
    final BridgeTarget bridgeTarget = listEnvironmentCommand.getTarget();
    assertThat(bridgeTarget).isNotNull();
    assertThat(bridgeTarget.getScopes()).isNotNull();
    assertThat(bridgeTarget.getScopes().size()).isEqualTo(1);
    assertThat(bridgeTarget.getScopes().get(0)).isEqualTo("APIM");
}
Also used : BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) 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