Search in sources :

Example 1 with EnvironmentCommand

use of io.gravitee.cockpit.api.command.environment.EnvironmentCommand 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 2 with EnvironmentCommand

use of io.gravitee.cockpit.api.command.environment.EnvironmentCommand 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

EnvironmentCommand (io.gravitee.cockpit.api.command.environment.EnvironmentCommand)2 EnvironmentPayload (io.gravitee.cockpit.api.command.environment.EnvironmentPayload)2 EnvironmentReply (io.gravitee.cockpit.api.command.environment.EnvironmentReply)2 UpdateEnvironmentEntity (io.gravitee.rest.api.model.UpdateEnvironmentEntity)2 Test (org.junit.Test)2 Command (io.gravitee.cockpit.api.command.Command)1 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)1 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)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