use of io.gravitee.cockpit.api.command.environment.EnvironmentReply in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentCommandHandler method handle.
@Override
public Single<EnvironmentReply> handle(EnvironmentCommand command) {
EnvironmentPayload environmentPayload = command.getPayload();
try {
UpdateEnvironmentEntity newEnvironment = new UpdateEnvironmentEntity();
newEnvironment.setCockpitId(environmentPayload.getCockpitId());
newEnvironment.setHrids(environmentPayload.getHrids());
newEnvironment.setName(environmentPayload.getName());
newEnvironment.setDescription(environmentPayload.getDescription());
newEnvironment.setDomainRestrictions(environmentPayload.getDomainRestrictions());
final EnvironmentEntity environment = environmentService.createOrUpdate(environmentPayload.getOrganizationId(), environmentPayload.getId(), newEnvironment);
logger.info("Environment [{}] handled with id [{}].", environment.getName(), environment.getId());
return Single.just(new EnvironmentReply(command.getId(), CommandStatus.SUCCEEDED));
} catch (Exception e) {
logger.error("Error occurred when handling environment [{}] with id [{}].", environmentPayload.getName(), environmentPayload.getId(), e);
return Single.just(new EnvironmentReply(command.getId(), CommandStatus.ERROR));
}
}
use of io.gravitee.cockpit.api.command.environment.EnvironmentReply in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentCommandHandlerTest method handleWithException.
@Test
public void handleWithException() {
EnvironmentPayload environmentPayload = new EnvironmentPayload();
EnvironmentCommand command = new EnvironmentCommand(environmentPayload);
environmentPayload.setId("env#1");
environmentPayload.setCockpitId("env#cockpit-1");
environmentPayload.setOrganizationId("orga#1");
environmentPayload.setDescription("Environment description");
environmentPayload.setName("Environment name");
environmentPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(environmentService.createOrUpdate(eq("orga#1"), eq("env#1"), any(UpdateEnvironmentEntity.class))).thenThrow(new RuntimeException("fake error"));
TestObserver<EnvironmentReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertNoErrors();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
use of io.gravitee.cockpit.api.command.environment.EnvironmentReply in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentCommandHandlerTest method handle.
@Test
public void handle() {
EnvironmentPayload environmentPayload = new EnvironmentPayload();
EnvironmentCommand command = new EnvironmentCommand(environmentPayload);
environmentPayload.setId("env#1");
environmentPayload.setCockpitId("env#cockpit-1");
environmentPayload.setHrids(Collections.singletonList("env-1"));
environmentPayload.setOrganizationId("orga#1");
environmentPayload.setDescription("Environment description");
environmentPayload.setName("Environment name");
environmentPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(environmentService.createOrUpdate(eq("orga#1"), eq("env#1"), argThat(newEnvironment -> newEnvironment.getCockpitId().equals(environmentPayload.getCockpitId()) && newEnvironment.getHrids().equals(environmentPayload.getHrids()) && newEnvironment.getDescription().equals(environmentPayload.getDescription()) && newEnvironment.getName().equals(environmentPayload.getName()) && newEnvironment.getDomainRestrictions().equals(environmentPayload.getDomainRestrictions())))).thenReturn(new EnvironmentEntity());
TestObserver<EnvironmentReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
Aggregations