Search in sources :

Example 16 with PostRequest

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

the class FormRestApiJsonPost_Test method testRemoveChildAssociationsFromNode.

/**
 * This test method attempts to remove an existing child association between two
 * existing nodes.
 */
public void testRemoveChildAssociationsFromNode() throws Exception {
    List<NodeRef> associatedNodes;
    checkOriginalChildAssocsBeforeChanges();
    // Remove an association
    JSONObject jsonPostData = new JSONObject();
    String assocsToRemove = childDoc_B.toString();
    jsonPostData.put(ASSOC_SYS_CHILDREN_REMOVED, assocsToRemove);
    String jsonPostString = jsonPostData.toString();
    sendRequest(new PostRequest(containingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
    // Check the now updated child associations via the node service
    List<ChildAssociationRef> modifiedAssocs = nodeService.getChildAssocs(containerNodeRef);
    assertEquals(1, modifiedAssocs.size());
    // Extract the target nodeRefs to make them easier to examine
    associatedNodes = new ArrayList<NodeRef>(5);
    for (ChildAssociationRef assocRef : modifiedAssocs) {
        associatedNodes.add(assocRef.getChildRef());
    }
    assertTrue(associatedNodes.contains(childDoc_A));
// The Rest API should also give us the modified assocs.
/*Response response = sendRequest(new GetRequest(containingNodeUpdateUrl), 200);
        String jsonRspString = response.getContentAsString();
        JSONObject jsonGetResponse = new JSONObject(jsonRspString);
        JSONObject jsonData = (JSONObject)jsonGetResponse.get("data");
        assertNotNull(jsonData);

        JSONObject jsonFormData = (JSONObject)jsonData.get("formData");
        assertNotNull(jsonFormData);
        
        String jsonAssocs = (String)jsonFormData.get(ASSOC_SYS_CHILDREN);
        
        // We expect exactly 1 assoc on the test node
        assertEquals(1, jsonAssocs.split(",").length);
        for (ChildAssociationRef assocRef : modifiedAssocs)
        {
            assertTrue(jsonAssocs.contains(assocRef.getChildRef().toString()));
        }*/
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 17 with PostRequest

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

the class FormRestApiJsonPost_Test method testRemoveChildAssocThatDoesNotExist.

/**
 * This test method attempts to remove a child association that does not exist. This
 * attempt will not succeed, but the test case is to confirm that there is no
 * exception thrown back across the REST API.
 */
public void testRemoveChildAssocThatDoesNotExist() throws Exception {
    checkOriginalChildAssocsBeforeChanges();
    // Remove a non-existent child association
    JSONObject jsonPostData = new JSONObject();
    String assocsToRemove = childDoc_E.toString();
    jsonPostData.put(ASSOC_SYS_CHILDREN_REMOVED, assocsToRemove);
    String jsonPostString = jsonPostData.toString();
    sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 18 with PostRequest

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

the class GroupsTest method testCreateRootGroup.

/**
 * Detailed test of create root group
 * Detailed test of delete root group
 */
public void testCreateRootGroup() throws Exception {
    String myGroupName = "GT_CRG";
    String myDisplayName = "GT_CRGDisplay";
    /**
     * Negative test - try to create a group without admin authority
     */
    {
        JSONObject newGroupJSON = new JSONObject();
        newGroupJSON.put("displayName", myDisplayName);
        sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR);
    }
    this.authenticationComponent.setSystemUserAsCurrentUser();
    try {
        /**
         * Create a root group
         */
        {
            JSONObject newGroupJSON = new JSONObject();
            newGroupJSON.put("displayName", myDisplayName);
            Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
            JSONObject top = new JSONObject(response.getContentAsString());
            JSONObject rootGroup = top.getJSONObject("data");
            assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName"));
            assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName"));
        }
        /**
         * Negative test Create a root group that already exists
         */
        {
            JSONObject newGroupJSON = new JSONObject();
            newGroupJSON.put("displayName", myDisplayName);
            sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
        }
        /**
         * Delete the root group
         */
        sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK);
        /**
         * Attempt to delete the root group again - should fail
         */
        sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND);
    } finally {
        /**
         * Delete the root group
         */
        sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 19 with PostRequest

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

the class InvitationWebScriptTest method createNominatedInvitation.

private String createNominatedInvitation(String siteName, String inviteeFirstName, String inviteeLastName, String inviteeEmail, String inviteeUserName, String inviteeRoleName, String serverPath, String acceptURL, String rejectURL) throws Exception {
    /*
         * Create a new nominated invitation
         */
    JSONObject newInvitation = new JSONObject();
    newInvitation.put("invitationType", "NOMINATED");
    newInvitation.put("inviteeRoleName", inviteeRoleName);
    if (inviteeUserName != null) {
        // nominate an existing user
        newInvitation.put("inviteeUserName", inviteeUserName);
    } else {
        // nominate someone else
        newInvitation.put("inviteeFirstName", inviteeFirstName);
        newInvitation.put("inviteeLastName", inviteeLastName);
        newInvitation.put("inviteeEmail", inviteeEmail);
    }
    newInvitation.put("serverPath", serverPath);
    newInvitation.put("acceptURL", acceptURL);
    newInvitation.put("rejectURL", rejectURL);
    Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
    JSONObject top = new JSONObject(response.getContentAsString());
    JSONObject data = top.getJSONObject("data");
    String inviteId = data.getString("inviteId");
    createdInvitations.add(new Tracker(inviteId, siteName));
    return inviteId;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 20 with PostRequest

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

the class InvitationWebScriptTest method createSite.

private JSONObject createSite(String sitePreset, String shortName, String title, String description, SiteVisibility visibility, int expectedStatus) throws Exception {
    JSONObject site = new JSONObject();
    site.put("sitePreset", sitePreset);
    site.put("shortName", shortName);
    site.put("title", title);
    site.put("description", description);
    site.put("visibility", visibility.toString());
    Response response = sendRequest(new PostRequest(URL_SITES, site.toString(), "application/json"), expectedStatus);
    this.createdSites.add(shortName);
    return new JSONObject(response.getContentAsString());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Aggregations

PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)110 JSONObject (org.json.JSONObject)90 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)84 JSONArray (org.json.JSONArray)28 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)25 JSONTokener (org.json.JSONTokener)23 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)14 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)10 JSONStringer (org.json.JSONStringer)9 File (java.io.File)8 ZipFile (java.util.zip.ZipFile)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JSONObject (org.json.simple.JSONObject)5 IOException (java.io.IOException)4 UserTransaction (javax.transaction.UserTransaction)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 JSONException (org.json.JSONException)4 Serializable (java.io.Serializable)3