use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancesGet.
public void testTaskInstancesGet() throws Exception {
// Check USER2 starts with no tasks.
personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray results = json.getJSONArray("data");
assertNotNull(results);
assertTrue(results.length() == 0);
// 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));
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 USER2 now has one task.
List<WorkflowTask> tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
WorkflowTask task = tasks.get(0);
Map<QName, Serializable> updateParams = new HashMap<QName, Serializable>(1);
updateParams.put(WorkflowModel.PROP_DUE_DATE, new Date());
workflowService.updateTask(task.getId(), updateParams, null, null);
personManager.setUser(USER2);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
assertTrue(results.length() == tasks.size());
JSONObject result = results.getJSONObject(0);
int totalItems = results.length();
String expUrl = "api/task-instances/" + task.getId();
assertEquals(expUrl, result.getString("url"));
assertEquals(task.getName(), result.getString("name"));
assertEquals(task.getTitle(), result.getString("title"));
assertEquals(task.getDescription(), result.getString("description"));
assertEquals(task.getState().name(), result.getString("state"));
assertEquals("api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
assertFalse(result.getBoolean("isPooled"));
assertTrue(result.getBoolean("isEditable"));
assertTrue(result.getBoolean("isReassignable"));
assertFalse(result.getBoolean("isClaimable"));
assertFalse(result.getBoolean("isReleasable"));
JSONObject owner = result.getJSONObject("owner");
assertEquals(USER2, owner.getString("userName"));
assertEquals(personManager.getFirstName(USER2), owner.getString("firstName"));
assertEquals(personManager.getLastName(USER2), owner.getString("lastName"));
JSONObject properties = result.getJSONObject("properties");
assertNotNull(properties);
JSONObject instance = result.getJSONObject("workflowInstance");
assertNotNull(instance);
// Check state filtering
checkTasksState(URL_TASKS + "?state=completed", WorkflowTaskState.COMPLETED);
checkTasksState(URL_TASKS + "?state=in_progress", WorkflowTaskState.IN_PROGRESS);
// TODO: Add more tests to check pooled actors.
// Check for priority filtering
checkPriorityFiltering(URL_TASKS + "?priority=2");
// Due after yesterday, started task should be in it
dueDateCal.add(Calendar.DAY_OF_MONTH, -1);
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_AFTER, ISO8601DateFormat.format(dueDateCal.getTime())), true, task.getId());
// Due before yesterday, started task shouldn't be in it
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_BEFORE, ISO8601DateFormat.format(dueDateCal.getTime())), false, task.getId());
// Due before tomorrow, started task should be in it
dueDateCal.add(Calendar.DAY_OF_MONTH, 2);
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_BEFORE, ISO8601DateFormat.format(dueDateCal.getTime())), true, task.getId());
// Due after tomorrow, started task shouldn't be in it
checkTasksPresent(MessageFormat.format(URL_TASKS_DUE_AFTER, ISO8601DateFormat.format(dueDateCal.getTime())), false, task.getId());
// checkFiltering(URL_TASKS + "?dueAfter=" +
// ISO8601DateFormat.format(dueDate));
// checkFiltering(URL_TASKS + "?dueBefore=" +
// ISO8601DateFormat.format(new Date()));
// Check property filtering on the task assigned to USER2
String customProperties = "bpm_description,bpm_priority";
checkTaskPropertyFiltering(customProperties, Arrays.asList("bpm_description", "bpm_priority"));
// Properties that aren't explicitally present on task should be
// returned as wel
customProperties = "bpm_unexistingProperty,bpm_description,bpm_priority";
checkTaskPropertyFiltering(customProperties, Arrays.asList("bpm_description", "bpm_priority", "bpm_unexistingProperty"));
// Check paging
int maxItems = 3;
for (int skipCount = 0; skipCount < totalItems; skipCount += maxItems) {
// one of this should test situation when skipCount + maxItems >
// totalItems
checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount=" + skipCount, totalItems, maxItems, skipCount);
}
// testing when skipCount > totalItems
checkPaging(MessageFormat.format(URL_USER_TASKS, USER2) + "&maxItems=" + maxItems + "&skipCount=" + (totalItems + 1), totalItems, maxItems, totalItems + 1);
// check the exclude filtering
String exclude = "wf:submitAdhocTask";
response = sendRequest(new GetRequest(URL_TASKS + "?exclude=" + exclude), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr);
results = json.getJSONArray("data");
assertNotNull(results);
boolean adhocTasksPresent = false;
for (int i = 0; i < results.length(); i++) {
JSONObject taskJSON = results.getJSONObject(i);
String type = taskJSON.getString("name");
if (exclude.equals(type)) {
adhocTasksPresent = true;
break;
}
}
assertFalse("Found wf:submitAdhocTask when they were supposed to be excluded", adhocTasksPresent);
// CLOUD-1928: Check skip-count works toghether with filter, start another process
personManager.setUser(USER1);
params.clear();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
dueDateCal.add(Calendar.DAY_OF_YEAR, 2);
params.put(WorkflowModel.PROP_DUE_DATE, dueDateCal.getTime());
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
WorkflowPath adhocPath2 = workflowService.startWorkflow(adhocDef.getId(), params);
String workflowId2 = adhocPath2.getInstance().getId();
workflows.add(workflowId2);
WorkflowTask startTask2 = workflowService.getStartTask(workflowId2);
workflowService.endTask(startTask2.getId(), null);
// Filter based on due-date and skip first result. Should return nothing instead of
// the second task, since only one matches and one is skipped
// Due after tomorrow, started task shouldn't be in it
String url = MessageFormat.format(URL_TASKS_DUE_AFTER_AND_SKIP, ISO8601DateFormat.format(dueDateCal.getTime()), 1);
json = getDataFromRequest(url);
JSONArray resultArray = json.getJSONArray("data");
assertEquals(0, resultArray.length());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancesForWorkflowGet.
public void testTaskInstancesForWorkflowGet() throws Exception {
// Check starts with no workflow.
personManager.setUser(USER2);
sendRequest(new GetRequest(MessageFormat.format(URL_WORKFLOW_TASKS, "Foo")), Status.STATUS_INTERNAL_SERVER_ERROR);
// 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));
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);
// End start task.
WorkflowTask startTask = workflowService.getStartTask(workflowId);
String startTaskId = startTask.getId();
workflowService.endTask(startTaskId, null);
// Check USER2 now has one task.
List<WorkflowTask> tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
assertEquals(1, tasks.size());
WorkflowTask task = tasks.get(0);
// Retrieve tasks using the workflow instance
String baseUrl = MessageFormat.format(URL_WORKFLOW_TASKS, workflowId);
// Check returns the completed start task.
String adhocTaskId = task.getId();
checkTasksMatch(baseUrl, startTaskId);
String completedUrl = baseUrl + "?state=" + WorkflowTaskState.COMPLETED;
checkTasksMatch(completedUrl, startTaskId);
personManager.setUser(USER2);
String inProgressUrl = baseUrl + "?state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(inProgressUrl, adhocTaskId);
String user1Url = baseUrl + "?authority=" + USER1;
checkTasksMatch(user1Url, startTaskId);
String user2Url = baseUrl + "?authority=" + USER2;
checkTasksMatch(user2Url, adhocTaskId);
String user1CompletedURL = user1Url + "&state=" + WorkflowTaskState.COMPLETED;
checkTasksMatch(user1CompletedURL, startTaskId);
String user1InProgressURL = user1Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(user1InProgressURL);
String user2CompletedURL = user2Url + "&state=" + WorkflowTaskState.COMPLETED;
checkTasksMatch(user2CompletedURL);
String user2InProgressURL = user2Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(user2InProgressURL, adhocTaskId);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class GroupsTest method getDataArray.
private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException {
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
return data;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class InvitationWebScriptTest method testInvitationsGet.
/**
* Detailed Test of List Invitation Web Script.
* Using URL: /api/invitations
*
* @param requireAcceptance true if a workflow requiring acceptance is being used
* @throws Exception
*/
protected void testInvitationsGet(boolean requireAcceptance) throws Exception {
// Create two sites.
String shortNameSiteA = GUID.generate();
createSite("myPreset", shortNameSiteA, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
String shortNameSiteB = GUID.generate();
createSite("myPreset", shortNameSiteB, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// Create a moderated invitation on SiteA, USER_TWO
String inviteeComments = "Please sir, let $* me in";
String userName = userTwo;
String roleName = SiteModel.SITE_CONSUMER;
String moderatedIdAUSER_TWO = createModeratedInvitation(shortNameSiteA, inviteeComments, userName, roleName);
// Create a moderated invitation on SiteB, USER_TWO
String moderatedIdBUSER_TWO = createModeratedInvitation(shortNameSiteB, inviteeComments, userName, roleName);
String inviteeCommentsB = "Please sir, let $* me in";
String userNameB = userThree;
String roleNameB = SiteModel.SITE_CONSUMER;
// Create a moderated invitation on SiteB, USER_THREE
String moderatedIdBUSER_THREE = createModeratedInvitation(shortNameSiteB, inviteeCommentsB, userNameB, roleNameB);
String inviteeFirstName = "Buffy";
String inviteeLastName = "Summers";
String inviteeEmail = "buffy@sunnydale";
String inviteeUserName = userName;
String serverPath = "http://localhost:8081/share/";
String acceptURL = "page/accept-invite";
String rejectURL = "page/reject-invite";
// Create a nominated invitation on SiteA, UsER_TWO
String nominatedId = createNominatedInvitation(shortNameSiteA, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
// search by user - find USER_TWO's three invitations
{
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?inviteeUserName=" + userTwo), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
JSONObject moderatedAInv = getInvitation(moderatedIdAUSER_TWO, data);
assertNotNull("Moderated invitation to Site A not present!", moderatedAInv);
JSONObject moderatedBInv = getInvitation(moderatedIdBUSER_TWO, data);
assertNotNull("Moderated invitation to Site B not present!", moderatedBInv);
JSONObject nominatedInv = getInvitation(nominatedId, data);
if (requireAcceptance) {
assertNotNull("Nominated invitation to Site A not present!", nominatedInv);
}
checkJSONInvitations(data);
}
// search by type - should find three moderated invitations
{
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED"), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
JSONObject obj = data.getJSONObject(i);
assertEquals("Wrong invitation type", "MODERATED", obj.getString("invitationType"));
}
JSONObject moderatedATwoInv = getInvitation(moderatedIdAUSER_TWO, data);
assertNotNull("first is null", moderatedATwoInv);
JSONObject moderatedBTwoInv = getInvitation(moderatedIdBUSER_TWO, data);
assertNotNull("second is null", moderatedBTwoInv);
JSONObject moderatedBThreeInv = getInvitation(moderatedIdBUSER_THREE, data);
assertNotNull("third is null", moderatedBThreeInv);
}
// Search by type and site
{
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName=" + shortNameSiteA + "&resourceType=WEB_SITE"), 200);
JSONObject top = new JSONObject(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("One moderated invitations not found", 1, data.length());
}
// negative test - unknown resourceType
{
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName=" + shortNameSiteA + "&resourceType=madeUpStuff"), 500);
assertEquals(500, response.getStatus());
JSONObject top = new JSONObject(response.getContentAsString());
assertNotNull(top.getString("message"));
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class InviteServiceTest method listInvitations.
private JSONObject listInvitations(String siteShortName, String userNameSearch, int expectedStatus) throws Exception {
// construct get invites URL
String getInvitesUrl = "/api/sites/" + siteShortName + "/potentialmembers?authorityType=USER&sortBy=fullName&dir=asc&filter=" + userNameSearch + "&maxResults=250";
// invoke get invites web script
Response response = sendRequest(new GetRequest(getInvitesUrl), expectedStatus);
JSONObject result = new JSONObject(response.getContentAsString());
return result;
}
Aggregations