use of io.gravitee.rest.api.management.rest.model.GroupMembership in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateApiRole.
@Test
public void shouldUpdateApiRole() {
initUPDATEmock();
MemberRoleEntity apiRole = new MemberRoleEntity();
apiRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.API);
apiRole.setRoleName("CUSTOM_API");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Collections.singletonList(apiRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(any(), any(), any());
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.API, "CUSTOM_API"));
}
use of io.gravitee.rest.api.management.rest.model.GroupMembership in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateApplicationRole.
@Test
public void shouldUpdateApplicationRole() {
initUPDATEmock();
MemberRoleEntity appRole = new MemberRoleEntity();
appRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.APPLICATION);
appRole.setRoleName("CUSTOM_APP");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Collections.singletonList(appRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(any(), any(), any());
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, "CUSTOM_APP"));
}
use of io.gravitee.rest.api.management.rest.model.GroupMembership in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldAddMemberWithCustomApplicationRoleAndCustomApiRole.
@Test
public void shouldAddMemberWithCustomApplicationRoleAndCustomApiRole() {
initADDmock();
MemberRoleEntity apiRole = new MemberRoleEntity();
apiRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.API);
apiRole.setRoleName("CUSTOM_API");
MemberRoleEntity appRole = new MemberRoleEntity();
appRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.APPLICATION);
appRole.setRoleName("CUSTOM_APP");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Arrays.asList(apiRole, appRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.API, "CUSTOM_API"));
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, "CUSTOM_APP"));
}
use of io.gravitee.rest.api.management.rest.model.GroupMembership in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateNothing.
@Test
public void shouldUpdateNothing() {
initUPDATEmock();
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, never()).addRoleToMemberOnReference(any(), any(), any());
}
use of io.gravitee.rest.api.management.rest.model.GroupMembership in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResourceTest method shouldUpdateApiAndApplicationRole.
@Test
public void shouldUpdateApiAndApplicationRole() {
initUPDATEmock();
MemberRoleEntity apiRole = new MemberRoleEntity();
apiRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.API);
apiRole.setRoleName("CUSTOM_API");
MemberRoleEntity appRole = new MemberRoleEntity();
appRole.setRoleScope(io.gravitee.rest.api.model.permissions.RoleScope.APPLICATION);
appRole.setRoleName("CUSTOM_APP");
GroupMembership groupMembership = new GroupMembership();
groupMembership.setId(USERNAME);
groupMembership.setRoles(Arrays.asList(apiRole, appRole));
final Response response = envTarget().request().post(Entity.json(Collections.singleton(groupMembership)));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.API);
verify(roleService, never()).findDefaultRoleByScopes(RoleScope.APPLICATION);
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.API, "CUSTOM_API"));
verify(membershipService, times(1)).addRoleToMemberOnReference(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, GROUP_ID), new MembershipService.MembershipMember(USERNAME, null, MembershipMemberType.USER), new MembershipService.MembershipRole(RoleScope.APPLICATION, "CUSTOM_APP"));
}
Aggregations