use of io.gravitee.cockpit.api.command.bridge.BridgeReply in project gravitee-management-rest-api by gravitee-io.
the class CockpitServiceTest method shouldNotProcessPromotionCommandError.
@Test
public void shouldNotProcessPromotionCommandError() {
BridgeReply reply = new BridgeSimpleReply();
reply.setCommandStatus(CommandStatus.ERROR);
when(cockpitCommandService.send(any())).thenReturn(reply);
final CockpitReply<PromotionEntity> result = cockpitService.processPromotion(new PromotionEntity());
assertThat(result).isNotNull();
assertThat(result.getStatus()).isEqualTo(CockpitReplyStatus.ERROR);
final PromotionEntity entity = result.getReply();
assertThat(entity).isNull();
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply 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;
});
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply 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 + "]"));
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply 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 + "]"));
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply 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);
}
Aggregations