use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class RuleServiceTest method testQueueAction.
public void testQueueAction() throws Exception {
String url = formateQueueActionUrl(false);
JSONObject copyAction = buildCopyAction(testWorkNodeRef);
copyAction.put("actionedUponNode", testNodeRef);
// execute before response (should be successful)
Response successResponse = sendRequest(new PostRequest(url, copyAction.toString(), "application/json"), 200);
JSONObject successResult = new JSONObject(successResponse.getContentAsString());
assertNotNull(successResult);
assertTrue(successResult.has("data"));
JSONObject successData = successResult.getJSONObject("data");
assertTrue(successData.has("status"));
assertEquals("success", successData.getString("status"));
assertTrue(successData.has("actionedUponNode"));
assertFalse(successData.has("exception"));
assertTrue(successData.has("action"));
// execute before response (should fail)
sendRequest(new PostRequest(url, copyAction.toString(), "application/json"), 500);
// execute after response (should fail but error should not present in response)
String asyncUrl = formateQueueActionUrl(true);
Response response = sendRequest(new PostRequest(asyncUrl, copyAction.toString(), "application/json"), 200);
// wait while action executed
Thread.sleep(1000);
JSONObject result = new JSONObject(response.getContentAsString());
assertNotNull(result);
assertTrue(result.has("data"));
JSONObject data = result.getJSONObject("data");
assertTrue(data.has("status"));
assertEquals("queued", data.getString("status"));
assertTrue(data.has("actionedUponNode"));
assertFalse(data.has("exception"));
assertTrue(data.has("action"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class AbstractSiteServiceTest method createSite.
protected 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 SiteExportServiceTest method testExportSiteWithMutipleUsers.
public void testExportSiteWithMutipleUsers() throws Exception {
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// add a user and a person as members
addSiteMember(USER_FROM_LDAP, shortName);
addSiteMember(USER_ONE, shortName);
// Export site
Response response = sendRequest(new GetRequest(getExportUrl(shortName)), 200);
// check exported files
List<String> entries = getEntries(new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray())));
assertFalse(entries.contains("No_Users_In_Site.txt"));
assertFalse(entries.contains("No_Persons_In_Site.txt"));
assertTrue(entries.contains("People.acp"));
assertTrue(entries.contains(shortName + "-people.xml"));
assertTrue(entries.contains("Users.acp"));
assertTrue(entries.contains(shortName + "-users.xml"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testListInvitation.
/**
* Detailed Test of List Invitation Web Script.
* @throws Exception
*/
public void testListInvitation() throws Exception {
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
String inviteeComments = "Please sir, let $* me in";
String userName = USER_TWO;
String roleName = SiteModel.SITE_CONSUMER;
String moderatedIdA = createModeratedInvitation(shortName, inviteeComments, userName, roleName);
String inviteeCommentsB = "Please sir, let $* me in";
String userNameB = USER_THREE;
String roleNameB = SiteModel.SITE_CONSUMER;
String moderatedIdB = createModeratedInvitation(shortName, 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
String nominatedId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL, 201);
/**
* search by user - negative test wombat does not have an invitation
*/
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=wombat"), 200);
JSONObject top = new JSONObject(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("user wombat", data.length(), 0);
}
/**
* search by user - find USER_TWO's invitation
*/
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + USER_TWO), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("user two invitation not found", 1, data.length());
JSONObject first = data.getJSONObject(0);
assertEquals("userid is wrong", first.getString("inviteeUserName"), USER_TWO);
}
/**
* search by type - should find two moderated invitations
*/
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?invitationType=MODERATED"), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("two moderated invitations not found", data.length(), 2);
}
// negative test - unknown invitationType
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?invitationType=Crap"), 500);
JSONObject top = new JSONObject(response.getContentAsString());
}
/**
* search by user and type
*/
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + USER_TWO + "&invitationType=MODERATED"), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertEquals("user two invitation not found", data.length(), 1);
JSONObject first = data.getJSONObject(0);
assertEquals("first userid is wrong", first.getString("inviteeUserName"), USER_TWO);
assertEquals("type is wrong", first.getString("invitationType"), "MODERATED");
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testChangeMembershipRoleAsSiteAdmin.
public void testChangeMembershipRoleAsSiteAdmin() 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 jsonObj = new JSONObject(response.getContentAsString());
// Check the result
assertEquals(SiteModel.SITE_CONSUMER, jsonObj.get("role"));
assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
// try to change the user role as user3
this.authenticationComponent.setCurrentUser(USER_THREE);
membership.put("role", SiteModel.SITE_COLLABORATOR);
sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 500);
assertEquals("User's role should not have been changed.", SiteModel.SITE_CONSUMER.toString(), siteService.getMembersRole(shortName, USER_TWO));
// set the current user as site-admin
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
jsonObj = new JSONObject(response.getContentAsString());
// Check the result
assertEquals(SiteModel.SITE_COLLABORATOR, jsonObj.get("role"));
assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
}
Aggregations