use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class SharedLinkApiTest method testSharedLinkFind.
/**
* Tests find shared links to file (content)
*
* Note: relies on search service
*
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links}
*/
@Test
@Category({ LuceneTests.class, RedundantTests.class })
public void testSharedLinkFind() throws Exception {
// As user 1 ...
setRequestContext(user1);
Paging paging = getPaging(0, 100);
// Get all shared links visible to user 1 (note: for now assumes clean repo)
HttpResponse response = getAll(URL_SHARED_LINKS, paging, 200);
List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(0, sharedLinks.size());
// create doc d1 - in "My" folder
String myFolderNodeId = getMyNodeId();
String content1Text = "The quick brown fox jumps over the lazy dog 1.";
String docName1 = "content" + RUNID + "_1.txt";
Document doc1 = createTextFile(myFolderNodeId, docName1, content1Text);
String d1Id = doc1.getId();
// create doc2 - in "Shared" folder
String sharedFolderNodeId = getSharedNodeId();
String docName2 = "content" + RUNID + "_2.txt";
Document doc2 = createTextFile(sharedFolderNodeId, docName2, content1Text);
String d2Id = doc2.getId();
// create shared link to doc 1
Map<String, String> body = new HashMap<>();
body.put("nodeId", d1Id);
response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String shared1Id = resp.getId();
// As user 2 ...
setRequestContext(user2);
// create shared link to doc 2
body = new HashMap<>();
body.put("nodeId", d2Id);
response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201);
resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String shared2Id = resp.getId();
//
// find links
//
setRequestContext(user1);
response = getAll(URL_SHARED_LINKS, paging, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
assertEquals(shared1Id, sharedLinks.get(1).getId());
assertEquals(d1Id, sharedLinks.get(1).getNodeId());
setRequestContext(user2);
response = getAll(URL_SHARED_LINKS, paging, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
setRequestContext(user1);
// find my links
Map<String, String> params = new HashMap<>();
params.put("where", "(" + QuickShareLinks.PARAM_SHAREDBY + "='" + People.DEFAULT_USER + "')");
response = getAll(URL_SHARED_LINKS, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared1Id, sharedLinks.get(0).getId());
assertEquals(d1Id, sharedLinks.get(0).getNodeId());
// find links shared by a given user
params = new HashMap<>();
params.put("where", "(" + QuickShareLinks.PARAM_SHAREDBY + "='" + user2 + "')");
response = getAll(URL_SHARED_LINKS, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
setRequestContext(null);
// -ve test - unauthenticated
getAll(URL_SHARED_LINKS, paging, params, 401);
// delete the shared links
setRequestContext(user1);
deleteSharedLink(shared1Id);
setRequestContext(user2);
deleteSharedLink(shared2Id);
// TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test
// (else need to verify test mechanism for enterprise admin via jmx ... etc)
setRequestContext(user1);
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
try {
quickShareLinks.setEnabled(false);
// -ve - disabled service tests
getAll(URL_SHARED_LINKS, paging, 501);
} finally {
quickShareLinks.setEnabled(true);
}
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testSetOutcome.
@Test
@SuppressWarnings("unchecked")
public void testSetOutcome() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInf = startReviewPooledProcess(requestContext);
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInf.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
activitiProcessEngine.getTaskService().saveTask(task);
Map<String, String> params = new HashMap<String, String>();
params.put("select", "state,variables");
HttpResponse response = tasksClient.update("tasks", task.getId(), null, null, "{\"state\":\"completed\",\"variables\":[{\"name\":\"wf_reviewOutcome\",\"value\":\"Approve\",\"scope\":\"local\"},{\"name\":\"bpm_comment\",\"value\":\"approved by me\",\"scope\":\"local\"}]}", params, "Failed to update task", 200);
HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().includeTaskLocalVariables().singleResult();
String outcome = (String) historyTask.getTaskLocalVariables().get("bpm_outcome");
assertEquals("Approve", outcome);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class DeletedNodesTest method testCreateAndDelete.
/**
* Tests getting deleted nodes
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/deleted-nodes/}
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/deleted-nodes/<nodeId>/}
*/
@Test
public void testCreateAndDelete() throws Exception {
setRequestContext(user1);
Date now = new Date();
String folder1 = "folder-testCreateAndDelete-" + now.getTime() + "_1";
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
assertNotNull(createdFolder);
String f1Id = createdFolder.getId();
// Create a folder outside a site
Folder createdFolderNonSite = createFolder(Nodes.PATH_MY, folder1, null);
assertNotNull(createdFolderNonSite);
Document document = createEmptyTextFile(f1Id, "d1.txt");
PublicApiClient.Paging paging = getPaging(0, 100);
// First get any deleted nodes
HttpResponse response = getAll(URL_DELETED_NODES, paging, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertNotNull(nodes);
int numOfNodes = nodes.size();
deleteNode(document.getId());
deleteNode(createdFolder.getId());
deleteNode(createdFolderNonSite.getId());
response = getAll(URL_DELETED_NODES, paging, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertNotNull(nodes);
assertEquals(numOfNodes + 3, nodes.size());
// The list is ordered with the most recently deleted node first
checkDeletedNodes(now, createdFolder, createdFolderNonSite, document, nodes);
// sanity check paging
paging = getPaging(1, 1);
response = getAll(URL_DELETED_NODES, paging, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertNotNull(nodes);
assertEquals(1, nodes.size());
PublicApiClient.ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(numOfNodes + 3, expectedPaging.getTotalItems().intValue());
assertEquals(1, expectedPaging.getCount().intValue());
assertEquals(1, expectedPaging.getSkipCount().intValue());
assertEquals(1, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
Map<String, String> params = Collections.singletonMap("include", "path");
response = getSingle(URL_DELETED_NODES, document.getId(), params, 200);
Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
assertNotNull(node);
assertEquals(user1, node.getArchivedByUser().getId());
assertTrue(node.getArchivedAt().after(now));
PathInfo path = node.getPath();
assertNull("Path should be null because its parent has been deleted", path);
assertNull("We don't show the parent id for a deleted node", node.getParentId());
response = getSingle(URL_DELETED_NODES, createdFolder.getId(), params, 200);
Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
assertNotNull(fNode);
assertEquals(user1, fNode.getArchivedByUser().getId());
assertTrue(fNode.getArchivedAt().after(now));
path = fNode.getPath();
assertNotNull(path);
assertEquals("/Company Home/Sites/" + tSiteId + "/documentLibrary", path.getName());
assertTrue(path.getIsComplete());
assertNull("We don't show the parent id for a deleted node", fNode.getParentId());
response = getSingle(URL_DELETED_NODES, createdFolderNonSite.getId(), params, 200);
fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
assertNotNull(fNode);
assertEquals(user1, fNode.getArchivedByUser().getId());
assertTrue(fNode.getArchivedAt().after(now));
path = fNode.getPath();
assertNotNull(path);
assertEquals("/Company Home/User Homes/" + user1, path.getName());
assertTrue(path.getIsComplete());
// User 2 can't get it but user 1 can.
setRequestContext(user2);
getSingle(URL_DELETED_NODES, createdFolderNonSite.getId(), Status.STATUS_FORBIDDEN);
setRequestContext(user1);
// Invalid node ref
getSingle(URL_DELETED_NODES, "iddontexist", 404);
// Now as admin
setRequestContext(networkAdmin);
paging = getPaging(0, 100);
response = publicApiClient.get(getScope(), URL_DELETED_NODES, null, null, null, createParams(paging, null));
checkStatus(200, response.getStatusCode());
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertNotNull(nodes);
checkDeletedNodes(now, createdFolder, createdFolderNonSite, document, nodes);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class BasicSearchApiIntegrationTest method testBadQuery.
@Test
public void testBadQuery() throws Exception {
setRequestContext(user1);
// Bad request
HttpResponse response = post(URL_SEARCH, bad_json, null, null, SEARCH_API_NAME, 400);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class AbstractBaseApiTest method createEmptyTextFile.
protected Document createEmptyTextFile(String parentFolderId, String docName, Map<String, String> params, int expectedStatus) throws Exception {
Document d1 = new Document();
d1.setName(docName);
d1.setNodeType("cm:content");
ContentInfo ci = new ContentInfo();
ci.setMimeType("text/plain");
d1.setContent(ci);
// create empty file
HttpResponse response = post(getNodeChildrenUrl(parentFolderId), toJsonAsStringNonNull(d1), params, null, "alfresco", expectedStatus);
if (expectedStatus != 201) {
return null;
}
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
}
Aggregations