Search in sources :

Example 6 with BridgeCommand

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

the class PromoteApiOperationHandlerTest 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("target");
    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 request 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 7 with BridgeCommand

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

the class CockpitCommandServiceTest method shouldSendCommandToCockpitConnector.

@Test
public void shouldSendCommandToCockpitConnector() {
    BridgePayload payload = new BridgePayload();
    payload.setContent("a content");
    BridgeCommand command = new BridgeCommand();
    command.setId(UUID.toString(UUID.random()));
    command.setInstallationId(UUID.toString(UUID.random()));
    command.setOrganizationId(UUID.toString(UUID.random()));
    command.setOperation("an_operation");
    command.setTarget(new BridgeTarget());
    command.setPayload(payload);
    BridgeReply reply = mock(BridgeReply.class);
    when(cockpitConnector.sendCommand(command)).thenReturn(Single.just(reply));
    BridgeReply bridgeReply = cockpitCommandService.send(command);
    assertThat(bridgeReply).isEqualTo(reply);
}
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)

Example 8 with BridgeCommand

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

the class BridgeCommandHandlerTest method shouldNotHandleUnknownOperation.

@Test
public void shouldNotHandleUnknownOperation() {
    BridgeCommand command = new BridgeCommand();
    command.setOperation("UNKWOWN_OPERATION");
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR) && reply.getMessage().equals("No handler found for this operation: UNKWOWN_OPERATION"));
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 9 with BridgeCommand

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

the class BridgeCommandHandlerTest method shouldHandleListEnvironmentsOperation.

@Test
public void shouldHandleListEnvironmentsOperation() {
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.LIST_ENVIRONMENT.name());
    command.setId("command-id");
    cut = new BridgeCommandHandler(Arrays.asList(new TestingFakeListEnvironmentOperationHandler(), new AnotherTestingFakeOperationHandler()));
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && reply.getMessage().equals("Fake operation handler"));
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 10 with BridgeCommand

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

the class ProcessPromotionOperationHandlerTest 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("source");
    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 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