Search in sources :

Example 21 with PostRequest

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

the class InvitationWebScriptTest method createModeratedInvitation.

private String createModeratedInvitation(String siteName, String inviteeComments, String inviteeUserName, String inviteeRoleName) throws Exception {
    /*
         * Create a new moderated invitation
         */
    JSONObject newInvitation = new JSONObject();
    newInvitation.put("invitationType", "MODERATED");
    newInvitation.put("inviteeRoleName", inviteeRoleName);
    newInvitation.put("inviteeComments", inviteeComments);
    newInvitation.put("inviteeUserName", inviteeUserName);
    Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
    JSONObject top = new JSONObject(response.getContentAsString());
    JSONObject data = top.getJSONObject("data");
    String inviteId = data.getString("inviteId");
    createdInvitations.add(new Tracker(inviteId, siteName));
    return inviteId;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 22 with PostRequest

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

the class InviteServiceTest method createModeratedInvitation.

private String createModeratedInvitation(String siteName, String inviteeComments, String inviteeUserName, String inviteeRoleName) throws Exception {
    String URL_SITES = "/api/sites";
    /*
         * Create a new moderated invitation
         */
    JSONObject newInvitation = new JSONObject();
    newInvitation.put("invitationType", "MODERATED");
    newInvitation.put("inviteeRoleName", inviteeRoleName);
    newInvitation.put("inviteeComments", inviteeComments);
    newInvitation.put("inviteeUserName", inviteeUserName);
    Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
    JSONObject top = new JSONObject(response.getContentAsString());
    JSONObject data = top.getJSONObject("data");
    String inviteId = data.getString("inviteId");
    return inviteId;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 23 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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 24 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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 25 with PostRequest

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

the class QuickShareRestApiTest method testSanityCheckUrls.

public void testSanityCheckUrls() throws Exception {
    checkTransformer();
    final int expectedStatusOK = 200;
    final int expectedStatusNotFound = 404;
    // currently mapped from AccessDenied (should it be 403, 404 or does it depend on use-case)
    final int expectedStatusServerError = 500;
    final int expectedStatusForbidden = 403;
    String testNodeRef_3 = testNode.toString().replace("://", "/");
    // As user one ...
    // get metadata for node (authenticated)
    Response rsp = sendRequest(new GetRequest(AUTH_METADATA_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String name = jsonRsp.getString("name");
    assertEquals(TEST_NAME, name);
    String mimetype = jsonRsp.getString("mimetype");
    assertEquals(TEST_MIMETYPE_JPEG, mimetype);
    // get content for node (authenticated)
    // Commented out when removing original CMIS impl
    // rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
    // byte[] content = rsp.getContentAsByteArray();
    // checkBytes(TEST_CONTENT, content);
    // get content thumbnail for node (authenticated)
    rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_ONE);
    String type = rsp.getContentType();
    assertEquals(TEST_MIMETYPE_PNG, type);
    // As user two ...
    rsp = sendRequest(new GetRequest(AUTH_METADATA_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusServerError, USER_TWO);
    // Commented out when removing original CMIS impl
    // rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusForbidden, USER_TWO);
    rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusServerError, USER_TWO);
    // As user one ...
    // share
    rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", testNodeRef_3), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
    jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String sharedId = jsonRsp.getString("sharedId");
    assertNotNull(sharedId);
    // note: we may have to adjust/remove this check if we change length of id (or it becomes variable length)
    assertEquals(22, sharedId.length());
    // As user two ...
    // get metadata for share (note: can be unauthenticated)
    rsp = sendRequest(new GetRequest(SHARE_METADATA_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO);
    jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    name = jsonRsp.getString("name");
    assertEquals(TEST_NAME, name);
    mimetype = jsonRsp.getString("mimetype");
    assertEquals(TEST_MIMETYPE_JPEG, mimetype);
    // get content for share (note: can be unauthenticated)
    rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO);
    byte[] content = rsp.getContentAsByteArray();
    checkBytes(TEST_CONTENT, content);
    // get content thumbnail for share (note: can be unauthenticated)
    rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_TWO);
    type = rsp.getContentType();
    assertEquals(TEST_MIMETYPE_PNG, type);
    // As user one ...
    // unshare
    rsp = sendRequest(new DeleteRequest(UNSHARE_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_ONE);
    // As user two ...
    // -ve test (should not be able to get metadata or content via sharedId) - whether authenticated or not
    rsp = sendRequest(new GetRequest(SHARE_METADATA_URL.replace("{shared_id}", sharedId)), expectedStatusNotFound, USER_TWO);
    rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusNotFound, USER_TWO);
    rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusNotFound, USER_TWO);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Aggregations

PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)110 JSONObject (org.json.JSONObject)90 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)84 JSONArray (org.json.JSONArray)28 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)25 JSONTokener (org.json.JSONTokener)23 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)14 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)10 JSONStringer (org.json.JSONStringer)9 File (java.io.File)8 ZipFile (java.util.zip.ZipFile)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JSONObject (org.json.simple.JSONObject)5 IOException (java.io.IOException)4 UserTransaction (javax.transaction.UserTransaction)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 JSONException (org.json.JSONException)4 Serializable (java.io.Serializable)3