Search in sources :

Example 41 with Response

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

the class InvitationWebScriptTest method testInvitationsGet.

/**
 * Detailed Test of List Invitation Web Script.
 * Using URL: /api/invitations
 *
 * @param requireAcceptance true if a workflow requiring acceptance is being used
 * @throws Exception
 */
protected void testInvitationsGet(boolean requireAcceptance) throws Exception {
    // Create two sites.
    String shortNameSiteA = GUID.generate();
    createSite("myPreset", shortNameSiteA, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    String shortNameSiteB = GUID.generate();
    createSite("myPreset", shortNameSiteB, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    // Create a moderated invitation on SiteA, USER_TWO
    String inviteeComments = "Please sir, let $* me in";
    String userName = userTwo;
    String roleName = SiteModel.SITE_CONSUMER;
    String moderatedIdAUSER_TWO = createModeratedInvitation(shortNameSiteA, inviteeComments, userName, roleName);
    // Create a moderated invitation on SiteB, USER_TWO
    String moderatedIdBUSER_TWO = createModeratedInvitation(shortNameSiteB, inviteeComments, userName, roleName);
    String inviteeCommentsB = "Please sir, let $* me in";
    String userNameB = userThree;
    String roleNameB = SiteModel.SITE_CONSUMER;
    // Create a moderated invitation on SiteB, USER_THREE
    String moderatedIdBUSER_THREE = createModeratedInvitation(shortNameSiteB, inviteeCommentsB, userNameB, roleNameB);
    String inviteeFirstName = "Buffy";
    String inviteeLastName = "Summers";
    String inviteeEmail = "buffy@sunnydale";
    String inviteeUserName = userName;
    String serverPath = "http://localhost:8081/share/";
    String acceptURL = "page/accept-invite";
    String rejectURL = "page/reject-invite";
    // Create a nominated invitation on SiteA, UsER_TWO
    String nominatedId = createNominatedInvitation(shortNameSiteA, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
    // search by user - find USER_TWO's three invitations
    {
        Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?inviteeUserName=" + userTwo), 200);
        JSONObject top = new JSONObject(response.getContentAsString());
        // System.out.println(response.getContentAsString());
        JSONArray data = top.getJSONArray("data");
        JSONObject moderatedAInv = getInvitation(moderatedIdAUSER_TWO, data);
        assertNotNull("Moderated invitation to Site A not present!", moderatedAInv);
        JSONObject moderatedBInv = getInvitation(moderatedIdBUSER_TWO, data);
        assertNotNull("Moderated invitation to Site B not present!", moderatedBInv);
        JSONObject nominatedInv = getInvitation(nominatedId, data);
        if (requireAcceptance) {
            assertNotNull("Nominated invitation to Site A not present!", nominatedInv);
        }
        checkJSONInvitations(data);
    }
    // search by type - should find three moderated invitations
    {
        Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED"), 200);
        JSONObject top = new JSONObject(response.getContentAsString());
        // System.out.println(response.getContentAsString());
        JSONArray data = top.getJSONArray("data");
        for (int i = 0; i < data.length(); i++) {
            JSONObject obj = data.getJSONObject(i);
            assertEquals("Wrong invitation type", "MODERATED", obj.getString("invitationType"));
        }
        JSONObject moderatedATwoInv = getInvitation(moderatedIdAUSER_TWO, data);
        assertNotNull("first is null", moderatedATwoInv);
        JSONObject moderatedBTwoInv = getInvitation(moderatedIdBUSER_TWO, data);
        assertNotNull("second is null", moderatedBTwoInv);
        JSONObject moderatedBThreeInv = getInvitation(moderatedIdBUSER_THREE, data);
        assertNotNull("third is null", moderatedBThreeInv);
    }
    // Search by type and site
    {
        Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName=" + shortNameSiteA + "&resourceType=WEB_SITE"), 200);
        JSONObject top = new JSONObject(response.getContentAsString());
        JSONArray data = top.getJSONArray("data");
        assertEquals("One moderated invitations not found", 1, data.length());
    }
    // negative test - unknown resourceType
    {
        Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName=" + shortNameSiteA + "&resourceType=madeUpStuff"), 500);
        assertEquals(500, response.getStatus());
        JSONObject top = new JSONObject(response.getContentAsString());
        assertNotNull(top.getString("message"));
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 42 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response 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 43 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response 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)

Example 44 with Response

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

the class InvitationWebScriptTest method createModeratedInvitation.

private String createModeratedInvitation(String siteName, String inviteeComments, String inviteeUserName, String inviteeRoleName) throws Exception {
    /*
         * Create a new moderated invitation
         */
    JSONObject newInvitation = new JSONObject();
    newInvitation.put("invitationType", "MODERATED");
    newInvitation.put("inviteeRoleName", inviteeRoleName);
    newInvitation.put("inviteeComments", inviteeComments);
    newInvitation.put("inviteeUserName", inviteeUserName);
    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 45 with Response

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

the class InviteServiceTest method listInvitations.

private JSONObject listInvitations(String siteShortName, String userNameSearch, int expectedStatus) throws Exception {
    // construct get invites URL
    String getInvitesUrl = "/api/sites/" + siteShortName + "/potentialmembers?authorityType=USER&sortBy=fullName&dir=asc&filter=" + userNameSearch + "&maxResults=250";
    // invoke get invites web script
    Response response = sendRequest(new GetRequest(getInvitesUrl), expectedStatus);
    JSONObject result = new JSONObject(response.getContentAsString());
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)281 JSONObject (org.json.JSONObject)228 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)171 JSONArray (org.json.JSONArray)116 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)84 JSONTokener (org.json.JSONTokener)39 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)37 NodeRef (org.alfresco.service.cmr.repository.NodeRef)34 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)32 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)16 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)16 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 Date (java.util.Date)13 JSONStringer (org.json.JSONStringer)13 UserTransaction (javax.transaction.UserTransaction)12 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)12 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)11 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)11