use of io.gravitee.cockpit.api.command.organization.OrganizationReply 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.OrganizationReply in project gravitee-management-rest-api by gravitee-io.
the class OrganizationCommandHandler method handle.
@Override
public Single<OrganizationReply> handle(OrganizationCommand command) {
OrganizationPayload organizationPayload = command.getPayload();
try {
UpdateOrganizationEntity newOrganization = new UpdateOrganizationEntity();
newOrganization.setCockpitId(organizationPayload.getCockpitId());
newOrganization.setHrids(organizationPayload.getHrids());
newOrganization.setName(organizationPayload.getName());
newOrganization.setDescription(organizationPayload.getDescription());
newOrganization.setDomainRestrictions(organizationPayload.getDomainRestrictions());
final OrganizationEntity organization = organizationService.createOrUpdate(organizationPayload.getId(), newOrganization);
logger.info("Organization [{}] handled with id [{}].", organization.getName(), organization.getId());
return Single.just(new OrganizationReply(command.getId(), CommandStatus.SUCCEEDED));
} catch (Exception e) {
logger.error("Error occurred when handling organization [{}] with id [{}].", organizationPayload.getName(), organizationPayload.getId(), e);
return Single.just(new OrganizationReply(command.getId(), CommandStatus.ERROR));
}
}
use of io.gravitee.cockpit.api.command.organization.OrganizationReply 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