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