use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class CalendarRestApiTest method testCreateEditDeleteEntry.
// Tests
/**
* Creating, editing, fetching and deleting an entry
*/
public void testCreateEditDeleteEntry() throws Exception {
JSONObject entry;
String name;
// Won't be there to start with
entry = getEntry(EVENT_TITLE_ONE, Status.STATUS_OK);
assertEquals(true, entry.has("error"));
// Create
entry = createEntry(EVENT_TITLE_ONE, "Where", "Thing", Status.STATUS_OK);
name = getNameFromEntry(entry);
assertEquals(EVENT_TITLE_ONE, entry.getString("name"));
assertEquals("Where", entry.getString("where"));
assertEquals("Thing", entry.getString("desc"));
// Different format!
assertEquals("2011-06-29", entry.getJSONObject("startAt").getString("legacyDate"));
// Different format!
assertEquals("2011-06-29", entry.getJSONObject("endAt").getString("legacyDate"));
assertEquals("12:00", entry.getJSONObject("startAt").getString("legacyTime"));
assertEquals("13:00", entry.getJSONObject("endAt").getString("legacyTime"));
assertEquals("false", entry.getString("allday"));
// No isoutlook on create/edit
// Fetch
entry = getEntry(name, Status.STATUS_OK);
assertEquals("Error found " + entry.toString(), false, entry.has("error"));
assertEquals(EVENT_TITLE_ONE, entry.getString("what"));
assertEquals(name, entry.getString("name"));
// Not where...
assertEquals("Where", entry.getString("location"));
// Not desc...
assertEquals("Thing", entry.getString("description"));
assertEquals("false", entry.getString("isoutlook"));
assertEquals("6/29/2011", entry.getJSONObject("startAt").getString("legacyDate"));
assertEquals("6/29/2011", entry.getJSONObject("endAt").getString("legacyDate"));
assertEquals("12:00", entry.getJSONObject("startAt").getString("legacyTime"));
assertEquals("13:00", entry.getJSONObject("endAt").getString("legacyTime"));
assertEquals("false", entry.getString("allday"));
// Check the new style dates too
assertEquals("2011-06-29T12:00:00.000+01:00", entry.getJSONObject("startAt").get("iso8601"));
assertEquals("6/29/2011", entry.getJSONObject("startAt").get("legacyDate"));
assertEquals("12:00", entry.getJSONObject("startAt").get("legacyTime"));
assertEquals("2011-06-29T13:00:00.000+01:00", entry.getJSONObject("endAt").get("iso8601"));
assertEquals("6/29/2011", entry.getJSONObject("endAt").get("legacyDate"));
assertEquals("13:00", entry.getJSONObject("endAt").get("legacyTime"));
// Check the permissions on it
assertEquals(true, entry.has("permissions"));
JSONObject permissions = entry.getJSONObject("permissions");
assertEquals(true, permissions.getBoolean("edit"));
assertEquals(true, permissions.getBoolean("delete"));
// Switch users to consumer, check we can still see it
this.authenticationComponent.setCurrentUser(USER_FOUR);
entry = getEntry(name, Status.STATUS_OK);
assertEquals("Error found " + entry.toString(), false, entry.has("error"));
assertEquals(EVENT_TITLE_ONE, entry.getString("what"));
assertEquals(name, entry.getString("name"));
assertEquals("2011-06-29T12:00:00.000+01:00", entry.getJSONObject("startAt").get("iso8601"));
assertEquals("6/29/2011", entry.getJSONObject("startAt").get("legacyDate"));
assertEquals("12:00", entry.getJSONObject("startAt").get("legacyTime"));
assertEquals("2011-06-29T13:00:00.000+01:00", entry.getJSONObject("endAt").get("iso8601"));
assertEquals("6/29/2011", entry.getJSONObject("endAt").get("legacyDate"));
assertEquals("13:00", entry.getJSONObject("endAt").get("legacyTime"));
// Check the other user sees different permissions
assertEquals(true, entry.has("permissions"));
permissions = entry.getJSONObject("permissions");
assertEquals(false, permissions.getBoolean("edit"));
assertEquals(false, permissions.getBoolean("delete"));
// Back to the main user for more tests
this.authenticationComponent.setCurrentUser(USER_ONE);
// Edit
entry = updateEntry(name, EVENT_TITLE_ONE, "More Where", "More Thing", false, Status.STATUS_OK);
assertEquals("Error found " + entry.toString(), false, entry.has("error"));
assertEquals(EVENT_TITLE_ONE, entry.getString("summary"));
assertEquals("More Where", entry.getString("location"));
assertEquals("More Thing", entry.getString("description"));
// Now uses new style dates
assertEquals("2011-06-28T11:30", entry.getJSONObject("startAt").getString("legacyDateTime"));
assertEquals("2011-06-28T13:30", entry.getJSONObject("endAt").getString("legacyDateTime"));
assertEquals("false", entry.getString("allday"));
// No isoutlook on create/edit
// Fetch
entry = getEntry(name, Status.STATUS_OK);
assertEquals("Error found " + entry.toString(), false, entry.has("error"));
assertEquals(EVENT_TITLE_ONE, entry.getString("what"));
assertEquals(name, entry.getString("name"));
// Not where...
assertEquals("More Where", entry.getString("location"));
assertEquals("More Thing", entry.getString("description"));
assertEquals("false", entry.getString("isoutlook"));
assertEquals("6/28/2011", entry.getJSONObject("startAt").getString("legacyDate"));
assertEquals("6/28/2011", entry.getJSONObject("endAt").getString("legacyDate"));
assertEquals("11:30", entry.getJSONObject("startAt").getString("legacyTime"));
assertEquals("13:30", entry.getJSONObject("endAt").getString("legacyTime"));
assertEquals("false", entry.getString("allday"));
// TODO Make it a whole day event and check that
// Make it recurring
entry = updateEntry(name, EVENT_TITLE_ONE, "More Where", "More Thing", true, Status.STATUS_OK);
// Fetch
entry = getEntry(name, Status.STATUS_OK);
assertEquals("Error found " + entry.toString(), false, entry.has("error"));
assertEquals(EVENT_TITLE_ONE, entry.getString("what"));
assertEquals(name, entry.getString("name"));
// Not where...
assertEquals("More Where", entry.getString("location"));
assertEquals("More Thing", entry.getString("description"));
assertEquals("false", entry.getString("isoutlook"));
assertEquals("6/28/2011", entry.getJSONObject("startAt").getString("legacyDate"));
assertEquals("6/28/2011", entry.getJSONObject("endAt").getString("legacyDate"));
assertEquals("11:30", entry.getJSONObject("startAt").getString("legacyTime"));
assertEquals("13:30", entry.getJSONObject("endAt").getString("legacyTime"));
assertEquals("false", entry.getString("allday"));
assertEquals("Occurs every 2 weeks on Wednesday, Friday, effective " + "28-Jun-2011 until 11-Sep-2011 from 11:30 to 13:30 (BST)", entry.getString("recurrence"));
// Delete
sendRequest(new DeleteRequest(URL_EVENT_BASE + name), Status.STATUS_NO_CONTENT);
// Fetch, will have gone
entry = getEntry(EVENT_TITLE_ONE, Status.STATUS_OK);
assertEquals(true, entry.has("error"));
// Can't delete again
sendRequest(new DeleteRequest(URL_EVENT_BASE + name), Status.STATUS_NOT_FOUND);
// Can't edit it when it's deleted
sendRequest(new PutRequest(URL_EVENT_BASE + name, "{}", "application/json"), Status.STATUS_OK);
assertEquals(true, entry.has("error"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project records-management by Alfresco.
the class EventRestApiTest method testPutRole.
public void testPutRole() throws Exception {
String eventName = GUID.generate();
eventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL);
try {
JSONObject obj = new JSONObject();
obj.put(KEY_EVENT_NAME, eventName);
obj.put(KEY_EVENT_DISPLAY_LABEL, "changed");
obj.put(KEY_EVENT_TYPE, EVENT_TYPE);
// Get the roles
Response rsp = sendRequest(new PutRequest(GET_EVENTS_URL + "/" + eventName, obj.toString(), APPLICATION_JSON), 200);
String rspContent = rsp.getContentAsString();
JSONObject result = new JSONObject(rspContent);
JSONObject eventObj = result.getJSONObject("data");
assertNotNull(eventObj);
assertEquals(eventName, eventObj.get(KEY_EVENT_NAME));
assertEquals("changed", eventObj.get(KEY_EVENT_DISPLAY_LABEL));
assertEquals(EVENT_TYPE, eventObj.get(KEY_EVENT_TYPE));
// Bad requests
obj = new JSONObject();
obj.put(KEY_EVENT_NAME, "cheese");
obj.put(KEY_EVENT_DISPLAY_LABEL, "whatever");
obj.put(KEY_EVENT_TYPE, EVENT_TYPE);
sendRequest(new PutRequest(GET_EVENTS_URL + "/cheese", obj.toString(), APPLICATION_JSON), 404);
} finally {
// Clean up
eventService.removeEvent(eventName);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class RepositoryContainerTest method testLargeContentRequest.
/*
* Test for MNT-11237 : CMIS uploading file larger the 4mb fails
*
* Tests that requests with content larger than 4mb (default memoryThreshold value) can be successfully handled by repository container
*/
public void testLargeContentRequest() throws Exception {
authenticationComponent.setCurrentUser(USER_ONE);
// create the 5 mb size buffer of zero bytes
byte[] content = new byte[5 * 1024 * 1024];
Arrays.fill(content, (byte) 0);
// chek that we can upload file larger than 4 mb
Response response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
assertEquals(SUCCESS, response.getContentAsString());
// trigger the webscript temp folder cleaner job
CronTrigger webscriptsTempFileCleanerJobTrigger = (CronTrigger) getServer().getApplicationContext().getBean("webscripts.tempFileCleanerTrigger");
Scheduler scheduler = (Scheduler) getServer().getApplicationContext().getBean("schedulerFactory");
scheduler.triggerJob(webscriptsTempFileCleanerJobTrigger.getJobKey());
// check that we still can upload file larger than 4 mb, i.e. ensure that cleaner has not deleted temp folder
response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
assertEquals(SUCCESS, response.getContentAsString());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class NodeArchiveServiceRestApiTest method testRestoreDeletedItemsAsNonAdminUser.
/**
* This test method restores some deleted nodes from the archive store for the current user.
*/
public void testRestoreDeletedItemsAsNonAdminUser() throws Exception {
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
String restoreUrl = getArchiveUrl(user2_DeletedTestNode.getStoreRef()) + "/" + user2_DeletedTestNode.getId();
String jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString();
// User_One has the nodeRef of the node deleted by User_Two. User_One is
// not an Admin, so he must not be allowed to restore a node which he doesn’t own.
Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 403);
assertEquals(403, rsp.getStatus());
// Now User_One gets his own archived node and tries to restore it
JSONObject jsonRsp = getArchivedNodes();
JSONObject dataObj = (JSONObject) jsonRsp.get(DATA);
JSONArray deletedNodesArray = (JSONArray) dataObj.get(AbstractArchivedNodeWebScript.DELETED_NODES);
// User_One deleted only 1 node and he doesn't have permission to see other users' archived data.
assertEquals("Unexpectedly found more than 1 item in the archive store.", 1, deletedNodesArray.length());
JSONObject archivedNode = (JSONObject) deletedNodesArray.get(0);
// So we have identified a specific Node in the archive that we want to restore.
String nodeRefString = archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF);
assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
NodeRef nodeRef = new NodeRef(nodeRefString);
// This is its current StoreRef i.e. archive://SpacesStore
restoreUrl = getArchiveUrl(nodeRef.getStoreRef()) + "/" + nodeRef.getId();
int archivedNodesCountBeforeRestore = getArchivedNodesCount();
// Send the PUT REST call.
jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString();
rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200);
assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class BlogServiceTest method testBlogIntegration.
/**
* You can attach information to the blog container relating
* to integration with external blogs.
* This tests that feature
*/
public void testBlogIntegration() throws Exception {
// Try to fetch the details on a new site
Response response = sendRequest(new GetRequest(URL_BLOG_CORE), 200);
String json = response.getContentAsString();
JSONObject result = new JSONObject(json);
assertEquals("No item in:\n" + json, true, result.has("item"));
JSONObject item = result.getJSONObject("item");
assertEquals("Missing key in: " + item, true, item.has("qnamePath"));
assertEquals("Missing key in: " + item, true, item.has("detailsUrl"));
assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl"));
// Blog properties are empty to start
assertEquals("", item.getString("type"));
assertEquals("", item.getString("name"));
assertEquals("", item.getString("description"));
assertEquals("", item.getString("url"));
assertEquals("", item.getString("username"));
assertEquals("", item.getString("password"));
// Have it updated
JSONObject blog = new JSONObject();
blog.put("blogType", "wordpress");
blog.put("blogName", "A Blog!");
blog.put("username", "guest");
sendRequest(new PutRequest(URL_BLOG_CORE, blog.toString(), "application/json"), Status.STATUS_OK);
// Check again now
response = sendRequest(new GetRequest(URL_BLOG_CORE), 200);
json = response.getContentAsString();
result = new JSONObject(json);
assertEquals("No item in:\n" + json, true, result.has("item"));
item = result.getJSONObject("item");
assertEquals("Missing key in: " + item, true, item.has("qnamePath"));
assertEquals("Missing key in: " + item, true, item.has("detailsUrl"));
assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl"));
// Blog properties should now be set
assertEquals("wordpress", item.getString("type"));
assertEquals("A Blog!", item.getString("name"));
assertEquals("", item.getString("description"));
assertEquals("", item.getString("url"));
assertEquals("guest", item.getString("username"));
assertEquals("", item.getString("password"));
}
Aggregations