use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstancesWithPaging.
@Test
public void testGetProcessInstancesWithPaging() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
final ProcessInfo process2 = startAdhocProcess(requestContext, null);
final ProcessInfo process3 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
// Test with existing processDefinitionId
Map<String, String> params = new HashMap<String, String>();
params.put("processDefinitionId", process1.getProcessDefinitionId());
JSONObject processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
JSONObject paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
JSONArray jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(3, jsonEntries.size());
// Test with existing processDefinitionId and max items
params.clear();
params.put("maxItems", "2");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
// Test with existing processDefinitionId and skip count
params.clear();
params.put("skipCount", "1");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(1l, paginationJSON.get("skipCount"));
// MNT-10977: Workflow process retrieval returns incorrect hasMoreItems value
// Repository must answer 'false' for 'hasMoreItems' since the total number of items is 3, 2 items are requested and 1 is skipped
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
// Test with existing processDefinitionId and max items and skip count
params.clear();
params.put("maxItems", "3");
params.put("skipCount", "2");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(1l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
// MNT-10977: Workflow process retrieval returns incorrect hasMoreItems value
// Repository must answer 'false' for 'hasMoreItems' since the total number of items is 3 and 2 items are skipped
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(1, jsonEntries.size());
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class GroupsTest method createAuthorityContext.
/**
* Creates authority context.
*
* @param userName
* The user to run as.
*/
private void createAuthorityContext(String userName) throws PublicApiException {
String groupName = "Group_ROOT" + GUID.generate();
AuthenticationUtil.setRunAsUser(userName);
if (rootGroupName == null) {
rootGroupName = authorityService.getName(AuthorityType.GROUP, groupName);
}
if (!authorityService.authorityExists(rootGroupName)) {
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, groupName);
authorityService.addAuthorityToZones(rootGroupName, zoneSet("APITEST.MYZONE"));
authorityService.setAuthorityDisplayName(rootGroupName, "Root Group");
String groupBAuthorityName = authorityService.createAuthority(AuthorityType.GROUP, "Test_GroupB" + GUID.generate());
authorityService.setAuthorityDisplayName(groupBAuthorityName, "B Group");
authorityService.addAuthority(rootGroupName, groupBAuthorityName);
authorityService.addAuthorityToZones(groupBAuthorityName, zoneSet("APITEST.MYZONE"));
when(groupBResultSetRow.getNodeRef()).thenReturn(authorityService.getAuthorityNodeRef(groupBAuthorityName));
String groupAAuthorityName = authorityService.createAuthority(AuthorityType.GROUP, "Test_GroupA" + GUID.generate());
authorityService.setAuthorityDisplayName(groupAAuthorityName, "A Group");
authorityService.addAuthority(rootGroupName, groupAAuthorityName);
authorityService.addAuthorityToZones(groupAAuthorityName, zoneSet("APITEST.MYZONE", "APITEST.ANOTHER"));
when(groupAResultSetRow.getNodeRef()).thenReturn(authorityService.getAuthorityNodeRef(groupAAuthorityName));
authorityService.addAuthority(groupAAuthorityName, user1);
authorityService.addAuthority(groupBAuthorityName, user2);
rootGroup = new Group();
rootGroup.setId(rootGroupName);
rootGroup.setDisplayName("Root Group");
groupA = new Group();
groupA.setId(groupAAuthorityName);
groupA.setDisplayName("A Group");
groupB = new Group();
groupB.setId(groupBAuthorityName);
groupB.setDisplayName("B Group");
groupMemberA = new GroupMember();
groupMemberA.setId(groupAAuthorityName);
groupMemberA.setMemberType(AuthorityType.GROUP.toString());
groupMemberB = new GroupMember();
groupMemberB.setId(groupBAuthorityName);
groupMemberB.setMemberType(AuthorityType.GROUP.toString());
}
{
publicApiClient.setRequestContext(new RequestContext(networkOne.getId(), networkAdmin, "admin"));
Person 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);
personMember = new GroupMember();
personMember.setId(personAlice.getId());
personMember.setMemberType(MEMBER_TYPE_PERSON);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext 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.RequestContext in project alfresco-remote-api by Alfresco.
the class QueriesNodesApiTest method testLiveSearchNodes_Tags.
@Test
@Category(RedundantTests.class)
public void testLiveSearchNodes_Tags() throws Exception {
setRequestContext(user1);
PublicApiClient.Nodes nodesProxy = publicApiClient.nodes();
int f1Count = 5;
List<String> f1NodeIds = new ArrayList<>(f1Count);
int f2Count = 3;
List<String> f2NodeIds = new ArrayList<>(f2Count);
int totalCount = f1Count + f2Count;
List<String> allIds = new ArrayList<>(totalCount);
String testTag = "ghi789tag";
String testFileTag = "ghi789file";
String testFolderTag = "ghi789folder";
try {
// As user 1 ...
Paging paging = getPaging(0, 100);
String f1Id = createFolder(Nodes.PATH_MY, "folder tag 1").getId();
String f2Id = createFolder(Nodes.PATH_MY, "folder tag 2").getId();
String name = "name";
for (int i = 1; i <= f1Count; i++) {
// create doc - in folder 1
String contentText = "f1 test document " + user1 + " document " + i;
String docName = name + i;
Document doc = createTextFile(f1Id, docName, contentText, "UTF-8", null);
publicApiClient.setRequestContext(new RequestContext("", user1));
// ignore result
nodesProxy.createNodeTag(doc.getId(), new Tag(testTag));
// ignore result
nodesProxy.createNodeTag(doc.getId(), new Tag(testFileTag));
f1NodeIds.add(doc.getId());
}
for (int i = 1; i <= f2Count; i++) {
// create folder - in folder 2
String folderName = name + i;
Folder folder = createFolder(f2Id, folderName, null);
publicApiClient.setRequestContext(new RequestContext("", user1));
// ignore result
nodesProxy.createNodeTag(folder.getId(), new Tag(testTag));
// ignore result
nodesProxy.createNodeTag(folder.getId(), new Tag(testFolderTag));
f2NodeIds.add(folder.getId());
}
allIds.addAll(f1NodeIds);
allIds.addAll(f2NodeIds);
// Search hits based on tag
Map<String, String> params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testTag);
HttpResponse response = getAll(URL_QUERIES_LSN, paging, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, allIds, null);
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testFileTag);
response = getAll(URL_QUERIES_LSN, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f1NodeIds, null);
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testFolderTag);
response = getAll(URL_QUERIES_LSN, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f2NodeIds, null);
} finally {
// some cleanup
setRequestContext(user1);
for (String nodeId : allIds) {
deleteNode(nodeId, true, 204);
}
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestPeople method testPagingAndSortingByInvalidSortKey.
/**
* Tests the capability to sort and paginate the list of people orderBy =
* invalid sort key ASC skip = 1, count = 3
*
* @throws Exception
*/
@Test
public void testPagingAndSortingByInvalidSortKey() throws Exception {
publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
// paging
int skipCount = 1;
int maxItems = 3;
int totalResults = 5;
PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// orderBy=invalidSortKey ASC
listPeople(paging, "invalidSortKey", true, 400);
}
Aggregations