use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class QuickShareRestApiTest method testCopy.
/**
* This test verifies that copying a shared node does not across the shared aspect and it's associated properties.
* @throws IOException
* @throws UnsupportedEncodingException
* @throws JSONException
* @throws FileNotFoundException
* @throws FileExistsException
*/
public void testCopy() throws UnsupportedEncodingException, IOException, JSONException, FileExistsException, FileNotFoundException {
final int expectedStatusOK = 200;
String testNodeRef = testNode.toString().replace("://", "/");
// As user one ...
// share
Response rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", testNodeRef), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
JSONObject 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());
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
FileInfo copyFileInfo = fileFolderService.copy(testNode, userOneHome, "Copied node");
NodeRef copyNodeRef = copyFileInfo.getNodeRef();
assertFalse(nodeService.hasAspect(copyNodeRef, QuickShareModel.ASPECT_QSHARE));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class QuickShareTurnedOffRestApiTest method testQuickShareDisabled.
public void testQuickShareDisabled() throws IOException {
String testNodeRef = "workspace://SpacesStore/" + GUID.generate();
sendRequest(new PostRequest(SHARE_URL.replace("{node_ref}", testNodeRef), "", APPLICATION_JSON), 403, AuthenticationUtil.getAdminUserName());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class BlogServiceTest method createPost.
private JSONObject createPost(String title, String content, String[] tags, boolean isDraft, int expectedStatus) throws Exception {
JSONObject post = getRequestObject(title, content, tags, isDraft);
Response response = sendRequest(new PostRequest(URL_BLOG_POSTS, post.toString(), "application/json"), expectedStatus);
if (expectedStatus != 200) {
return null;
}
// logger.debug(response.getContentAsString());
JSONObject result = new JSONObject(response.getContentAsString());
JSONObject item = result.getJSONObject("item");
if (isDraft) {
this.drafts.add(item.getString("name"));
} else {
this.posts.add(item.getString("name"));
}
return item;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class CalendarRestApiTest method createEntry.
/**
* Creates an event, with the date properties manually set
*/
private JSONObject createEntry(String name, String where, String description, JSONObject datesJSON, int expectedStatus) throws Exception {
JSONObject json = new JSONObject();
json.put("site", SITE_SHORT_NAME_CALENDAR);
json.put("what", name);
json.put("where", where);
json.put("desc", description);
json.put("tags", "");
json.put("docfolder", "");
json.put("page", "calendar");
// Copy in the date properties
for (String key : getKeys(datesJSON, false)) {
json.put(key, datesJSON.get(key));
}
Response response = sendRequest(new PostRequest(URL_EVENT_CREATE, json.toString(), "application/json"), expectedStatus);
if (expectedStatus == Status.STATUS_OK) {
JSONObject result = validateAndParseJSON(response.getContentAsString());
if (result.has("event")) {
return result.getJSONObject("event");
}
return result;
} else {
return null;
}
}
Aggregations