use of org.alfresco.rest.api.tests.client.data.Group in project alfresco-remote-api by Alfresco.
the class GroupsTest method shouldNotAllowWildcards.
private void shouldNotAllowWildcards() throws Exception {
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("where", "(displayName in ('*'))");
ListResponse<Group> response = getGroups(paging, otherParams);
List<Group> groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(isRoot=true AND displayName in ('*'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(displayName in ('A*'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(isRoot=true AND displayName in ('A*'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(displayName in ('*roup'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(isRoot=true AND displayName in ('*roup'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(displayName in ('Root ?ROUP'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(isRoot=true AND displayName in ('Root ?ROUP'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(displayName in ('Group'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
otherParams.put("where", "(isRoot=true AND displayName in ('Group'))");
response = getGroups(paging, otherParams);
groups = response.getList();
assertEquals(0, groups.size());
}
use of org.alfresco.rest.api.tests.client.data.Group in project alfresco-remote-api by Alfresco.
the class GroupsTest method shouldFilterGroupByDisplayNameWhenGroupIsRoot.
private void shouldFilterGroupByDisplayNameWhenGroupIsRoot() throws Exception {
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("where", "(isRoot=true AND displayName in ('Root Group'))");
ListResponse<Group> response = getGroups(paging, otherParams);
List<Group> groups = response.getList();
assertEquals(1, groups.size());
assertEquals("Root Group", groups.get(0).getDisplayName());
}
use of org.alfresco.rest.api.tests.client.data.Group in project alfresco-remote-api by Alfresco.
the class GroupsTest method canGetGroupsForUserId.
private void canGetGroupsForUserId() throws Exception {
Person personAlice;
{
publicApiClient.setRequestContext(new RequestContext(networkOne.getId(), networkAdmin, "admin"));
personAlice = new Person();
String aliceId = "alice-" + UUID.randomUUID() + "@" + networkOne.getId();
personAlice.setUserName(aliceId);
personAlice.setId(aliceId);
personAlice.setFirstName("Alice");
personAlice.setEmail("alison.smith@example.com");
personAlice.setPassword("password");
personAlice.setEnabled(true);
PublicApiClient.People people = publicApiClient.people();
people.create(personAlice);
}
Groups groupsProxy = publicApiClient.groups();
// As admin
setRequestContext(networkOne.getId(), networkAdmin, "admin");
// New user has only the one default group.
{
ListResponse<Group> groups = groupsProxy.getGroupsByPersonId(personAlice.getId(), null, "Couldn't get user's groups", 200);
assertEquals(1L, (long) groups.getPaging().getTotalItems());
Iterator<Group> it = groups.getList().iterator();
assertEquals(GROUP_EVERYONE, it.next().getId());
}
// Add the user to a couple more groups and list them.
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
authorityService.addAuthority(groupA.getId(), personAlice.getId());
authorityService.addAuthority(groupB.getId(), personAlice.getId());
ListResponse<Group> groups = groupsProxy.getGroupsByPersonId(personAlice.getId(), null, "Couldn't get user's groups", 200);
assertEquals(4L, (long) groups.getPaging().getTotalItems());
Iterator<Group> it = groups.getList().iterator();
assertEquals(groupA, it.next());
assertEquals(groupB, it.next());
assertEquals(GROUP_EVERYONE, it.next().getId());
assertEquals(rootGroup, it.next());
}
{
Group aardvark = new Group();
try {
aardvark.setId("GROUP_AARDVARK");
aardvark.setDisplayName("Aardvark");
authorityService.createAuthority(AuthorityType.GROUP, aardvark.getId());
authorityService.setAuthorityDisplayName(aardvark.getId(), aardvark.getDisplayName());
Person personBob;
personBob = new Person();
String bobId = "bob-" + UUID.randomUUID() + "@" + networkOne.getId();
personBob.setUserName(bobId);
personBob.setId(bobId);
personBob.setFirstName("Bob");
personBob.setEmail("bob.cratchet@example.com");
personBob.setPassword("password");
personBob.setEnabled(true);
PublicApiClient.People people = publicApiClient.people();
people.create(personBob);
authorityService.addAuthority(aardvark.getId(), personBob.getId());
// Check sorting by ID when groups have no display name (REPO-1844)
// We don't want the GROUP_EVERYONE group to be sorted as an empty string, for example,
// which is what the comparator was doing.
Map<String, String> params = new HashMap<>();
addOrderBy(params, org.alfresco.rest.api.Groups.PARAM_ID, true);
ListResponse<Group> groups = groupsProxy.getGroupsByPersonId(personBob.getId(), params, "Couldn't get user's groups", 200);
assertEquals(2L, (long) groups.getPaging().getTotalItems());
Iterator<Group> it = groups.getList().iterator();
assertEquals(aardvark.getId(), it.next().getId());
assertEquals("GROUP_EVERYONE", it.next().getId());
} finally {
authorityService.deleteAuthority(aardvark.getId());
}
}
// Get network admin's groups by explicit ID.
{
ListResponse<Group> groups = groupsProxy.getGroupsByPersonId(networkAdmin, null, "Couldn't get user's groups", 200);
assertEquals(6L, (long) groups.getPaging().getTotalItems());
}
// test -me- alias (as network admin)
{
ListResponse<Group> groups = groupsProxy.getGroupsByPersonId("-me-", null, "Couldn't get user's groups", 200);
assertEquals(6L, (long) groups.getPaging().getCount());
Iterator<Group> it = groups.getList().iterator();
assertEquals("GROUP_ALFRESCO_ADMINISTRATORS", it.next().getId());
}
// Filter by isRoot
{
Map<String, String> params = new HashMap<>();
params.put("where", "(isRoot=true)");
ListResponse<Group> response = groupsProxy.getGroupsByPersonId("-me-", params, "Couldn't get user's groups", 200);
List<Group> groups = response.getList();
assertFalse(groups.isEmpty());
// All groups should be root groups.
groups.forEach(group -> assertTrue(group.getIsRoot()));
params.put("where", "(isRoot=false)");
response = groupsProxy.getGroupsByPersonId("-me-", params, "Couldn't get user's groups", 200);
groups = response.getList();
assertFalse(groups.isEmpty());
// All groups should be non-root groups.
groups.forEach(group -> assertFalse(group.getIsRoot()));
}
// -ve test: attempt to get groups for non-existent person
{
groupsProxy.getGroupsByPersonId("i-do-not-exist", null, "Incorrect response", 404);
}
// As Alice
setRequestContext(networkOne.getId(), personAlice.getId(), "password");
// test -me- alias as Alice
{
ListResponse<Group> groups = groupsProxy.getGroupsByPersonId("-me-", null, "Couldn't get user's groups", 200);
assertEquals(4L, (long) groups.getPaging().getCount());
Iterator<Group> it = groups.getList().iterator();
assertEquals(groupA, it.next());
assertEquals(groupB, it.next());
assertEquals(GROUP_EVERYONE, it.next().getId());
assertEquals(rootGroup, it.next());
}
// +ve: check skip count.
{
// Sort params
Map<String, String> otherParams = new HashMap<>();
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME, false);
// Paging and list groups
int skipCount = 0;
int maxItems = 4;
Paging paging = getPaging(skipCount, maxItems);
ListResponse<Group> resp = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
// Paging and list groups with skip count.
skipCount = 2;
maxItems = 2;
paging = getPaging(skipCount, maxItems);
ListResponse<Group> sublistResponse = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
List<Group> expectedSublist = sublist(resp.getList(), skipCount, maxItems);
checkList(expectedSublist, sublistResponse.getPaging(), sublistResponse);
}
// -ve: check skip count.
{
getGroupsByPersonId(personAlice.getId(), getPaging(-1, null), null, HttpServletResponse.SC_BAD_REQUEST);
}
// orderBy=sortColumn should be the same to orderBy=sortColumn ASC
{
// paging
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
// Default order.
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME, null);
ListResponse<Group> resp = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
List<Group> groups = resp.getList();
assertTrue("groups order not valid", groups.indexOf(groupA) < groups.indexOf(groupB));
// Ascending order.
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME, true);
ListResponse<Group> respOrderAsc = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
checkList(respOrderAsc.getList(), resp.getPaging(), resp);
}
// Sorting should be the same regardless of implementation (canned query
// or postprocessing).
{
// paging
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME, null);
// Get and sort groups using canned query.
ListResponse<Group> respCannedQuery = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
// Get and sort groups using postprocessing.
otherParams.put("where", "(isRoot=true)");
ListResponse<Group> respPostProcess = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
List<Group> expected = respCannedQuery.getList();
expected.retainAll(respPostProcess.getList());
// If this assertion fails, then the tests aren't providing any value - change them!
assertTrue("List doesn't contain enough items for test to be conclusive.", expected.size() > 0);
checkList(expected, respPostProcess.getPaging(), respPostProcess);
}
{
// paging
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_ID, null);
// Get and sort groups using canned query.
ListResponse<Group> respCannedQuery = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
// Get and sort groups using postprocessing.
otherParams.put("where", "(isRoot=true)");
ListResponse<Group> respPostProcess = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
List<Group> expected = respCannedQuery.getList();
expected.retainAll(respPostProcess.getList());
// If this assertion fails, then the tests aren't providing any value - change them!
assertTrue("List doesn't contain enough items for test to be conclusive.", expected.size() > 0);
checkList(expected, respPostProcess.getPaging(), respPostProcess);
}
// Sort by id.
{
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
Group groupEveryone = new Group();
groupEveryone.setId(PermissionService.ALL_AUTHORITIES);
// Sort by ID ascending
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_ID, true);
ListResponse<Group> resp = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
assertEquals(4, resp.getList().size());
Iterator<Group> it = resp.getList().iterator();
// GROUP_EVERYONE
assertEquals(groupEveryone, it.next());
// GROUP_Group_ROOT<UUID>
assertEquals(rootGroup, it.next());
// GROUP_Test_GroupA<UUID>
assertEquals(groupA, it.next());
// GROUP_Test_GroupB<UUID>
assertEquals(groupB, it.next());
// Sort by ID descending
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_ID, false);
resp = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
assertEquals(4, resp.getList().size());
it = resp.getList().iterator();
// GROUP_Test_GroupB<UUID>
assertEquals(groupB, it.next());
// GROUP_Test_GroupA<UUID>
assertEquals(groupA, it.next());
// GROUP_Group_ROOT<UUID>
assertEquals(rootGroup, it.next());
// GROUP_EVERYONE
assertEquals(groupEveryone, it.next());
}
// Multiple sort fields not allowed.
{
// paging
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("orderBy", org.alfresco.rest.api.Groups.PARAM_ID + " ASC," + org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME + " ASC");
getGroupsByPersonId(personAlice.getId(), paging, otherParams, HttpServletResponse.SC_BAD_REQUEST);
}
// Check include parent ids.
{
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS);
ListResponse<Group> resp = getGroupsByPersonId(personAlice.getId(), paging, otherParams);
assertEquals(4, resp.getList().size());
Iterator<Group> it = resp.getList().iterator();
Group group = it.next();
assertEquals(groupA.getId(), group.getId());
assertEquals(1, group.getParentIds().size());
assertTrue(group.getParentIds().contains(rootGroup.getId()));
group = it.next();
assertEquals(groupB.getId(), group.getId());
assertEquals(1, group.getParentIds().size());
assertTrue(group.getParentIds().contains(rootGroup.getId()));
group = it.next();
assertEquals(PermissionService.ALL_AUTHORITIES, group.getId());
assertEquals(0, group.getParentIds().size());
group = it.next();
assertEquals(rootGroup.getId(), group.getId());
assertEquals(0, group.getParentIds().size());
}
// Filter by zone, use the -me- alias.
{
Map<String, String> params = new HashMap<>();
params.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES);
params.put("where", "(zones in ('APP.DEFAULT'))");
// Use the -me- alias
ListResponse<Group> response = groupsProxy.getGroupsByPersonId("-me-", params, "Couldn't get user's groups", 200);
List<Group> groups = response.getList();
assertFalse(groups.isEmpty());
// All groups should contain the selected zone.
groups.forEach(group -> assertTrue(group.getZones().contains("APP.DEFAULT")));
}
// Filter by zone, use the -me- alias.
{
Map<String, String> params = new HashMap<>();
params.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES);
params.put("where", "(zones in ('APITEST.MYZONE'))");
// Use the -me- alias
ListResponse<Group> response = groupsProxy.getGroupsByPersonId("-me-", params, "Couldn't get user's groups", 200);
List<Group> groups = response.getList();
assertEquals(3, groups.size());
// All groups should contain the selected zone.
groups.forEach(group -> assertTrue(group.getZones().contains("APITEST.MYZONE")));
}
// Filter by zone - use the person's ID, without "include"-ing zones
{
Map<String, String> params = new HashMap<>();
params.put("where", "(zones in ('APITEST.ANOTHER'))");
ListResponse<Group> response = groupsProxy.getGroupsByPersonId(personAlice.getId(), params, "Couldn't get user's groups", 200);
List<Group> groups = response.getList();
assertEquals(1, groups.size());
// We haven't included the zone info
groups.forEach(group -> assertNull(group.getZones()));
}
// Filter zones while using where isRoot=true
// (this causes a different query path to be used)
{
Map<String, String> otherParams = new HashMap<>();
// Ensure predictable result ordering
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME, true);
otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES);
otherParams.put("where", "(isRoot=true AND zones in ('APITEST.MYZONE'))");
ListResponse<Group> response = groupsProxy.getGroupsByPersonId("-me-", otherParams, "Unexpected response", 200);
List<Group> groups = response.getList();
assertEquals(1, groups.size());
assertEquals(rootGroup, groups.get(0));
assertTrue(groups.get(0).getZones().contains("APITEST.MYZONE"));
// Zone that doesn't exist.
otherParams.put("where", "(isRoot=true AND zones in ('I.DO.NOT.EXIST'))");
response = groupsProxy.getGroupsByPersonId("-me-", otherParams, "Unexpected response", 200);
groups = response.getList();
assertTrue(groups.isEmpty());
}
// Filter zones while using where isRoot=false
{
Map<String, String> otherParams = new HashMap<>();
// Ensure predictable result ordering
addOrderBy(otherParams, org.alfresco.rest.api.Groups.PARAM_DISPLAY_NAME, true);
otherParams.put("where", "(isRoot=false AND zones in ('APITEST.MYZONE'))");
ListResponse<Group> response = groupsProxy.getGroupsByPersonId("-me-", otherParams, "Unexpected response", 200);
List<Group> groups = response.getList();
assertEquals(2, groups.size());
assertEquals(groupA, groups.get(0));
assertEquals(groupB, groups.get(1));
// We haven't included the zones info.
groups.forEach(group -> assertNull(group.getZones()));
// Zone that doesn't exist.
otherParams.put("where", "(isRoot=false AND zones in ('I.DO.NOT.EXIST'))");
response = groupsProxy.getGroupsByPersonId("-me-", otherParams, "Unexpected response", 200);
groups = response.getList();
assertTrue(groups.isEmpty());
}
// -ve test: invalid zones clause
{
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES);
// Empty zone list
otherParams.put("where", "(zones in ())");
groupsProxy.getGroupsByPersonId(personAlice.getId(), otherParams, "Incorrect response", 400);
// Empty zone name
otherParams.put("where", "(zones in (''))");
groupsProxy.getGroupsByPersonId(personAlice.getId(), otherParams, "Incorrect response", 400);
// Too many zones
otherParams.put("where", "(zones in ('APP.DEFAULT', 'APITEST.MYZONE'))");
groupsProxy.getGroupsByPersonId(personAlice.getId(), otherParams, "Incorrect response", 400);
// "A series of unfortunate errors"
otherParams.put("where", "(zones in ('', 'APP.DEFAULT', '', 'APITEST.MYZONE'))");
groupsProxy.getGroupsByPersonId(personAlice.getId(), otherParams, "Incorrect response", 400);
// OR operator not currently supported
otherParams.put("where", "(isRoot=true OR zones in ('APP.DEFAULT'))");
groupsProxy.getGroupsByPersonId(personAlice.getId(), otherParams, "Incorrect response", 400);
}
}
use of org.alfresco.rest.api.tests.client.data.Group in project alfresco-remote-api by Alfresco.
the class GroupsTest method shouldFilterGroupByDisplayNameWhenIsRootIsFalse.
private void shouldFilterGroupByDisplayNameWhenIsRootIsFalse() throws Exception {
Paging paging = getPaging(0, Integer.MAX_VALUE);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("where", "(isRoot=False AND displayName in ('A Group'))");
ListResponse<Group> response = getGroups(paging, otherParams);
List<Group> groups = response.getList();
assertEquals(1, groups.size());
assertEquals("A Group", groups.get(0).getDisplayName());
}
use of org.alfresco.rest.api.tests.client.data.Group in project alfresco-remote-api by Alfresco.
the class GroupsTest method testGetGroup.
@Test
public void testGetGroup() throws Exception {
final Groups groupsProxy = publicApiClient.groups();
try {
createAuthorityContext(user1);
setRequestContext(user1);
// Check invalid group id.
{
groupsProxy.getGroup("invalidGroupId", HttpServletResponse.SC_NOT_FOUND);
}
{
Group group = groupsProxy.getGroup(groupA.getId());
validateGroupDefaultFields(group);
}
{
Map<String, String> otherParams = new HashMap<>();
otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS);
Group group = groupsProxy.getGroup(groupA.getId(), otherParams, HttpServletResponse.SC_OK);
validateGroupDefaultFields(group, true);
assertNotNull(group.getParentIds());
assertNull(group.getZones());
}
{
Map<String, String> otherParams = new HashMap<>();
otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES);
Group group = groupsProxy.getGroup(groupA.getId(), otherParams, HttpServletResponse.SC_OK);
validateGroupDefaultFields(group, true);
assertNull(group.getParentIds());
assertNotNull(group.getZones());
}
// Support GROUP_EVERYONE
{
Group group = groupsProxy.getGroup(GROUP_EVERYONE, null, HttpServletResponse.SC_OK);
assertNotNull(group);
assertNotNull(group.getId());
assertNotNull(group.getIsRoot());
}
} finally {
clearAuthorityContext();
}
}
Aggregations