use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.
the class ApplicationMembersResource method convert.
private Membership convert(NewMembership newMembership) {
Membership membership = new Membership();
membership.setMemberId(newMembership.getMemberId());
membership.setMemberType(newMembership.getMemberType());
membership.setRoleId(newMembership.getRole());
return membership;
}
use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.
the class MembershipServiceTest method shouldAddDomainUserRole.
@Test
public void shouldAddDomainUserRole() {
NewMembership membership = new NewMembership();
membership.setMemberType(MemberType.USER);
membership.setMemberId("user#1");
DefaultUser principal = new DefaultUser("username");
principal.setId("user#1");
User user = new User();
user.setReferenceId(ORGANIZATION_ID);
user.setReferenceType(ReferenceType.ORGANIZATION);
Role environmentUserRole = new Role();
environmentUserRole.setId("role#1");
when(membershipRepository.findByCriteria(eq(ReferenceType.DOMAIN), eq("domain#1"), any(MembershipCriteria.class))).thenReturn(Flowable.empty());
when(roleService.findDefaultRole("orga#1", DefaultRole.DOMAIN_USER, ReferenceType.DOMAIN)).thenReturn(Maybe.just(environmentUserRole));
when(membershipRepository.create(any())).thenReturn(Single.just(new Membership()));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
when(membershipRepository.findByCriteria(eq(ReferenceType.ENVIRONMENT), eq("env#1"), any(MembershipCriteria.class))).thenReturn(Flowable.empty());
when(roleService.findDefaultRole("orga#1", DefaultRole.ENVIRONMENT_USER, ReferenceType.ENVIRONMENT)).thenReturn(Maybe.just(environmentUserRole));
TestObserver<Void> completable = membershipService.addDomainUserRoleIfNecessary("orga#1", "env#1", "domain#1", membership, principal).test();
completable.awaitTerminalEvent();
completable.assertNoErrors();
completable.assertComplete();
}
use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.
the class MembershipServiceTest method shouldAddEnvironmentUserRole.
@Test
public void shouldAddEnvironmentUserRole() {
NewMembership membership = new NewMembership();
membership.setMemberType(MemberType.USER);
membership.setMemberId("user#1");
DefaultUser principal = new DefaultUser("username");
principal.setId("user#1");
User user = new User();
user.setReferenceId(ORGANIZATION_ID);
user.setReferenceType(ReferenceType.ORGANIZATION);
Role environmentUserRole = new Role();
environmentUserRole.setId("role#1");
when(membershipRepository.findByCriteria(eq(ReferenceType.ENVIRONMENT), eq("env#1"), any(MembershipCriteria.class))).thenReturn(Flowable.empty());
when(roleService.findDefaultRole("orga#1", DefaultRole.ENVIRONMENT_USER, ReferenceType.ENVIRONMENT)).thenReturn(Maybe.just(environmentUserRole));
when(membershipRepository.create(any())).thenReturn(Single.just(new Membership()));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver<Void> completable = membershipService.addEnvironmentUserRoleIfNecessary("orga#1", "env#1", membership, principal).test();
completable.awaitTerminalEvent();
completable.assertNoErrors();
completable.assertComplete();
}
use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.
the class MembershipServiceTest method shouldNotAddDomainUserRole_userAlreadyHasMembership.
@Test
public void shouldNotAddDomainUserRole_userAlreadyHasMembership() {
NewMembership membership = new NewMembership();
membership.setMemberType(MemberType.USER);
membership.setMemberId("user#1");
DefaultUser principal = new DefaultUser("username");
principal.setId("user#1");
User user = new User();
user.setReferenceId(ORGANIZATION_ID);
user.setReferenceType(ReferenceType.ORGANIZATION);
Role environmentUserRole = new Role();
environmentUserRole.setId("role#1");
when(membershipRepository.findByCriteria(eq(ReferenceType.ENVIRONMENT), eq("env#1"), any(MembershipCriteria.class))).thenReturn(Flowable.just(new Membership()));
when(membershipRepository.findByCriteria(eq(ReferenceType.DOMAIN), eq("domain#1"), any(MembershipCriteria.class))).thenReturn(Flowable.just(new Membership()));
TestObserver<Void> completable = membershipService.addDomainUserRoleIfNecessary("orga#1", "env#1", "domain#1", membership, principal).test();
completable.awaitTerminalEvent();
completable.assertNoErrors();
completable.assertComplete();
verify(membershipRepository, times(0)).create(any());
verifyZeroInteractions(auditService);
}
use of io.gravitee.am.service.model.NewMembership in project gravitee-access-management by gravitee-io.
the class MembersResourceTest method shouldNotAddMember_invalidInput.
@Test
public void shouldNotAddMember_invalidInput() {
Organization organization = new Organization();
organization.setId(Organization.DEFAULT);
Membership membership = new Membership();
membership.setId("membership-1");
doReturn(Single.just(organization)).when(organizationService).findById(organization.getId());
doReturn(Single.just(membership)).when(membershipService).addOrUpdate(eq(organization.getId()), any(Membership.class), any(io.gravitee.am.identityprovider.api.User.class));
// invalid input.
NewMembership newMembership = new NewMembership();
final Response response = target("organizations").path(organization.getId()).path("members").request().post(Entity.json(newMembership));
assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
}
Aggregations