use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class ThumbnailServiceTest method testCreateThumbnail.
public void testCreateThumbnail() throws Exception {
// Check for pdfToSWF transformation before doing test
if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_FLASH, new TransformationOptions()) != null) {
String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnails";
JSONObject tn = new JSONObject();
tn.put("thumbnailName", "webpreview");
Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200);
System.out.println(response.getContentAsString());
}
// Check getAll whilst we are here
Response getAllResp = sendRequest(new GetRequest(getThumbnailsURL(jpgNode)), 200);
JSONArray getArr = new JSONArray(getAllResp.getContentAsString());
assertNotNull(getArr);
assertEquals(0, getArr.length());
// Do a image transformation (medium)
String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails";
JSONObject tn = new JSONObject();
tn.put("thumbnailName", "medium");
Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200);
System.out.println(response.getContentAsString());
JSONObject result = new JSONObject(response.getContentAsString());
String thumbnailUrl = result.getString("url").substring(17);
System.out.println(thumbnailUrl);
response = sendRequest(new GetRequest(thumbnailUrl), 200);
// Check getAll whilst we are here
getAllResp = sendRequest(new GetRequest(getThumbnailsURL(jpgNode)), 200);
getArr = new JSONArray(getAllResp.getContentAsString());
assertNotNull(getArr);
assertEquals(1, getArr.length());
assertEquals("medium", getArr.getJSONObject(0).get("thumbnailName"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testWorkflowPermissions.
public void testWorkflowPermissions() throws Exception {
// Start workflow as USER1 and assign task to USER1.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER1));
Calendar dueDateCal = Calendar.getInstance();
Date dueDate = dueDateCal.getTime();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Check tasks of USER1 from behalf of USER2
personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER1)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray results = json.getJSONArray("data");
assertNotNull(results);
assertTrue("User2 should not see any tasks if he is not initiator or assignee", results.length() == 0);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testWorkflowInstancesForNodeGet.
public void testWorkflowInstancesForNodeGet() throws Exception {
// Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
params.put(WorkflowModel.PROP_DUE_DATE, new Date());
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
nodeService.addChild(packageRef, contentNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_NAME))));
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String url = MessageFormat.format(URL_WORKFLOW_INSTANCES_FOR_NODE, contentNodeRef.getStoreRef().getProtocol(), contentNodeRef.getStoreRef().getIdentifier(), contentNodeRef.getId());
Response response = sendRequest(new GetRequest(url), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray result = json.getJSONArray("data");
assertNotNull(result);
assertTrue(result.length() > 0);
workflowService.cancelWorkflow(adhocPath.getInstance().getId());
Response afterCancelResponse = sendRequest(new GetRequest(url), 200);
assertEquals(Status.STATUS_OK, afterCancelResponse.getStatus());
String afterCancelJsonStr = afterCancelResponse.getContentAsString();
JSONObject afterCancelJson = new JSONObject(afterCancelJsonStr);
JSONArray afterCancelResult = afterCancelJson.getJSONArray("data");
assertNotNull(afterCancelResult);
assertTrue(afterCancelResult.length() == 0);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method getDataFromRequest.
private JSONObject getDataFromRequest(String url) throws Exception {
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
return json;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancesGetWithFiltering.
public void testTaskInstancesGetWithFiltering() throws Exception {
// Check USER2 starts with no tasks.
personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
getJsonArray(response, 0);
// Start workflow as USER1 and assign the task to GROUP.
personManager.setUser(USER1);
WorkflowDefinition wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<>(3);
params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest1");
WorkflowPath wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
String workflowId = wfPath.getInstance().getId();
workflows.add(workflowId);
WorkflowTask startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Start another workflow as USER1 and assign the task to GROUP.
wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest2/withSlash");
wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
workflowId = wfPath.getInstance().getId();
workflows.add(workflowId);
startTask = workflowService.getStartTask(workflowId);
workflowService.endTask(startTask.getId(), null);
// Check USER2's tasks without filtering. It should return two tasks as USER2 is a member of the GROUP
personManager.setUser(USER2);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
getJsonArray(response, 2);
// Check USER2's tasks With filtering where property bpm:description should match "descTest1"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest1"), 200);
JSONArray results = getJsonArray(response, 1);
JSONObject result = results.getJSONObject(0);
assertNotNull(result);
JSONObject properties = result.getJSONObject("properties");
assertNotNull(properties);
assertEquals("descTest1", properties.getString("bpm_description"));
// Check USER2's tasks With filtering where property bpm:description should match "descTest2"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest2/withSlash"), 200);
results = getJsonArray(response, 1);
result = results.getJSONObject(0);
assertNotNull(result);
properties = result.getJSONObject("properties");
assertNotNull(properties);
assertEquals("descTest2/withSlash", properties.getString("bpm_description"));
/*
* -ve tests
*/
// Mismatched property value - There is no task with the description "somePropValue"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/somePropValue"), 200);
getJsonArray(response, 0);
// Unregistered namespace prefix (ignores "property" parameter)
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=unknownPrefix:description/test"), 200);
getJsonArray(response, 2);
// Nonexistent property (ignores "property" parameter)
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:nonexistentProp/test"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=descTest1"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=/descTest1"), 200);
getJsonArray(response, 2);
// Check USER3's tasks without filtering. It should return 0 task as USER3 is not a member of the GROUP
personManager.setUser(USER3);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200);
getJsonArray(response, 0);
}
Aggregations