use of io.gravitee.cockpit.api.command.organization.OrganizationCommand in project gravitee-management-rest-api by gravitee-io.
the class OrganizationCommandHandlerTest method handle.
@Test
public void handle() {
OrganizationPayload organizationPayload = new OrganizationPayload();
OrganizationCommand command = new OrganizationCommand(organizationPayload);
organizationPayload.setId("orga#1");
organizationPayload.setCockpitId("org#cockpit-1");
organizationPayload.setHrids(Collections.singletonList("orga-1"));
organizationPayload.setDescription("Organization description");
organizationPayload.setName("Organization name");
organizationPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(organizationService.createOrUpdate(eq("orga#1"), argThat(newOrganization -> newOrganization.getCockpitId().equals(organizationPayload.getCockpitId()) && newOrganization.getHrids().equals(organizationPayload.getHrids()) && newOrganization.getDescription().equals(organizationPayload.getDescription()) && newOrganization.getName().equals(organizationPayload.getName()) && newOrganization.getDomainRestrictions().equals(organizationPayload.getDomainRestrictions())))).thenReturn(new OrganizationEntity());
TestObserver<OrganizationReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
use of io.gravitee.cockpit.api.command.organization.OrganizationCommand in project gravitee-management-rest-api by gravitee-io.
the class OrganizationCommandHandlerTest method handleWithException.
@Test
public void handleWithException() {
OrganizationPayload organizationPayload = new OrganizationPayload();
OrganizationCommand command = new OrganizationCommand(organizationPayload);
organizationPayload.setId("orga#1");
organizationPayload.setDescription("Organization description");
organizationPayload.setName("Organization name");
organizationPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(organizationService.createOrUpdate(eq("orga#1"), any(UpdateOrganizationEntity.class))).thenThrow(new RuntimeException("fake error"));
TestObserver<OrganizationReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertNoErrors();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
Aggregations