Search in sources :

Example 1 with PutRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.

the class NodeArchiveServiceRestApiTest method testRestoreDeletedItems.

/**
 * This test method restores some deleted nodes from the archive store.
 */
public void testRestoreDeletedItems() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    JSONObject archivedNodesJson = getArchivedNodes();
    JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
    JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
    int archivedNodesLength = archivedNodesArray.length();
    assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
    // Take a specific archived node and restore it.
    JSONObject firstArchivedNode = archivedNodesArray.getJSONObject(0);
    // So we have identified a specific Node in the archive that we want to restore.
    String nodeRefString = firstArchivedNode.getString(AbstractArchivedNodeWebScript.NODEREF);
    assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
    NodeRef nodeRef = new NodeRef(nodeRefString);
    // This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
    // This is its current StoreRef i.e. archive://SpacesStore
    final StoreRef currentStoreRef = nodeRef.getStoreRef();
    String restoreUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
    int archivedNodesCountBeforeRestore = getArchivedNodesCount();
    // Send the PUT REST call.
    String jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString();
    Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200);
    assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) JSONStringer(org.json.JSONStringer)

Example 2 with PutRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.

the class SubscriptionServiceRestApiTest method setSubscriptionListPrivate.

protected void setSubscriptionListPrivate(String user, boolean setPrivate) throws Exception {
    JSONObject privateObject = new JSONObject();
    privateObject.put("private", setPrivate);
    String url = getUrl(URL_PRIVATE, user);
    Response response = sendRequest(new PutRequest(url, privateObject.toString(), "application/json"), Status.STATUS_OK);
    JSONObject resultObject = new JSONObject(response.getContentAsString());
    assertTrue(resultObject.has("private"));
    assertEquals(setPrivate, resultObject.getBoolean("private"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 3 with PutRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.

the class ThumbnailServiceTest method testUpdateThumbnail.

public void testUpdateThumbnail() throws Exception {
    // Do a image transformation
    String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails";
    JSONObject tn = new JSONObject();
    tn.put("thumbnailName", "doclib");
    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(1, getArr.length());
    assertEquals("doclib", getArr.getJSONObject(0).get("thumbnailName"));
    // Now we know that thumbnail was created
    sendRequest(new GetRequest(getThumbnailsURL(jpgNode) + "/incorrectname"), 404);
    // Request for update of thumbnail, that is absent
    sendRequest(new PutRequest(getThumbnailsURL(jpgNode) + "/incorrectname", "", "application/json"), 404);
    // Request for update of correct thumbnail
    sendRequest(new PutRequest(getThumbnailsURL(jpgNode) + "/doclib", "", "application/json"), 200);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 4 with PutRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method runReviewPooledFlow.

protected void runReviewPooledFlow(boolean approve) throws Exception {
    // Start workflow as USER1
    personManager.setUser(USER1);
    WorkflowDefinition reviewDef = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    // Reviewer is group GROUP
    params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
    Date dueDate = new Date();
    params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    params.put(WorkflowModel.PROP_CONTEXT, packageRef);
    WorkflowPath reviewPath = workflowService.startWorkflow(reviewDef.getId(), params);
    String workflowId = reviewPath.getInstance().getId();
    workflows.add(workflowId);
    WorkflowTask startTask = workflowService.getTasksForWorkflowPath(reviewPath.getId()).get(0);
    // End start task
    startTask = workflowService.endTask(startTask.getId(), null);
    // Check if task is NOT available in list USER3, not a member of the
    // group
    personManager.setUser(USER3);
    Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    String jsonStr = response.getContentAsString();
    JSONObject json = new JSONObject(jsonStr);
    JSONArray results = json.getJSONArray("data");
    assertNotNull(results);
    assertEquals(0, results.length());
    // Check if task is available in list of reviewer, member of GROUP:
    // USER2
    personManager.setUser(USER2);
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr);
    results = json.getJSONArray("data");
    assertNotNull(results);
    assertEquals(1, results.length());
    // Check if task is claimable and pooled
    JSONObject taskJson = results.getJSONObject(0);
    String taskId = taskJson.getString("id");
    assertTrue(taskJson.getBoolean("isClaimable"));
    assertTrue(taskJson.getBoolean("isPooled"));
    // Claim task, using PUT, updating the owner
    JSONObject properties = new JSONObject();
    properties.put(qnameToString(ContentModel.PROP_OWNER), USER2);
    sendRequest(new PutRequest(URL_TASKS + "/" + taskId, properties.toString(), "application/json"), 200);
    // Check if task insn't claimable anymore
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr);
    results = json.getJSONArray("data");
    assertNotNull(results);
    assertEquals(1, results.length());
    taskJson = results.getJSONObject(0);
    assertFalse(taskJson.getBoolean("isClaimable"));
    assertTrue(taskJson.getBoolean("isPooled"));
    // Delegate approval/rejection to implementing engine-test
    if (approve) {
        approveTask(taskId);
    } else {
        rejectTask(taskId);
    }
    // 'Approved'/'Rejected' task should be available for initiator
    personManager.setUser(USER1);
    response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER1)), 200);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr);
    results = json.getJSONArray("data");
    assertNotNull(results);
    assertEquals(1, results.length());
    // Correct task type check
    String taskType = results.getJSONObject(0).getString("name");
    if (approve) {
        assertEquals("wf:approvedTask", taskType);
    } else {
        assertEquals("wf:rejectedTask", taskType);
    }
    workflowService.cancelWorkflow(workflowId);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) Date(java.util.Date) Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 5 with PutRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.

the class InviteServiceTest method testAcceptInvite.

public void testAcceptInvite() throws Exception {
    // inviter starts invite (sends out invitation)
    JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_CREATED);
    // get hold of invite ID and invite ticket of started invite
    JSONObject data = result.getJSONObject("data");
    String inviteId = data.getString("inviteId");
    String inviteTicket = data.getString("inviteTicket");
    // Invitee accepts invitation to a Site from Inviter
    String acceptInviteUrl = URL_INVITE + "/" + inviteId + "/" + inviteTicket + "/accept";
    sendRequest(new PutRequest(acceptInviteUrl, (byte[]) null, null), Status.STATUS_OK);
    // Invitee attempts to accept the invitation again
    sendRequest(new PutRequest(acceptInviteUrl, (byte[]) null, null), Status.STATUS_CONFLICT);
    // Invitee attempts to reject an invitation that has already been accepted.
    rejectInvite(inviteId, inviteTicket, Status.STATUS_CONFLICT);
    // 
    // test that invitation represented by invite ID (of invitation started above)
    // is no longer pending (as a result of the invitation having being accepted)
    // 
    // get pending invite matching inviteId from invite started above (run as inviter user)
    this.authenticationComponent.setCurrentUser(USER_INVITER);
    JSONObject getInvitesResult = getInvitesByInviteId(inviteId, Status.STATUS_OK);
// there should no longer be any invites identified by invite ID pending
// assertEquals(0, getInvitesResult.getJSONArray("invites").length());
}
Also used : JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Aggregations

PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)41 JSONObject (org.json.JSONObject)39 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)37 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)17 JSONArray (org.json.JSONArray)13 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)10 JSONTokener (org.json.JSONTokener)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 JSONStringer (org.json.JSONStringer)5 IOException (java.io.IOException)3 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)3 QName (org.alfresco.service.namespace.QName)3 JSONException (org.json.JSONException)3 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)3 ArrayList (java.util.ArrayList)1