use of io.gravitee.am.model.Organization in project gravitee-access-management by gravitee-io.
the class OrganizationServiceTest method shouldFindById.
@Test
public void shouldFindById() {
Organization organization = new Organization();
when(organizationRepository.findById(ORGANIZATION_ID)).thenReturn(Maybe.just(organization));
TestObserver<Organization> obs = cut.findById(ORGANIZATION_ID).test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertValue(organization);
}
use of io.gravitee.am.model.Organization in project gravitee-access-management by gravitee-io.
the class OrganizationServiceTest method shouldCreate_updateError.
@Test
public void shouldCreate_updateError() {
Organization existingOrganization = new Organization();
existingOrganization.setId(ORGANIZATION_ID);
when(organizationRepository.findById(ORGANIZATION_ID)).thenReturn(Maybe.just(existingOrganization));
when(organizationRepository.update(argThat(organization -> organization.getId().equals(ORGANIZATION_ID)))).thenReturn(Single.error(new TechnicalManagementException()));
NewOrganization newOrganization = new NewOrganization();
newOrganization.setName("TestName");
newOrganization.setDescription("TestDescription");
newOrganization.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Organization> obs = cut.createOrUpdate(ORGANIZATION_ID, newOrganization, createdBy).test();
obs.awaitTerminalEvent();
obs.assertError(TechnicalManagementException.class);
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(ORGANIZATION_ID, audit.getReferenceId());
assertEquals(createdBy.getId(), audit.getActor().getId());
assertEquals(EventType.ORGANIZATION_UPDATED, audit.getType());
assertEquals(Status.FAILURE, audit.getOutcome().getStatus());
return true;
}));
}
use of io.gravitee.am.model.Organization in project gravitee-access-management by gravitee-io.
the class OrganizationServiceTest method shouldCreate_update.
@Test
public void shouldCreate_update() {
Organization existingOrganization = new Organization();
existingOrganization.setId(ORGANIZATION_ID);
when(organizationRepository.findById(ORGANIZATION_ID)).thenReturn(Maybe.just(existingOrganization));
when(organizationRepository.update(argThat(organization -> organization.getId().equals(ORGANIZATION_ID)))).thenAnswer(i -> Single.just(i.getArgument(0)));
NewOrganization newOrganization = new NewOrganization();
newOrganization.setName("TestName");
newOrganization.setDescription("TestDescription");
newOrganization.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
newOrganization.setHrids(Collections.singletonList("TestHridUpdate"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Organization> obs = cut.createOrUpdate(ORGANIZATION_ID, newOrganization, createdBy).test();
obs.awaitTerminalEvent();
obs.assertValue(organization -> {
assertEquals(ORGANIZATION_ID, organization.getId());
assertEquals(newOrganization.getName(), organization.getName());
assertEquals(newOrganization.getDescription(), organization.getDescription());
assertEquals(newOrganization.getDomainRestrictions(), organization.getDomainRestrictions());
assertEquals(newOrganization.getHrids(), organization.getHrids());
return true;
});
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(ORGANIZATION_ID, audit.getReferenceId());
assertEquals(createdBy.getId(), audit.getActor().getId());
assertEquals(EventType.ORGANIZATION_UPDATED, audit.getType());
assertEquals(Status.SUCCESS, audit.getOutcome().getStatus());
return true;
}));
}
use of io.gravitee.am.model.Organization in project gravitee-access-management by gravitee-io.
the class OrganizationServiceTest method shouldCreateDefault_OrganizationsAlreadyExists.
@Test
public void shouldCreateDefault_OrganizationsAlreadyExists() {
Organization defaultOrganization = new Organization();
defaultOrganization.setId(Organization.DEFAULT);
when(organizationRepository.count()).thenReturn(Single.just(1L));
TestObserver<Organization> obs = cut.createDefault().test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertNoValues();
verify(organizationRepository, times(1)).count();
verifyNoMoreInteractions(organizationRepository);
verifyZeroInteractions(auditService);
}
use of io.gravitee.am.model.Organization in project gravitee-access-management by gravitee-io.
the class OrganizationServiceTest method shouldNotCreateDefault_error.
@Test
public void shouldNotCreateDefault_error() {
Organization defaultOrganization = new Organization();
defaultOrganization.setId("DEFAULT");
when(organizationRepository.count()).thenReturn(Single.just(0L));
when(organizationRepository.create(argThat(organization -> organization.getId().equals(Organization.DEFAULT)))).thenReturn(Single.error(new TechnicalManagementException()));
TestObserver<Organization> obs = cut.createDefault().test();
obs.awaitTerminalEvent();
obs.assertError(TechnicalManagementException.class);
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(defaultOrganization.getId(), audit.getReferenceId());
assertEquals("system", audit.getActor().getId());
assertEquals(Status.FAILURE, audit.getOutcome().getStatus());
return true;
}));
}
Aggregations