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));
}
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));
}
Aggregations