use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method createNominatedInvitation.
private String createNominatedInvitation(String siteName, String inviteeFirstName, String inviteeLastName, String inviteeEmail, String inviteeUserName, String inviteeRoleName, String serverPath, String acceptURL, String rejectURL, int expectedStatus) 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"), expectedStatus);
JSONObject top = new JSONObject(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
String inviteId = data.getString("inviteId");
return inviteId;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testGetPersonSites.
public void testGetPersonSites() throws Exception {
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
String shortName2 = GUID.generate();
createSite("myPreset", shortName2, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
Response response = sendRequest(new GetRequest("/api/people/" + USER_TWO + "/sites"), 200);
JSONArray result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(0, result.length());
// Add some memberships
JSONObject membership = new JSONObject();
membership.put("role", SiteModel.SITE_CONSUMER);
JSONObject person = new JSONObject();
person.put("userName", USER_TWO);
membership.put("person", person);
sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
membership = new JSONObject();
membership.put("role", SiteModel.SITE_CONSUMER);
person = new JSONObject();
person.put("userName", USER_TWO);
membership.put("person", person);
sendRequest(new PostRequest(URL_SITES + "/" + shortName2 + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
response = sendRequest(new GetRequest("/api/people/" + USER_TWO + "/sites"), 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(2, result.length());
response = sendRequest(new GetRequest("/api/people/" + USER_ONE + "/sites"), 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(2, result.length());
response = sendRequest(new GetRequest("/api/people/" + USER_THREE + "/sites"), 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(0, result.length());
response = sendRequest(new GetRequest("/api/people/" + USER_ONE + "/sites?size=1"), 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(1, result.length());
response = sendRequest(new GetRequest("/api/people/" + USER_ONE + "/sites?size=5"), 200);
result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(2, result.length());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest 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");
return inviteId;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testQuerySites.
/**
* https://issues.alfresco.com/jira/browse/JAWS-456
*/
public void testQuerySites() throws Exception {
// Generate the short names of the sites
String[] shortNames = new String[] { GUID.generate(), GUID.generate(), GUID.generate(), GUID.generate(), GUID.generate() };
// Create the sites
createSite("myPreset", shortNames[0], "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
createSite("myPreset", shortNames[1], "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
createSite("myPreset", shortNames[2], "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
createSite("myPreset", shortNames[3], "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
createSite("myPreset", shortNames[4], "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// build query json
JSONObject shortNameQuery = new JSONObject();
shortNameQuery.put("match", "exact");
JSONArray valuesArray = new JSONArray();
valuesArray.put(0, shortNames[0]);
valuesArray.put(1, shortNames[2]);
valuesArray.put(2, shortNames[4]);
valuesArray.put(3, "bobbins");
shortNameQuery.put("values", valuesArray);
JSONObject query = new JSONObject();
query.put("shortName", shortNameQuery);
// execute site query
Response response = sendRequest(new PostRequest(URL_SITES_QUERY, query.toString(), "application/json"), 200);
JSONArray result = new JSONArray(response.getContentAsString());
// check we have the results we expect
assertEquals(3, result.length());
Set<String> resultSet = new HashSet<String>();
for (int i = 0; i < result.length(); i++) {
resultSet.add((String) result.getJSONObject(i).get("shortName"));
}
assertTrue(resultSet.contains(shortNames[0]));
assertFalse(resultSet.contains(shortNames[1]));
assertTrue(resultSet.contains(shortNames[2]));
assertFalse(resultSet.contains(shortNames[3]));
assertTrue(resultSet.contains(shortNames[4]));
assertFalse(resultSet.contains("bobbins"));
// sample one of the returned sites and check it's what we expect
JSONObject site = result.getJSONObject(0);
assertNotNull(site);
assertEquals("myPreset", site.get("sitePreset"));
assertEquals("myTitle", site.get("title"));
assertEquals("myDescription", site.get("description"));
assertNotNull(site.get("node"));
assertNotNull(site.get("tagScope"));
assertTrue(site.getBoolean("isPublic"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testPutMembership.
public void testPutMembership() 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
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
JSONObject newMember = new JSONObject(response.getContentAsString());
// Update the role by returning the data.
newMember.put("role", SiteModel.SITE_COLLABORATOR);
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, newMember.toString(), "application/json"), 200);
JSONObject result = new JSONObject(response.getContentAsString());
// Check the result
assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
assertEquals(USER_TWO, result.getJSONObject("authority").get("userName"));
// Double check and get the membership for user two
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
result = new JSONObject(response.getContentAsString());
assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
assertEquals(USER_TWO, result.getJSONObject("authority").get("userName"));
}
Aggregations