Search in sources :

Example 26 with PutRequest

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

the class LinksRestApiTest method updateLink.

/**
 * Updates the link with the new details
 */
private JSONObject updateLink(String name, String title, String description, String url, boolean internal, int expectedStatus) throws Exception {
    JSONObject json = new JSONObject();
    json.put("site", SITE_SHORT_NAME_LINKS);
    json.put("title", title);
    json.put("description", description);
    json.put("url", url);
    json.put("tags", "");
    json.put("internal", Boolean.toString(internal).toLowerCase());
    // TODO Is this really needed?
    json.put("page", "links-view");
    Response response = sendRequest(new PutRequest(URL_LINKS_UPDATE + name, json.toString(), "application/json"), expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
        JSONObject result = new JSONObject(response.getContentAsString());
        if (result.has("links")) {
            return result.getJSONObject("links");
        }
        return result;
    } else {
        return null;
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 27 with PutRequest

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

the class PersonServiceTest method updatePerson.

private JSONObject updatePerson(String userName, String title, String firstName, String lastName, String organisation, String jobTitle, String email, String bio, String avatarUrl, int expectedStatus) throws Exception {
    // switch to admin user to create a person
    String currentUser = this.authenticationComponent.getCurrentUserName();
    String adminUser = this.authenticationComponent.getSystemUserName();
    this.authenticationComponent.setCurrentUser(adminUser);
    JSONObject person = new JSONObject();
    person.put("userName", userName);
    person.put("title", title);
    person.put("firstName", firstName);
    person.put("lastName", lastName);
    person.put("organisation", organisation);
    person.put("jobtitle", jobTitle);
    person.put("email", email);
    Response response = sendRequest(new PutRequest(URL_PEOPLE + "/" + userName, person.toString(), "application/json"), expectedStatus);
    // switch back to non-admin user
    this.authenticationComponent.setCurrentUser(currentUser);
    return new JSONObject(response.getContentAsString());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 28 with PutRequest

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

the class CalendarRestApiTest method updateEntry.

/**
 * Updates the event to be a 2 hour, non-all day event on the 28th of June
 */
private JSONObject updateEntry(String name, String what, String where, String description, boolean withRecurrence, int expectedStatus) throws Exception {
    // A Tuesday
    String date = "2011/06/28";
    String start = "11:30";
    String end = "13:30";
    JSONObject json = new JSONObject();
    json.put("what", what);
    json.put("where", where);
    json.put("desc", description);
    json.put("from", date);
    json.put("to", date);
    // json.put("fromdate", "Tuesday, 30 June 2011"); // Not needed
    // json.put("todate", "Tuesday, 30 June 2011"); // Not needed
    json.put("start", start);
    json.put("end", end);
    json.put("tags", "");
    json.put("docfolder", "");
    json.put("page", "calendar");
    if (withRecurrence) {
        json.put("recurrenceRule", "FREQ=WEEKLY;INTERVAL=2;BYDAY=WE,FR");
        json.put("recurrenceLastMeeting", "2011-09-11");
    }
    Response response = sendRequest(new PutRequest(URL_EVENT_BASE + name, json.toString(), "application/json"), expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
        JSONObject result = validateAndParseJSON(response.getContentAsString());
        if (result.has("event")) {
            return result.getJSONObject("event");
        }
        if (result.has("data")) {
            return result.getJSONObject("data");
        }
        return result;
    } else {
        return null;
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 29 with PutRequest

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

the class CommentsApiTest method updateComment.

/**
 * @param nodeRef
 * @param user
 * @param expectedStatus
 * @return
 * @throws Exception
 */
private Response updateComment(NodeRef nodeRef, String user, int expectedStatus) throws Exception {
    Response response = null;
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    AuthenticationUtil.setFullyAuthenticatedUser(user);
    String now = System.currentTimeMillis() + "";
    JSONObject comment = new JSONObject();
    comment.put("title", "Test title updated " + now);
    comment.put("content", "Test comment updated " + now);
    response = sendRequest(new PutRequest(MessageFormat.format(URL_PUT_COMMENT, new Object[] { nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId() }), comment.toString(), JSON), expectedStatus);
    assertEquals(expectedStatus, response.getStatus());
    // around the calls.  if the WebScript fails, then we should rollback.
    if (response.getStatus() == 500) {
        txn.rollback();
    } else {
        txn.commit();
    }
    return response;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) UserTransaction(javax.transaction.UserTransaction) JSONObject(org.json.simple.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) JSONObject(org.json.simple.JSONObject)

Example 30 with PutRequest

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

the class DiscussionRestApiTest method doUpdatePost.

private JSONObject doUpdatePost(String url, String title, String content, int expectedStatus) throws Exception {
    JSONObject post = new JSONObject();
    post.put("title", title);
    post.put("content", content);
    Response response = sendRequest(new PutRequest(url, post.toString(), "application/json"), expectedStatus);
    if (expectedStatus != Status.STATUS_OK) {
        return null;
    }
    JSONObject result = new JSONObject(response.getContentAsString());
    return result.getJSONObject("item");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) 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