Search in sources :

Example 1 with GroupMembership

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.management.service.MembershipService) GroupMembership(io.gravitee.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 2 with GroupMembership

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.management.service.MembershipService) GroupMembership(io.gravitee.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 3 with GroupMembership

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());
}
Also used : Response(javax.ws.rs.core.Response) GroupMembership(io.gravitee.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 4 with GroupMembership

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.management.service.MembershipService) GroupMembership(io.gravitee.management.rest.model.GroupMembership) Test(org.junit.Test)

Example 5 with GroupMembership

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"));
}
Also used : Response(javax.ws.rs.core.Response) MembershipService(io.gravitee.management.service.MembershipService) GroupMembership(io.gravitee.management.rest.model.GroupMembership) Test(org.junit.Test)

Aggregations

GroupMembership (io.gravitee.management.rest.model.GroupMembership)5 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 MembershipService (io.gravitee.management.service.MembershipService)4