use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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.PostRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testDeleteMembership.
public void testDeleteMembership() 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
sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
// Delete the membership
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
// Check that the membership has been deleted
sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 404);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class CustomModelImportTest method testValidUpload_ExtModuleOnly.
public void testValidUpload_ExtModuleOnly() throws Exception {
File zipFile = getResourceFile("validExtModule.zip");
PostRequest postRequest = buildMultipartPostRequest(zipFile);
AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
Response response = sendRequest(postRequest, 403);
AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
response = sendRequest(postRequest, 200);
JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
assertFalse(json.has("modelName"));
String extModule = json.getString("shareExtModule");
Document document = XMLUtil.parse(extModule);
NodeList nodes = document.getElementsByTagName("id");
assertEquals(1, nodes.getLength());
assertNotNull(nodes.item(0).getTextContent());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class CustomModelImportTest method testInvalidZipUpload.
public void testInvalidZipUpload() throws Exception {
String content = "<note>" + "<from>Jane</from>" + "<to>John</to>" + "<heading>Upload test</heading>" + "<body>This is an invalid model or a Share extension module</body>" + "</note>";
ZipEntryContext context = new ZipEntryContext("invalidFormat.xml", content.getBytes());
File zipFile = createZip(context);
PostRequest postRequest = buildMultipartPostRequest(zipFile);
// Invalid. Neither a model nor a Share extension module file
sendRequest(postRequest, 400);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class CustomModelImportTest method buildMultipartPostRequest.
public PostRequest buildMultipartPostRequest(File file) throws IOException {
Part[] parts = { new FilePart("filedata", file.getName(), file, "application/zip", null) };
MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new HttpMethodParams());
ByteArrayOutputStream os = new ByteArrayOutputStream();
multipartRequestEntity.writeRequest(os);
PostRequest postReq = new PostRequest(UPLOAD_URL, os.toByteArray(), multipartRequestEntity.getContentType());
return postReq;
}
Aggregations