Search in sources :

Example 1 with EnvironmentPayload

use of io.gravitee.cockpit.api.command.environment.EnvironmentPayload 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));
    }
}
Also used : UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload)

Example 2 with EnvironmentPayload

use of io.gravitee.cockpit.api.command.environment.EnvironmentPayload 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));
}
Also used : UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Test(org.junit.Test)

Example 3 with EnvironmentPayload

use of io.gravitee.cockpit.api.command.environment.EnvironmentPayload 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));
}
Also used : EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Command(io.gravitee.cockpit.api.command.Command) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) 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) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Test(org.junit.Test)

Aggregations

EnvironmentPayload (io.gravitee.cockpit.api.command.environment.EnvironmentPayload)3 EnvironmentReply (io.gravitee.cockpit.api.command.environment.EnvironmentReply)3 UpdateEnvironmentEntity (io.gravitee.rest.api.model.UpdateEnvironmentEntity)3 EnvironmentCommand (io.gravitee.cockpit.api.command.environment.EnvironmentCommand)2 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)2 Test (org.junit.Test)2 Command (io.gravitee.cockpit.api.command.Command)1 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)1 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)1 TestObserver (io.reactivex.observers.TestObserver)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 Mock (org.mockito.Mock)1 Mockito.when (org.mockito.Mockito.when)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1