use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testGetMemberships.
public void testGetMemberships() throws Exception {
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// Check the memberships
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS), 200);
JSONArray result = new JSONArray(response.getContentAsString());
assertNotNull(result);
assertEquals(1, result.length());
JSONObject membership = result.getJSONObject(0);
assertEquals(SiteModel.SITE_MANAGER, membership.get("role"));
assertEquals(USER_ONE, membership.getJSONObject("authority").get("userName"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testUpdateSite.
public void testUpdateSite() throws Exception {
// Create a site
String shortName = GUID.generate();
JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// Update the site
result.put("title", "abs123abc");
result.put("description", "123abc123");
result.put("visibility", SiteVisibility.PRIVATE.toString());
Response response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, result.toString(), "application/json"), 200);
result = new JSONObject(response.getContentAsString());
assertEquals("abs123abc", result.get("title"));
assertEquals("123abc123", result.get("description"));
assertFalse(result.getBoolean("isPublic"));
assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
// Try and get the site and double check it's changed
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
result = new JSONObject(response.getContentAsString());
assertEquals("abs123abc", result.get("title"));
assertEquals("123abc123", result.get("description"));
assertFalse(result.getBoolean("isPublic"));
assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testGetMemberInfo.
public void testGetMemberInfo() throws Exception {
String testGroup = "SiteServiceTestGroupA";
String testGroupName = "GROUP_" + testGroup;
if (!authorityService.authorityExists(testGroupName)) {
this.authenticationComponent.setSystemUserAsCurrentUser();
testGroupName = authorityService.createAuthority(AuthorityType.GROUP, testGroup, testGroup, authorityService.getDefaultZones());
}
if (!authorityService.getContainedAuthorities(AuthorityType.USER, testGroupName, true).contains(USER_TWO)) {
this.authenticationComponent.setSystemUserAsCurrentUser();
this.authorityService.addAuthority(testGroupName, USER_TWO);
}
this.authenticationComponent.setCurrentUser(USER_ONE);
// CRUD a membership group for a web site
// 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 group = new JSONObject();
group.put("fullName", testGroupName);
membership.put("group", group);
// Create a new group membership
{
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
JSONObject newMember = new JSONObject(response.getContentAsString());
// Validate the return value
assertEquals("role not correct", SiteModel.SITE_CONSUMER, newMember.getString("role"));
JSONObject newGroup = newMember.getJSONObject("authority");
assertNotNull(newGroup);
assertEquals("full name not correct", testGroupName, newGroup.getString("fullName"));
assertEquals("authorityType not correct", "GROUP", newGroup.getString("authorityType"));
}
// Now List memberships
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "?authorityType=USER"), 200);
JSONArray listResult = new JSONArray(response.getContentAsString());
assertNotNull(listResult);
assertEquals(2, listResult.length());
for (int i = 0; i < listResult.length(); i++) {
JSONObject json = listResult.getJSONObject(i);
if (USER_ONE.equals(json.getJSONObject("authority").get("fullName"))) {
assertEquals("user one is Not member of any group", false, json.get("isMemberOfGroup"));
} else {
assertEquals("full name not correct", USER_TWO, json.getJSONObject("authority").get("fullName"));
assertEquals("user two is member of a SiteServiceTestGroupA group", true, json.get("isMemberOfGroup"));
}
}
}
// cleanup
if (authorityService.authorityExists(testGroupName)) {
this.authenticationComponent.setSystemUserAsCurrentUser();
this.authorityService.deleteAuthority(testGroupName);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testChangeSiteVisibilityAsSiteAdmin.
public void testChangeSiteVisibilityAsSiteAdmin() throws Exception {
// Create a site
String shortName = GUID.generate();
// Create a new site
JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
// try to change the site visibility as user2
this.authenticationComponent.setCurrentUser(USER_TWO);
JSONObject changeVisibility = new JSONObject();
changeVisibility.put("shortName", shortName);
changeVisibility.put("visibility", "PRIVATE");
// we should get AccessDeniedException
sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 500);
SiteInfo siteInfo = siteService.getSite(shortName);
assertEquals("Site visibility should not have been changed.", SiteVisibility.PUBLIC, siteInfo.getVisibility());
// set the current user as site-admin
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
// Change the visibility to private
Response response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 200);
JSONObject jsonObj = new JSONObject(response.getContentAsString());
assertEquals(SiteVisibility.PRIVATE.toString(), jsonObj.get("visibility"));
// Change the visibility to moderated. We want to test if we can find
// the private site before changing its visibility
changeVisibility.put("visibility", "MODERATED");
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 200);
jsonObj = new JSONObject(response.getContentAsString());
assertEquals(SiteVisibility.MODERATED.toString(), jsonObj.get("visibility"));
// Remove user4 from the site-admin group
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
authorityService.removeAuthority("GROUP_SITE_ADMINISTRATORS", USER_FOUR_AS_SITE_ADMIN);
// set the current user as site-admin
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
// Now that we have removed user4 from the group, try to test if he can still modify the site
changeVisibility.put("visibility", "PUBLIC");
sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 500);
siteInfo = siteService.getSite(shortName);
assertEquals("Site visibility should not have been changed.", SiteVisibility.MODERATED, siteInfo.getVisibility());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testGetAllSitesAsSiteAdmin.
public void testGetAllSitesAsSiteAdmin() throws Exception {
String user1PublicSiteName = GUID.generate();
String user1ModeratedSiteName = GUID.generate();
String user1PrivateSiteName = GUID.generate();
String user2PrivateSiteName = GUID.generate();
// USER_ONE public site
JSONObject result = createSite("myPreset", user1PublicSiteName, "u1PublicSite", "myDescription", SiteVisibility.PUBLIC, 200);
assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
// USER_ONE moderated site
result = createSite("myPreset", user1ModeratedSiteName, "u1ModeratedSite", "myDescription", SiteVisibility.MODERATED, 200);
assertEquals(SiteVisibility.MODERATED.toString(), result.get("visibility"));
// USER_ONE private site
result = createSite("myPreset", user1PrivateSiteName, "u1PrivateSite", "myDescription", SiteVisibility.PRIVATE, 200);
assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
this.authenticationComponent.setCurrentUser(USER_TWO);
// USER_TWO private site
result = createSite("myPreset", user2PrivateSiteName, "u2PrivateSite", "myDescription", SiteVisibility.PRIVATE, 200);
assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
this.authenticationComponent.setCurrentUser(USER_THREE);
// Note: we'll get 404 rather than 403
sendRequest(new GetRequest(URL_SITES_ADMIN), 404);
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
Response response = sendRequest(new GetRequest(URL_SITES_ADMIN), 200);
JSONObject jsonObject = new JSONObject(response.getContentAsString());
JSONArray jsonArray = jsonObject.getJSONObject("list").getJSONArray("entries");
int siteAdminGetSitesSize = jsonArray.length();
// SiteAdmin can see the public, moderated and private sites
assertTrue("result too small", siteAdminGetSitesSize >= 4);
assertTrue("Site admin can access all the sites (PUBLIC | MODERATED | PRIVATE).", canSeePrivateSites(jsonArray));
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new GetRequest(URL_SITES_ADMIN), 200);
jsonObject = new JSONObject(response.getContentAsString());
jsonArray = jsonObject.getJSONObject("list").getJSONArray("entries");
;
assertEquals("SiteAdmin must have access to the same sites as the super Admin.", siteAdminGetSitesSize, jsonArray.length());
}
Aggregations