Search in sources :

Example 26 with DeleteRequest

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

the class LinksRestApiTest method testCommentLink.

public void testCommentLink() throws Exception {
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    JSONObject link = createLink(LINK_TITLE_ONE, "commented link", LINK_URL_ONE, false, Status.STATUS_OK);
    postLookup.execute();
    feedGenerator.execute();
    int activityNumStart = activityService.getSiteFeedEntries(SITE_SHORT_NAME_LINKS).size();
    String name = getNameFromLink(link);
    link = getLink(name, Status.STATUS_OK);
    String nodeRef = link.getString("nodeRef");
    JSONObject commentOne = createComment(nodeRef, "comment", "content", 200);
    postLookup.execute();
    feedGenerator.execute();
    int activityNumNext = activityService.getSiteFeedEntries(SITE_SHORT_NAME_LINKS).size();
    assertEquals("The activity feeds were not generated after adding a comment", activityNumStart + 1, activityNumNext);
    activityNumStart = activityNumNext;
    NodeRef commentNodeRef = new NodeRef(commentOne.getString("nodeRef"));
    sendRequest(new DeleteRequest(getDeleteCommentUrl(commentNodeRef)), 200);
    postLookup.execute();
    feedGenerator.execute();
    activityNumNext = activityService.getSiteFeedEntries(SITE_SHORT_NAME_LINKS).size();
    assertEquals("The activity feeds were not generated after deleting a comment", activityNumStart + 1, activityNumNext);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 27 with DeleteRequest

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

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest 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)

Example 29 with DeleteRequest

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

the class RatingRestApiTest method testApplyRatingsAsMultipleUsersAndRetrieve.

/**
 * This test method applies ratings from multiple users in a single rating
 * scheme to a single test node. It then retrieves those ratings to ensure they
 * were persisted correctly.
 */
public void testApplyRatingsAsMultipleUsersAndRetrieve() throws Exception {
    // POST a new rating to the testNode - as User One.
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    final String testNodeRatingUrl = getRatingUrl(testNode);
    final float userOneRatingValue = 4.5f;
    String jsonString = new JSONStringer().object().key("rating").value(userOneRatingValue).key("ratingScheme").value(FIVE_STAR_RATING_SCHEME).endObject().toString();
    Response postRsp = sendRequest(new PostRequest(testNodeRatingUrl, jsonString, APPLICATION_JSON), 200);
    String postRspString = postRsp.getContentAsString();
    // Get the returned URL and validate
    JSONObject jsonRsp = new JSONObject(new JSONTokener(postRspString));
    JSONObject dataObj = (JSONObject) jsonRsp.get(DATA);
    assertNotNull("JSON 'data' object was null", dataObj);
    String returnedUrl = dataObj.getString("ratedNodeUrl");
    assertEquals(testNodeRatingUrl, returnedUrl);
    assertEquals(FIVE_STAR_RATING_SCHEME, dataObj.getString("ratingScheme"));
    assertEquals(userOneRatingValue, (float) dataObj.getDouble("rating"));
    assertEquals(userOneRatingValue, (float) dataObj.getDouble("averageRating"));
    assertEquals(userOneRatingValue, (float) dataObj.getDouble("ratingsTotal"));
    assertEquals(1, dataObj.getInt("ratingsCount"));
    // And a second rating
    jsonString = new JSONStringer().object().key("rating").value(1).key("ratingScheme").value(LIKES_RATING_SCHEME).endObject().toString();
    sendRequest(new PostRequest(testNodeRatingUrl, jsonString, APPLICATION_JSON), 200);
    // Now GET the ratings via that returned URL
    Response getRsp = sendRequest(new GetRequest(testNodeRatingUrl), 200);
    String getRspString = getRsp.getContentAsString();
    jsonRsp = new JSONObject(new JSONTokener(getRspString));
    dataObj = (JSONObject) jsonRsp.get(DATA);
    assertNotNull("JSON 'data' object was null", dataObj);
    // There should be two ratings in there.
    final JSONObject ratingsObject = dataObj.getJSONObject(RATINGS);
    assertEquals(2, ratingsObject.length());
    JSONObject recoveredRating = ratingsObject.getJSONObject(FIVE_STAR_RATING_SCHEME);
    assertEquals(userOneRatingValue, (float) recoveredRating.getDouble("rating"));
    // As well as the average, total ratings.
    JSONObject statsObject = dataObj.getJSONObject(NODE_STATISTICS);
    JSONObject fiveStarStats = statsObject.getJSONObject(FIVE_STAR_RATING_SCHEME);
    assertEquals("Average rating was wrong.", userOneRatingValue, (float) fiveStarStats.getDouble(AVERAGE_RATING));
    assertEquals("Ratings count rating was wrong.", 1, fiveStarStats.getInt(RATINGS_COUNT));
    assertEquals("Ratings total was wrong.", userOneRatingValue, (float) fiveStarStats.getDouble(RATINGS_TOTAL));
    JSONObject likesStats = statsObject.getJSONObject(LIKES_RATING_SCHEME);
    assertEquals("Average rating was wrong.", 1f, (float) likesStats.getDouble(AVERAGE_RATING));
    assertEquals("Ratings count rating was wrong.", 1, likesStats.getInt(RATINGS_COUNT));
    assertEquals("Ratings total was wrong.", 1f, (float) likesStats.getDouble(RATINGS_TOTAL));
    // Now POST a second new rating to the testNode - as User Two.
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
    final float userTwoRatingValue = 3.5f;
    jsonString = new JSONStringer().object().key("rating").value(userTwoRatingValue).key("ratingScheme").value(FIVE_STAR_RATING_SCHEME).endObject().toString();
    postRsp = sendRequest(new PostRequest(testNodeRatingUrl, jsonString, APPLICATION_JSON), 200);
    postRspString = postRsp.getContentAsString();
    // Get the returned URL and validate
    jsonRsp = new JSONObject(new JSONTokener(postRspString));
    dataObj = (JSONObject) jsonRsp.get(DATA);
    assertNotNull("JSON 'data' object was null", dataObj);
    returnedUrl = dataObj.getString("ratedNodeUrl");
    assertEquals((userOneRatingValue + userTwoRatingValue) / 2, (float) dataObj.getDouble("averageRating"));
    assertEquals(userOneRatingValue + userTwoRatingValue, (float) dataObj.getDouble("ratingsTotal"));
    assertEquals(2, dataObj.getInt("ratingsCount"));
    // Again GET the ratings via that returned URL
    getRsp = sendRequest(new GetRequest(returnedUrl), 200);
    getRspString = getRsp.getContentAsString();
    jsonRsp = new JSONObject(new JSONTokener(getRspString));
    dataObj = (JSONObject) jsonRsp.get(DATA);
    assertNotNull("JSON 'data' object was null", dataObj);
    // There should still only be the one rating in the results - because we're running
    // as UserTwo and should not see UserOne's rating.
    final JSONObject userTwoRatings = dataObj.getJSONObject(RATINGS);
    assertEquals(1, userTwoRatings.length());
    JSONObject secondRating = (JSONObject) userTwoRatings.getJSONObject(FIVE_STAR_RATING_SCHEME);
    assertEquals(userTwoRatingValue, (float) secondRating.getDouble("rating"));
    // Now the average should have changed.
    statsObject = dataObj.getJSONObject(NODE_STATISTICS);
    fiveStarStats = statsObject.getJSONObject(FIVE_STAR_RATING_SCHEME);
    assertEquals("Average rating was wrong.", (userOneRatingValue + userTwoRatingValue) / 2.0, fiveStarStats.getDouble(AVERAGE_RATING));
    assertEquals("Ratings count rating was wrong.", 2, fiveStarStats.getInt(RATINGS_COUNT));
    assertEquals("Ratings total was wrong.", userOneRatingValue + userTwoRatingValue, (float) fiveStarStats.getDouble(RATINGS_TOTAL));
    // Now DELETE user two's rating.
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
    sendRequest(new DeleteRequest(testNodeRatingUrl + "/" + FIVE_STAR_RATING_SCHEME), 200);
    // GET the ratings again. Although user_one's rating will still be there,
    // user two can't see it and so we should see zero ratings.
    getRsp = sendRequest(new GetRequest(returnedUrl), 200);
    getRspString = getRsp.getContentAsString();
    jsonRsp = new JSONObject(new JSONTokener(getRspString));
    dataObj = (JSONObject) jsonRsp.get(DATA);
    assertNotNull("JSON 'data' object was null", dataObj);
    final JSONObject remainingRatings = dataObj.getJSONObject(RATINGS);
    assertEquals(0, remainingRatings.length());
    // Now the average should have changed.
    statsObject = dataObj.getJSONObject(NODE_STATISTICS);
    fiveStarStats = statsObject.getJSONObject(FIVE_STAR_RATING_SCHEME);
    assertEquals("Average rating was wrong.", userOneRatingValue, (float) fiveStarStats.getDouble(AVERAGE_RATING));
    assertEquals("Ratings count rating was wrong.", 1, fiveStarStats.getInt(RATINGS_COUNT));
    assertEquals("Ratings total was wrong.", userOneRatingValue, (float) fiveStarStats.getDouble(RATINGS_TOTAL));
}
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) JSONStringer(org.json.JSONStringer) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 30 with DeleteRequest

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

the class BlogServiceTest method testDeleteCommentPostActivity.

/**
 * REPO-828 (MNT-16401)
 * @throws Exception
 */
public void testDeleteCommentPostActivity() throws Exception {
    this.authenticationComponent.setCurrentUser(USER_ONE);
    JSONObject item = createPost("testActivity", "test", null, false, 200);
    assertNotNull(item);
    postLookup.execute();
    feedGenerator.execute();
    int activityNumStart = activityService.getSiteFeedEntries(SITE_SHORT_NAME_BLOG).size();
    String nodeRef = item.getString("nodeRef");
    JSONObject commentOne = createComment(nodeRef, "comment", "content", 200);
    assertNotNull(item);
    postLookup.execute();
    feedGenerator.execute();
    int activityNumNext = activityService.getSiteFeedEntries(SITE_SHORT_NAME_BLOG).size();
    assertEquals("The activity feeds were not generated after adding a comment", activityNumStart + 1, activityNumNext);
    activityNumStart = activityNumNext;
    NodeRef commentNodeRef = new NodeRef(commentOne.getString("nodeRef"));
    Response resp = sendRequest(new DeleteRequest(getDeleteCommentUrl(commentNodeRef)), 200);
    assertTrue(resp.getStatus() == 200);
    postLookup.execute();
    feedGenerator.execute();
    activityNumNext = activityService.getSiteFeedEntries(SITE_SHORT_NAME_BLOG).size();
    assertEquals("The activity feeds were not generated after deleting a comment", activityNumStart + 1, activityNumNext);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Aggregations

DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)43 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)32 JSONObject (org.json.JSONObject)29 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)21 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)14 JSONArray (org.json.JSONArray)9 JSONTokener (org.json.JSONTokener)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 UserTransaction (javax.transaction.UserTransaction)3 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 QName (org.alfresco.service.namespace.QName)3 JSONStringer (org.json.JSONStringer)3 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)3 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)2