Search in sources :

Example 6 with NewEnvironment

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));
}
Also used : EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) EnvironmentService(io.gravitee.am.service.EnvironmentService) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Environment(io.gravitee.am.model.Environment) Mockito.when(org.mockito.Mockito.when) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Single(io.reactivex.Single) Command(io.gravitee.cockpit.api.command.Command) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) NewEnvironment(io.gravitee.am.service.model.NewEnvironment) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) Environment(io.gravitee.am.model.Environment) NewEnvironment(io.gravitee.am.service.model.NewEnvironment) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Test(org.junit.Test)

Example 7 with NewEnvironment

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));
}
Also used : NewEnvironment(io.gravitee.am.service.model.NewEnvironment) EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) EnvironmentService(io.gravitee.am.service.EnvironmentService) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Single(io.reactivex.Single) Command(io.gravitee.cockpit.api.command.Command) Component(org.springframework.stereotype.Component) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) Stream(java.util.stream.Stream) NewEnvironment(io.gravitee.am.service.model.NewEnvironment) CommandHandler(io.gravitee.cockpit.api.command.CommandHandler) CollectionUtils(org.springframework.util.CollectionUtils) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload)

Aggregations

NewEnvironment (io.gravitee.am.service.model.NewEnvironment)7 Environment (io.gravitee.am.model.Environment)6 Single (io.reactivex.Single)6 Test (org.junit.Test)6 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)5 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)5 OrganizationNotFoundException (io.gravitee.am.service.exception.OrganizationNotFoundException)5 TestObserver (io.reactivex.observers.TestObserver)5 Collections (java.util.Collections)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Before (org.junit.Before)5 RunWith (org.junit.runner.RunWith)5 Mock (org.mockito.Mock)5 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 EventType (io.gravitee.am.common.audit.EventType)4 Status (io.gravitee.am.common.audit.Status)4 Organization (io.gravitee.am.model.Organization)4 ReferenceType (io.gravitee.am.model.ReferenceType)4 Audit (io.gravitee.am.reporter.api.audit.model.Audit)4