Search in sources :

Example 66 with PostRequest

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

the class InviteServiceTest method createNominatedInvitation.

/**
 * Adapted from similar method in org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest
 */
private JSONObject createNominatedInvitation(String siteName, String inviteeFirstName, String inviteeLastName, String inviteeEmail, String inviteeUserName, String inviteeRoleName, String serverPath, String acceptURL, String rejectURL, int expectedStatus) throws Exception {
    /*
         * Create a new nominated invitation
         */
    JSONObject newInvitation = new JSONObject();
    newInvitation.put("invitationType", "NOMINATED");
    newInvitation.put("inviteeRoleName", inviteeRoleName);
    if (inviteeUserName != null) {
        // nominate an existing user
        newInvitation.put("inviteeUserName", inviteeUserName);
    } else {
        // nominate someone else
        newInvitation.put("inviteeFirstName", inviteeFirstName);
        newInvitation.put("inviteeLastName", inviteeLastName);
        newInvitation.put("inviteeEmail", inviteeEmail);
    }
    newInvitation.put("serverPath", serverPath);
    newInvitation.put("acceptURL", acceptURL);
    newInvitation.put("rejectURL", rejectURL);
    Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), expectedStatus);
    JSONObject result = new JSONObject(response.getContentAsString());
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 67 with PostRequest

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

the class LinksRestApiTest method deleteLinks.

/**
 * Deletes the links
 */
private JSONObject deleteLinks(List<String> names, int expectedStatus) throws Exception {
    JSONArray items = new JSONArray();
    for (String name : names) {
        items.put(name);
    }
    JSONObject json = new JSONObject();
    json.put("items", items);
    Response response = sendRequest(new PostRequest(URL_LINKS_DELETE, json.toString(), "application/json"), expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
        JSONObject result = new JSONObject(response.getContentAsString());
        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) JSONArray(org.json.JSONArray)

Example 68 with PostRequest

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

the class PersonServiceTest method createPerson.

private JSONObject createPerson(String userName, String title, String firstName, String lastName, String organisation, String jobTitle, String email, String bio, String avatarUrl, long quota, int expectedStatus) throws Exception {
    // switch to admin user to create a person
    String currentUser = this.authenticationComponent.getCurrentUserName();
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    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);
    if (quota > 0) {
        person.put("quota", quota);
    }
    Response response = sendRequest(new PostRequest(URL_PEOPLE, person.toString(), "application/json"), expectedStatus);
    if ((userName != null) && (userName.length() != 0)) {
        this.createdPeople.add(userName);
    }
    // switch back to non-admin user
    this.authenticationComponent.setCurrentUser(currentUser);
    return new JSONObject(response.getContentAsString());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 69 with PostRequest

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

the class PreferenceServiceTest method testPreferences.

public void testPreferences() throws Exception {
    // Get the preferences before they have been set
    Response resp = sendRequest(new GetRequest(URL), 200);
    JSONObject jsonResult = new JSONObject(resp.getContentAsString());
    assertNotNull(jsonResult);
    assertFalse(jsonResult.keys().hasNext());
    // Set some preferences
    JSONObject jsonObject = getPreferenceObj();
    jsonObject.put("comp1", getPreferenceObj());
    resp = sendRequest(new PostRequest(URL, jsonObject.toString(), "application/json"), 200);
    assertEquals(0, resp.getContentLength());
    // Get the preferences
    resp = sendRequest(new GetRequest(URL), 200);
    jsonResult = new JSONObject(resp.getContentAsString());
    assertNotNull(jsonResult);
    assertTrue(jsonResult.keys().hasNext());
    checkJSONObject(jsonResult);
    checkJSONObject(jsonResult.getJSONObject("comp1"));
    // Update some of the preferences
    jsonObject.put("stringValue", "updated");
    jsonObject.put("comp2", getPreferenceObj());
    resp = sendRequest(new PostRequest(URL, jsonObject.toString(), "application/json"), 200);
    assertEquals(0, resp.getContentLength());
    // Get the preferences
    resp = sendRequest(new GetRequest(URL), 200);
    jsonResult = new JSONObject(resp.getContentAsString());
    assertNotNull(jsonResult);
    assertTrue(jsonResult.keys().hasNext());
    jsonObject.put("stringValue", "updated");
    jsonObject.put("numberValue", 10);
    jsonObject.put("numberValue2", 3.142);
    checkJSONObject(jsonResult.getJSONObject("comp1"));
    checkJSONObject(jsonResult.getJSONObject("comp2"));
    // Filter the preferences retrieved
    resp = sendRequest(new GetRequest(URL + "?pf=comp2"), 200);
    jsonResult = new JSONObject(resp.getContentAsString());
    assertNotNull(jsonResult);
    assertTrue(jsonResult.keys().hasNext());
    checkJSONObject(jsonResult.getJSONObject("comp2"));
    assertFalse(jsonResult.has("comp1"));
    assertFalse(jsonResult.has("stringValue"));
    // Clear some of the preferences
    sendRequest(new DeleteRequest(URL + "?pf=comp1"), 200);
    resp = sendRequest(new GetRequest(URL), 200);
    jsonResult = new JSONObject(resp.getContentAsString());
    assertNotNull(jsonResult);
    assertTrue(jsonResult.keys().hasNext());
    checkJSONObject(jsonResult.getJSONObject("comp2"));
    assertFalse(jsonResult.has("comp1"));
    // Clear all the preferences
    sendRequest(new DeleteRequest(URL), 200);
    resp = sendRequest(new GetRequest(URL), 200);
    jsonResult = new JSONObject(resp.getContentAsString());
    assertNotNull(jsonResult);
    assertFalse(jsonResult.keys().hasNext());
    // Test trying to update another user's permissions
    sendRequest(new PostRequest("/api/people/" + USER_BAD + "/preferences", jsonObject.toString(), "application/json"), 401);
    // Test error conditions
    sendRequest(new GetRequest("/api/people/noExistUser/preferences"), 404);
}
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) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 70 with PostRequest

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

the class QuickShareRestApiTest method testUnshareContributer.

public void testUnshareContributer() throws UnsupportedEncodingException, IOException, JSONException {
    final int expectedStatusOK = 200;
    final int expectedStatusForbidden = 403;
    authenticationComponent.setCurrentUser("admin");
    SiteInfo siteInfo = createSite("site" + RUN_ID);
    siteService.setMembership(siteInfo.getShortName(), USER_ONE, SiteModel.SITE_CONSUMER);
    siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_CONTRIBUTOR);
    NodeRef siteDocLib = siteService.getContainer(siteInfo.getShortName(), SiteService.DOCUMENT_LIBRARY);
    NodeRef testFile = createTestFile(siteDocLib, "unshare-test" + RUN_ID, quickFile);
    String strTestNodeRef = testFile.toString().replace("://", "/");
    authenticationComponent.setCurrentUser(USER_ONE);
    // share
    Response rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", strTestNodeRef), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String sharedId = jsonRsp.getString("sharedId");
    assertNotNull(sharedId);
    // unshare
    authenticationComponent.setCurrentUser(USER_TWO);
    rsp = sendRequest(new DeleteRequest(UNSHARE_URL.replace("{shared_id}", sharedId)), expectedStatusForbidden, USER_TWO);
    authenticationComponent.setCurrentUser(USER_ONE);
    rsp = sendRequest(new DeleteRequest(UNSHARE_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_ONE);
    authenticationComponent.setCurrentUser("admin");
    deleteSite(siteInfo.getShortName());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) 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