Search in sources :

Example 11 with DeleteRequest

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

the class SiteServiceTest method testDeleteMembership.

public void testDeleteMembership() throws Exception {
    // Create a site
    String shortName = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    // Build the JSON membership object
    JSONObject membership = new JSONObject();
    membership.put("role", SiteModel.SITE_CONSUMER);
    JSONObject person = new JSONObject();
    person.put("userName", USER_TWO);
    membership.put("person", person);
    // Post the membership
    sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    // Delete the membership
    sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
    // Check that the membership has been deleted
    sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 404);
}
Also used : 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 12 with DeleteRequest

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

the class BlogServiceTest method testComments.

public void testComments() throws Exception {
    JSONObject item = createPost("test", "test", null, false, 200);
    String name = item.getString("name");
    String nodeRef = item.getString("nodeRef");
    JSONObject commentOne = createComment(nodeRef, "comment", "content", 200);
    JSONObject commentTwo = createComment(nodeRef, "comment", "content", 200);
    // fetch the comments
    Response response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertEquals(2, result.getInt("total"));
    // add another one
    JSONObject commentThree = createComment(nodeRef, "comment", "content", 200);
    response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(3, result.getInt("total"));
    // delete the last comment
    response = sendRequest(new DeleteRequest(getCommentUrl(commentThree.getString("nodeRef"))), 200);
    response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(2, result.getInt("total"));
    JSONObject commentTwoUpdated = updateComment(commentTwo.getString("nodeRef"), "new title", "new content", 200);
    assertEquals("new title", commentTwoUpdated.getString("title"));
    assertEquals("new content", commentTwoUpdated.getString("content"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 13 with DeleteRequest

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

the class BlogServiceTest method testCreatePublishedPost.

public void testCreatePublishedPost() throws Exception {
    String title = "published";
    String content = "content";
    JSONObject item = createPost(title, content, null, false, 200);
    final String postName = item.getString("name");
    // check the values
    assertEquals(title, item.get("title"));
    assertEquals(content, item.get("content"));
    assertEquals(false, item.get("isDraft"));
    // check that user two has access to it as well
    this.authenticationComponent.setCurrentUser(USER_TWO);
    getPost(item.getString("name"), 200);
    this.authenticationComponent.setCurrentUser(USER_ONE);
    // Now we'll GET my-published to ensure that the post is there.
    Response response = sendRequest(new GetRequest(URL_MY_PUBLISHED_BLOG_POSTS), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    // we should have posts.size + drafts.size together
    assertEquals(this.posts.size() + this.drafts.size(), result.getInt("total"));
    // Finally, we'll delete the blog-post to test the REST DELETE call.
    response = sendRequest(new DeleteRequest(URL_BLOG_POST + postName), 200);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 14 with DeleteRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest 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"));
}
Also used : JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 15 with DeleteRequest

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

the class CommentsApiTest method deleteComment.

/**
 * delete comment
 *
 * @param commentNodeRef
 * @param parentNodeRef
 * @param user
 * @param status
 * @throws Exception
 */
private void deleteComment(NodeRef commentNodeRef, NodeRef parentNodeRef, String user, int status) throws Exception {
    Response response = null;
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    // Not allowed if you're not an admin
    AuthenticationUtil.setFullyAuthenticatedUser(user);
    String itemTitle = "Test Title";
    String page = "document-details";
    StringBuilder pageParamsBuilder = new StringBuilder("{");
    pageParamsBuilder.append("\"nodeRef\" : \"");
    pageParamsBuilder.append(parentNodeRef.toString());
    pageParamsBuilder.append("\", ");
    pageParamsBuilder.append("}");
    String pageParams = pageParamsBuilder.toString();
    String URL = MessageFormat.format(URL_DELETE_COMMENT, new Object[] { commentNodeRef.getStoreRef().getProtocol(), commentNodeRef.getStoreRef().getIdentifier(), commentNodeRef.getId(), SITE_SHORT_NAME, itemTitle, page, pageParams });
    response = sendRequest(new DeleteRequest(URL), status);
    assertEquals(status, response.getStatus());
    // around the calls. if the WebScript fails, then we should rollback.
    if (response.getStatus() == 500) {
        txn.rollback();
    } else {
        txn.commit();
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) UserTransaction(javax.transaction.UserTransaction) 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