use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management 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.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.getHrids().equals(environmentPayload.getHrids()) && newEnvironment.getDescription().equals(environmentPayload.getDescription()) && newEnvironment.getName().equals(environmentPayload.getName()) && newEnvironment.getDomainRestrictions().equals(environmentPayload.getDomainRestrictions())), isNull())).thenReturn(Single.just(new Environment()));
TestObserver<EnvironmentReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management by gravitee-io.
the class EnvironmentCommandHandler method handle.
@Override
public Single<EnvironmentReply> handle(EnvironmentCommand command) {
EnvironmentPayload environmentPayload = command.getPayload();
NewEnvironment newEnvironment = new NewEnvironment();
newEnvironment.setHrids(environmentPayload.getHrids());
newEnvironment.setName(environmentPayload.getName());
newEnvironment.setDescription(environmentPayload.getDescription());
newEnvironment.setDomainRestrictions(environmentPayload.getDomainRestrictions());
return environmentService.createOrUpdate(environmentPayload.getOrganizationId(), environmentPayload.getId(), newEnvironment, null).map(organization -> new EnvironmentReply(command.getId(), CommandStatus.SUCCEEDED)).doOnSuccess(reply -> logger.info("Environment [{}] handled with id [{}].", environmentPayload.getName(), environmentPayload.getId())).doOnError(error -> logger.error("Error occurred when handling environment [{}] with id [{}].", environmentPayload.getName(), environmentPayload.getId(), error)).onErrorReturn(throwable -> new EnvironmentReply(command.getId(), CommandStatus.ERROR));
}
Aggregations