Search in sources :

Example 1 with OrganizationReply

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));
}
Also used : UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OrganizationService(io.gravitee.rest.api.service.OrganizationService) Command(io.gravitee.cockpit.api.command.Command) OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) OrganizationCommand(io.gravitee.cockpit.api.command.organization.OrganizationCommand) 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) OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) OrganizationCommand(io.gravitee.cockpit.api.command.organization.OrganizationCommand) Test(org.junit.Test)

Example 2 with OrganizationReply

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));
    }
}
Also used : OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity)

Example 3 with OrganizationReply

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));
}
Also used : OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationCommand(io.gravitee.cockpit.api.command.organization.OrganizationCommand) Test(org.junit.Test)

Aggregations

OrganizationPayload (io.gravitee.cockpit.api.command.organization.OrganizationPayload)3 OrganizationReply (io.gravitee.cockpit.api.command.organization.OrganizationReply)3 UpdateOrganizationEntity (io.gravitee.rest.api.model.UpdateOrganizationEntity)3 OrganizationCommand (io.gravitee.cockpit.api.command.organization.OrganizationCommand)2 OrganizationEntity (io.gravitee.rest.api.model.OrganizationEntity)2 Test (org.junit.Test)2 Command (io.gravitee.cockpit.api.command.Command)1 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)1 OrganizationService (io.gravitee.rest.api.service.OrganizationService)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