use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class LinksRestApiTest method updateLink.
/**
* Updates the link with the new details
*/
private JSONObject updateLink(String name, 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", "");
json.put("internal", Boolean.toString(internal).toLowerCase());
// TODO Is this really needed?
json.put("page", "links-view");
Response response = sendRequest(new PutRequest(URL_LINKS_UPDATE + name, json.toString(), "application/json"), expectedStatus);
if (expectedStatus == Status.STATUS_OK) {
JSONObject result = new JSONObject(response.getContentAsString());
if (result.has("links")) {
return result.getJSONObject("links");
}
return result;
} else {
return null;
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class PersonServiceTest method updatePerson.
private JSONObject updatePerson(String userName, String title, String firstName, String lastName, String organisation, String jobTitle, String email, String bio, String avatarUrl, int expectedStatus) throws Exception {
// switch to admin user to create a person
String currentUser = this.authenticationComponent.getCurrentUserName();
String adminUser = this.authenticationComponent.getSystemUserName();
this.authenticationComponent.setCurrentUser(adminUser);
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);
Response response = sendRequest(new PutRequest(URL_PEOPLE + "/" + userName, person.toString(), "application/json"), expectedStatus);
// switch back to non-admin user
this.authenticationComponent.setCurrentUser(currentUser);
return new JSONObject(response.getContentAsString());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class CalendarRestApiTest method updateEntry.
/**
* Updates the event to be a 2 hour, non-all day event on the 28th of June
*/
private JSONObject updateEntry(String name, String what, String where, String description, boolean withRecurrence, int expectedStatus) throws Exception {
// A Tuesday
String date = "2011/06/28";
String start = "11:30";
String end = "13:30";
JSONObject json = new JSONObject();
json.put("what", what);
json.put("where", where);
json.put("desc", description);
json.put("from", date);
json.put("to", date);
// json.put("fromdate", "Tuesday, 30 June 2011"); // Not needed
// json.put("todate", "Tuesday, 30 June 2011"); // Not needed
json.put("start", start);
json.put("end", end);
json.put("tags", "");
json.put("docfolder", "");
json.put("page", "calendar");
if (withRecurrence) {
json.put("recurrenceRule", "FREQ=WEEKLY;INTERVAL=2;BYDAY=WE,FR");
json.put("recurrenceLastMeeting", "2011-09-11");
}
Response response = sendRequest(new PutRequest(URL_EVENT_BASE + name, json.toString(), "application/json"), expectedStatus);
if (expectedStatus == Status.STATUS_OK) {
JSONObject result = validateAndParseJSON(response.getContentAsString());
if (result.has("event")) {
return result.getJSONObject("event");
}
if (result.has("data")) {
return result.getJSONObject("data");
}
return result;
} else {
return null;
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class CommentsApiTest method updateComment.
/**
* @param nodeRef
* @param user
* @param expectedStatus
* @return
* @throws Exception
*/
private Response updateComment(NodeRef nodeRef, String user, int expectedStatus) throws Exception {
Response response = null;
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
AuthenticationUtil.setFullyAuthenticatedUser(user);
String now = System.currentTimeMillis() + "";
JSONObject comment = new JSONObject();
comment.put("title", "Test title updated " + now);
comment.put("content", "Test comment updated " + now);
response = sendRequest(new PutRequest(MessageFormat.format(URL_PUT_COMMENT, new Object[] { nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId() }), comment.toString(), JSON), expectedStatus);
assertEquals(expectedStatus, response.getStatus());
// around the calls. if the WebScript fails, then we should rollback.
if (response.getStatus() == 500) {
txn.rollback();
} else {
txn.commit();
}
return response;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class DiscussionRestApiTest method doUpdatePost.
private JSONObject doUpdatePost(String url, String title, String content, int expectedStatus) throws Exception {
JSONObject post = new JSONObject();
post.put("title", title);
post.put("content", content);
Response response = sendRequest(new PutRequest(url, post.toString(), "application/json"), expectedStatus);
if (expectedStatus != Status.STATUS_OK) {
return null;
}
JSONObject result = new JSONObject(response.getContentAsString());
return result.getJSONObject("item");
}
Aggregations