use of io.gravitee.am.model.common.event.Event in project gravitee-access-management by gravitee-io.
the class MembershipServiceTest method shouldCreate_primaryOwner.
@Test
public void shouldCreate_primaryOwner() {
Membership membership = new Membership();
membership.setReferenceId(DOMAIN_ID);
membership.setReferenceType(ReferenceType.DOMAIN);
membership.setMemberId("user-id");
membership.setMemberType(MemberType.USER);
membership.setRoleId("role-primary-owner");
User user = new User();
user.setReferenceId(ORGANIZATION_ID);
user.setReferenceType(ReferenceType.ORGANIZATION);
Role role = new Role();
role.setId("role-primary-owner");
role.setName(SystemRole.DOMAIN_PRIMARY_OWNER.name());
role.setReferenceId(Platform.DEFAULT);
role.setSystem(true);
role.setReferenceType(ReferenceType.PLATFORM);
role.setAssignableType(ReferenceType.DOMAIN);
when(userService.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, membership.getMemberId())).thenReturn(Single.just(user));
when(roleService.findById(role.getId())).thenReturn(Maybe.just(role));
when(membershipRepository.findByReferenceAndMember(membership.getReferenceType(), membership.getReferenceId(), membership.getMemberType(), membership.getMemberId())).thenReturn(Maybe.empty());
when(membershipRepository.create(any())).thenReturn(Single.just(new Membership()));
when(membershipRepository.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), argThat(criteria -> criteria.getRoleId().isPresent()))).thenReturn(Flowable.empty());
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = membershipService.addOrUpdate(ORGANIZATION_ID, membership).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
}
use of io.gravitee.am.model.common.event.Event in project gravitee-access-management by gravitee-io.
the class GroupServiceTest method shouldDelete_technicalException.
@Test
public void shouldDelete_technicalException() {
when(groupRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-group")).thenReturn(Maybe.just(new Group()));
when(groupRepository.delete("my-group")).thenReturn(Completable.error(TechnicalException::new));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = new TestObserver();
groupService.delete(ReferenceType.DOMAIN, DOMAIN, "my-group").subscribe(testObserver);
testObserver.assertError(TechnicalManagementException.class);
testObserver.assertNotComplete();
}
use of io.gravitee.am.model.common.event.Event in project gravitee-access-management by gravitee-io.
the class IdentityProviderServiceTest method shouldNotUpdate_notUpgrader_isSystem.
@Test
public void shouldNotUpdate_notUpgrader_isSystem() {
UpdateIdentityProvider updateIdentityProvider = (UpdateIdentityProvider) createIdentityProviders(true, false);
IdentityProvider identityProvider = (IdentityProvider) createIdentityProviders(false, true);
when(identityProviderRepository.findById(eq(ReferenceType.DOMAIN), eq(DOMAIN), eq("my-identity-provider"))).thenReturn(Maybe.just(identityProvider));
when(identityProviderRepository.update(any(IdentityProvider.class))).thenReturn(Single.just(identityProvider));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = identityProviderService.update(DOMAIN, "my-identity-provider", updateIdentityProvider, false).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
verify(identityProviderRepository, times(1)).update(argThat(upIdp -> upIdp.getConfiguration().equals("initial-config")));
verify(identityProviderRepository, times(1)).update(any(IdentityProvider.class));
verify(eventService, times(1)).create(any());
}
use of io.gravitee.am.model.common.event.Event in project gravitee-access-management by gravitee-io.
the class MembershipServiceTest method shouldCreate_groupMembership.
@Test
public void shouldCreate_groupMembership() {
Membership membership = new Membership();
membership.setReferenceId(DOMAIN_ID);
membership.setReferenceType(ReferenceType.DOMAIN);
membership.setMemberId("group-id");
membership.setMemberType(MemberType.GROUP);
membership.setRoleId("role-id");
Role role = new Role();
role.setId("role-id");
role.setReferenceId(DOMAIN_ID);
role.setReferenceType(ReferenceType.DOMAIN);
role.setAssignableType(ReferenceType.DOMAIN);
Group group = new Group();
group.setReferenceId(DOMAIN_ID);
group.setReferenceType(ReferenceType.DOMAIN);
when(groupService.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, membership.getMemberId())).thenReturn(Single.just(group));
when(roleService.findById(role.getId())).thenReturn(Maybe.just(role));
when(membershipRepository.findByReferenceAndMember(membership.getReferenceType(), membership.getReferenceId(), membership.getMemberType(), membership.getMemberId())).thenReturn(Maybe.empty());
when(membershipRepository.create(any())).thenReturn(Single.just(new Membership()));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver testObserver = membershipService.addOrUpdate(ORGANIZATION_ID, membership).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
}
use of io.gravitee.am.model.common.event.Event in project gravitee-access-management by gravitee-io.
the class EventServiceTest method shouldNotCreate_technicalException.
@Test
public void shouldNotCreate_technicalException() {
Event newEvent = Mockito.mock(Event.class);
when(eventRepository.create(any(Event.class))).thenReturn(Single.error(TechnicalException::new));
TestObserver testObserver = eventService.create(newEvent).test();
testObserver.awaitTerminalEvent();
testObserver.assertError(TechnicalManagementException.class);
testObserver.assertNotComplete();
}
Aggregations