use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testGetPotentialMemberships.
/**
* @since 4.0
*/
public void testGetPotentialMemberships() throws Exception {
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// Check the memberships
String filter = "";
String authorityType = "GROUP";
String url = "/api/sites/" + shortName + "/potentialmembers?filter=" + filter + "&maxResults=10&authorityType=" + authorityType;
Response response = sendRequest(new GetRequest(url), 200);
final String contentAsString = response.getContentAsString();
JSONObject result = new JSONObject(contentAsString);
assertNotNull(result);
JSONArray people = result.getJSONArray("people");
assertNotNull("people array was null", people);
JSONArray data = result.getJSONArray("data");
assertNotNull("data array was null", data);
// Delete the site
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testDeleteMembershipAsSiteAdmin.
public void testDeleteMembershipAsSiteAdmin() 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 delete user2 from the site
this.authenticationComponent.setCurrentUser(USER_THREE);
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 500);
assertTrue(USER_THREE + " doesn’t have permission to delete users from the site", siteService.isMember(shortName, USER_TWO));
// set the current user as site-admin
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
assertFalse(siteService.isMember(shortName, USER_TWO));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project records-management by Alfresco.
the class RmRestApiTest method testMob1630ShouldNotBeAbleToCreateTwoSupersedesReferencesOnOneRecordPair.
public void testMob1630ShouldNotBeAbleToCreateTwoSupersedesReferencesOnOneRecordPair() throws Exception {
// Create 2 test records.
NodeRef testRecord1 = utils.createRecord(recordFolder, "testRecord1" + System.currentTimeMillis(), "The from recørd");
NodeRef testRecord2 = utils.createRecord(recordFolder, "testRecord2" + System.currentTimeMillis(), "The to récord");
String node1Url = testRecord1.toString().replace("://", "/");
String node2Url = testRecord2.toString().replace("://", "/");
String refInstancesRecord1Url = MessageFormat.format(REF_INSTANCES_URL_FORMAT, node1Url);
String refInstancesRecord2Url = MessageFormat.format(REF_INSTANCES_URL_FORMAT, node2Url);
{
// Sanity check. There should be no references defined on these new records.
Response rsp = sendRequest(new GetRequest(refInstancesRecord1Url), 200);
String rspContent = rsp.getContentAsString();
JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
JSONObject dataObj = jsonRsp.getJSONObject("data");
JSONArray refsFrom = dataObj.getJSONArray("customReferencesFrom");
JSONArray refsTo = dataObj.getJSONArray("customReferencesTo");
assertEquals("Incorrect from-refs count.", 0, refsFrom.length());
assertEquals("Incorrect to-refs count.", 0, refsTo.length());
}
// Add a supersedes ref instance between them
final String supersedesRefLocalName = CUSTOM_REF_SUPERSEDES.getLocalName();
String jsonString = new JSONStringer().object().key("toNode").value(testRecord2.toString()).key("refId").value(supersedesRefLocalName).endObject().toString();
Response rsp = sendRequest(new PostRequest(refInstancesRecord1Url, jsonString, APPLICATION_JSON), 200);
// The bug is that we can apply two such references which should not be allowed
rsp = sendRequest(new PostRequest(refInstancesRecord1Url, jsonString, APPLICATION_JSON), 500);
{
// Retrieve reference instances on this pair of records.
// The first record
rsp = sendRequest(new GetRequest(refInstancesRecord1Url), 200);
String rspContent = rsp.getContentAsString();
JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
JSONObject dataObj = jsonRsp.getJSONObject("data");
JSONArray refsFrom = dataObj.getJSONArray("customReferencesFrom");
JSONArray refsTo = dataObj.getJSONArray("customReferencesTo");
assertEquals("Incorrect from-refs count.", 1, refsFrom.length());
assertEquals("Incorrect to-refs count.", 0, refsTo.length());
// The second record - the back-reference
rsp = sendRequest(new GetRequest(refInstancesRecord2Url), 200);
rspContent = rsp.getContentAsString();
jsonRsp = new JSONObject(new JSONTokener(rspContent));
dataObj = jsonRsp.getJSONObject("data");
refsFrom = dataObj.getJSONArray("customReferencesFrom");
refsTo = dataObj.getJSONArray("customReferencesTo");
assertEquals("Incorrect from-refs count.", 0, refsFrom.length());
assertEquals("Incorrect to-refs count.", 1, refsTo.length());
}
// Delete the reference instance
String protocol = testRecord2.getStoreRef().getProtocol();
String identifier = testRecord2.getStoreRef().getIdentifier();
String recId = testRecord2.getId();
final String queryFormat = "?st={0}&si={1}&id={2}";
String urlQueryString = MessageFormat.format(queryFormat, protocol, identifier, recId);
rsp = sendRequest(new DeleteRequest(refInstancesRecord1Url + "/" + supersedesRefLocalName + urlQueryString), 200);
assertTrue(rsp.getContentAsString().contains("success"));
{
// Retrieve reference instances on this pair of records.
// The first record
rsp = sendRequest(new GetRequest(refInstancesRecord1Url), 200);
String rspContent = rsp.getContentAsString();
JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
JSONObject dataObj = jsonRsp.getJSONObject("data");
JSONArray refsFrom = dataObj.getJSONArray("customReferencesFrom");
JSONArray refsTo = dataObj.getJSONArray("customReferencesTo");
assertEquals("Incorrect from-refs count.", 0, refsFrom.length());
assertEquals("Incorrect to-refs count.", 0, refsTo.length());
// The second record - the back-reference
rsp = sendRequest(new GetRequest(refInstancesRecord2Url), 200);
rspContent = rsp.getContentAsString();
jsonRsp = new JSONObject(new JSONTokener(rspContent));
dataObj = jsonRsp.getJSONObject("data");
refsFrom = dataObj.getJSONArray("customReferencesFrom");
refsTo = dataObj.getJSONArray("customReferencesTo");
assertEquals("Incorrect from-refs count.", 0, refsFrom.length());
assertEquals("Incorrect to-refs count.", 0, refsTo.length());
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project records-management by Alfresco.
the class RmRestApiTest method testGetPostAndRemoveCustomReferenceInstances.
public void testGetPostAndRemoveCustomReferenceInstances() throws Exception {
NodeRef testRecord1 = utils.createRecord(recordFolder, "testRecord1" + System.currentTimeMillis(), "The from recørd");
NodeRef testRecord2 = utils.createRecord(recordFolder, "testRecord2" + System.currentTimeMillis(), "The to récord");
String node1Url = testRecord1.toString().replace("://", "/");
String refInstancesRecord1Url = MessageFormat.format(REF_INSTANCES_URL_FORMAT, node1Url);
// Create reference types.
String[] generatedRefIds = postCustomReferenceDefinitions();
// Add a standard ref
String jsonString = new JSONStringer().object().key("toNode").value(testRecord2.toString()).key("refId").value(generatedRefIds[1]).endObject().toString();
Response rsp = sendRequest(new PostRequest(refInstancesRecord1Url, jsonString, APPLICATION_JSON), 200);
// Add a child ref
jsonString = new JSONStringer().object().key("toNode").value(testRecord2.toString()).key("refId").value(generatedRefIds[0]).endObject().toString();
// System.out.println(jsonString);
rsp = sendRequest(new PostRequest(refInstancesRecord1Url, jsonString, APPLICATION_JSON), 200);
// System.out.println(rsp.getContentAsString());
// Now retrieve the applied references from the REST API
// 1. references on the 'from' record.
rsp = sendRequest(new GetRequest(refInstancesRecord1Url), 200);
String contentAsString = rsp.getContentAsString();
// System.out.println(contentAsString);
JSONObject jsonRsp = new JSONObject(new JSONTokener(contentAsString));
JSONObject dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
JSONArray customRefsFromArray = (JSONArray) dataObj.get("customReferencesFrom");
assertNotNull("JSON 'customReferencesFrom' object was null", customRefsFromArray);
int customRefsCount = customRefsFromArray.length();
assertTrue("There should be at least one custom reference. Found " + customRefsFromArray, customRefsCount > 0);
JSONArray customRefsToArray = (JSONArray) dataObj.get("customReferencesTo");
assertNotNull("JSON 'customReferencesTo' object was null", customRefsToArray);
assertEquals("customReferencesTo wrong length.", 0, customRefsToArray.length());
// 2. Back-references on the 'to' record
String node2Url = testRecord2.toString().replace("://", "/");
String refInstancesRecord2Url = MessageFormat.format(REF_INSTANCES_URL_FORMAT, node2Url);
rsp = sendRequest(new GetRequest(refInstancesRecord2Url), 200);
contentAsString = rsp.getContentAsString();
jsonRsp = new JSONObject(new JSONTokener(contentAsString));
dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
customRefsToArray = (JSONArray) dataObj.get("customReferencesTo");
assertNotNull("JSON 'customReferencesTo' object was null", customRefsToArray);
customRefsCount = customRefsToArray.length();
assertTrue("There should be at least one custom reference. Found " + customRefsToArray, customRefsCount > 0);
customRefsFromArray = (JSONArray) dataObj.get("customReferencesFrom");
assertNotNull("JSON 'customReferencesFrom' object was null", customRefsFromArray);
assertEquals("customReferencesFrom wrong length.", 0, customRefsFromArray.length());
// Now to delete a reference instance of each type
String protocol = testRecord2.getStoreRef().getProtocol();
String identifier = testRecord2.getStoreRef().getIdentifier();
String recId = testRecord2.getId();
final String queryFormat = "?st={0}&si={1}&id={2}";
String urlQueryString = MessageFormat.format(queryFormat, protocol, identifier, recId);
rsp = sendRequest(new DeleteRequest(refInstancesRecord1Url + "/" + generatedRefIds[1] + urlQueryString), 200);
assertTrue(rsp.getContentAsString().contains("success"));
rsp = sendRequest(new DeleteRequest(refInstancesRecord1Url + "/" + generatedRefIds[0] + urlQueryString), 200);
assertTrue(rsp.getContentAsString().contains("success"));
// Get the reference instances back and confirm they've been removed.
rsp = sendRequest(new GetRequest(refInstancesRecord1Url), 200);
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
customRefsFromArray = (JSONArray) dataObj.get("customReferencesFrom");
assertNotNull("JSON 'customReferences' object was null", customRefsFromArray);
assertTrue("customRefsArray was unexpectedly not empty.", customRefsFromArray.length() == 0);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project records-management by Alfresco.
the class RmRestApiTest method testAudit.
public void testAudit() throws Exception {
// call the list service to get audit events
Response rsp = sendRequest(new GetRequest(GET_LIST_URL), 200);
// System.out.println("GET : " + rsp.getContentAsString());
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
// get response as JSON and check
JSONObject jsonParsedObject = new JSONObject(new JSONTokener(rsp.getContentAsString()));
assertNotNull(jsonParsedObject);
JSONObject data = jsonParsedObject.getJSONObject("data");
JSONObject events = data.getJSONObject("auditEvents");
JSONArray items = events.getJSONArray("items");
assertEquals(auditService.getAuditEvents().size(), items.length());
assertTrue(items.length() > 0);
JSONObject item = items.getJSONObject(0);
assertTrue(item.length() == 2);
assertTrue(item.has("label"));
assertTrue(item.has("value"));
// get the full RM audit log and check response
rsp = sendRequest(new GetRequest(RMA_AUDITLOG_URL), 200);
assertEquals("application/json", rsp.getContentType());
JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
// get the full RM audit log as an HTML report and check response
rsp = sendRequest(new GetRequest(RMA_AUDITLOG_URL + "?format=html"), 200);
assertEquals("text/html", rsp.getContentType());
// export the full RM audit log and check response
rsp = sendRequest(new GetRequest(RMA_AUDITLOG_URL + "?export=true"), 200);
assertEquals("application/json", rsp.getContentType());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
// construct the URL
String nodeUrl = recordCategory.toString().replace("://", "/");
String auditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT, nodeUrl);
// send request
rsp = sendRequest(new GetRequest(auditUrl), 200);
// check response
assertEquals("application/json", rsp.getContentType());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
// get the audit log with all restrictions in place
String filteredAuditUrl = auditUrl + "?user=gavinc&size=5&from=2009-01-01&to=2009-12-31&event=Login";
rsp = sendRequest(new GetRequest(filteredAuditUrl), 200);
// check response
assertEquals("application/json", rsp.getContentType());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
// attempt to get the audit log with invalid restrictions in place
filteredAuditUrl = auditUrl + "?user=fred&size=abc&from=2009&to=2010&property=wrong";
rsp = sendRequest(new GetRequest(filteredAuditUrl), 200);
assertEquals("application/json", rsp.getContentType());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
checkAuditStatus(true);
// start the RM audit log
JSONObject jsonPostData = new JSONObject();
jsonPostData.put("enabled", true);
String jsonPostString = jsonPostData.toString();
rsp = sendRequest(new PutRequest(RMA_AUDITLOG_URL, jsonPostString, APPLICATION_JSON), 200);
checkAuditStatus(true);
// check the response
// System.out.println(rsp.getContentAsString());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
JSONObject dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
assertTrue(dataObj.getBoolean("enabled"));
assertTrue(dataObj.has("started"));
assertTrue(dataObj.has("stopped"));
// stop the RM audit log
jsonPostData = new JSONObject();
jsonPostData.put("enabled", false);
jsonPostString = jsonPostData.toString();
rsp = sendRequest(new PutRequest(RMA_AUDITLOG_URL, jsonPostString, APPLICATION_JSON), 200);
checkAuditStatus(false);
// check the response
// System.out.println(rsp.getContentAsString());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
assertFalse(dataObj.getBoolean("enabled"));
// clear the RM audit log
rsp = sendRequest(new DeleteRequest(RMA_AUDITLOG_URL), 200);
// System.out.println(rsp.getContentAsString());
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
assertFalse(dataObj.getBoolean("enabled"));
}
Aggregations