Search in sources :

Example 51 with Response

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

the class InviteServiceTest method getInvitesByInviterUserName.

private JSONObject getInvitesByInviterUserName(String inviterUserName, int expectedStatus) throws Exception {
    // construct get invites URL
    String getInvitesUrl = URL_INVITES + "?inviterUserName=" + inviterUserName;
    // invoke get invites web script
    Response response = sendRequest(new GetRequest(getInvitesUrl), expectedStatus);
    JSONObject result = new JSONObject(response.getContentAsString());
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 52 with Response

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

the class LinksRestApiTest method createComment.

private JSONObject createComment(String nodeRef, String title, String content, int expectedStatus) throws Exception {
    JSONObject comment = new JSONObject();
    comment.put("title", title);
    comment.put("content", content);
    comment.put("site", SITE_SHORT_NAME_LINKS);
    Response response = sendRequest(new PostRequest(getCommentsUrl(nodeRef), comment.toString(), "application/json"), expectedStatus);
    if (expectedStatus != 200) {
        return null;
    }
    // logger.debug("Comment created: " + response.getContentAsString());
    JSONObject result = new JSONObject(response.getContentAsString());
    return result.getJSONObject("item");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 53 with Response

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

the class LinksRestApiTest method createLink.

/**
 * Creates a single link based on the supplied details
 */
private JSONObject createLink(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", "");
    if (internal) {
        json.put("internal", "true");
    }
    // TODO Is this really needed?
    json.put("page", "links-view");
    Response response = sendRequest(new PostRequest(URL_LINKS_CREATE, json.toString(), "application/json"), expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
        JSONObject result = new JSONObject(response.getContentAsString());
        if (result.has("link")) {
            return result.getJSONObject("link");
        }
        return result;
    } else {
        return null;
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 54 with Response

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

the class LinksRestApiTest method getLinks.

// Test helper methods
private JSONObject getLinks(String filter, String username) throws Exception {
    String origUser = this.authenticationComponent.getCurrentUserName();
    if (username != null) {
        this.authenticationComponent.setCurrentUser(username);
        filter = "user";
    }
    String url = URL_LINKS_LIST;
    if (filter == null) {
        filter = "all";
    }
    url += "?filter=" + filter;
    url += "&startIndex=0&page=1&pageSize=4";
    Response response = sendRequest(new GetRequest(url), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    if (username != null) {
        this.authenticationComponent.setCurrentUser(origUser);
    }
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 55 with Response

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

the class LinksRestApiTest method checkLinkPermissions.

private void checkLinkPermissions(String siteName) throws Exception {
    String url = "/api/links/site/" + siteName + "/links";
    url += "?filter=" + "all";
    url += "&startIndex=0&page=1&pageSize=4";
    Response response = sendRequest(new GetRequest(url), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertTrue("The user sould have permission to create a new link.", result.getJSONObject("metadata").getJSONObject("linkPermissions").getBoolean("create"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)281 JSONObject (org.json.JSONObject)228 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)171 JSONArray (org.json.JSONArray)116 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)84 JSONTokener (org.json.JSONTokener)39 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)37 NodeRef (org.alfresco.service.cmr.repository.NodeRef)34 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)32 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)16 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)16 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 Date (java.util.Date)13 JSONStringer (org.json.JSONStringer)13 UserTransaction (javax.transaction.UserTransaction)12 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)12 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)11 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)11