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"));
}
}
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;
}
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());
}
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;
}
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;
}
Aggregations