use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class CalendarRestApiTest method getEntries.
private JSONObject getEntries(String username, String from) throws Exception {
String url = URL_EVENTS_LIST + "?site=" + SITE_SHORT_NAME_CALENDAR;
if (username != null) {
url = URL_USER_SITE_EVENTS_LIST;
}
if (from != null) {
if (url.indexOf('?') > 0) {
url += "&";
} else {
url += "?";
}
url += "from=" + from;
}
Response response = sendRequest(new GetRequest(url), 200);
JSONObject result = validateAndParseJSON(response.getContentAsString());
return result;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.
the class RMCaveatConfigScriptTest method testGetRMConstraintValues.
public void testGetRMConstraintValues() throws Exception {
createUser("fbloggs");
createUser("jrogers");
createUser("jdoe");
/**
* Delete the list to remove any junk then recreate it.
*/
{
if (caveatConfigService.getRMConstraint(RM_LIST) != null) {
caveatConfigService.deleteRMConstraint(RM_LIST);
}
caveatConfigService.addRMConstraint(RM_LIST, "my title", new String[0]);
List<String> values = new ArrayList<String>();
values.add("NOFORN");
values.add("FGI");
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "fbloggs", values);
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jrogers", values);
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jdoe", values);
}
/**
* Positive test Get the constraint
*/
{
String url = URL_RM_CONSTRAINTS + "/" + RM_LIST_URI_ELEM + "/values";
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
System.out.println(response.getContentAsString());
String constraintName = data.getString("constraintName");
assertNotNull("constraintName is null", constraintName);
String constraintTitle = data.getString("constraintTitle");
assertNotNull("constraintTitle is null", constraintTitle);
JSONArray values = data.getJSONArray("values");
assertTrue("details array does not contain 2 elements", values.length() == 2);
boolean fgiFound = false;
boolean nofornFound = false;
for (int i = 0; i < values.length(); i++) {
JSONObject value = values.getJSONObject(i);
if (value.getString("valueName").equalsIgnoreCase("FGI")) {
fgiFound = true;
}
if (value.getString("valueName").equalsIgnoreCase("NOFORN")) {
nofornFound = true;
}
}
assertTrue("fgi not found", fgiFound);
assertTrue("noforn not found", nofornFound);
}
deleteUser("fbloggs");
deleteUser("jrogers");
deleteUser("jdoe");
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.
the class RmRestApiTest method testGetDodCustomTypes.
public void testGetDodCustomTypes() throws IOException, JSONException {
final int expectedStatus = 200;
Response rsp = sendRequest(new GetRequest("/api/rma/admin/dodcustomtypes"), expectedStatus);
String rspContent = rsp.getContentAsString();
JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
// System.out.println(rspContent);
JSONObject dataObj = (JSONObject) jsonRsp.get("data");
assertNotNull("JSON 'data' object was null", dataObj);
JSONArray customTypesObj = (JSONArray) dataObj.get("dodCustomTypes");
assertNotNull("JSON 'dodCustomTypes' object was null", customTypesObj);
assertEquals("Wrong DOD custom types count.", 4, customTypesObj.length());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.
the class RmRestApiTest method postCustomPropertyDefinition.
/**
* Creates a new property definition using a POST call.
* GETs the resultant property definition.
*
* @param propertyLabel the label to use
* @param propId the propId to use - null to have one generated.
* @return the propId of the new property definition
*/
private String postCustomPropertyDefinition(String propertyLabel, String propId) throws JSONException, IOException, UnsupportedEncodingException {
String jsonString;
if (propId == null) {
jsonString = new JSONStringer().object().key("label").value(propertyLabel).key("description").value("Dynamically defined test property").key("mandatory").value(false).key("dataType").value("d:text").key("element").value("record").key("constraintRef").value("rmc:smList").endObject().toString();
} else {
jsonString = new JSONStringer().object().key("label").value(propertyLabel).key("description").value("Dynamically defined test property").key("mandatory").value(false).key("dataType").value("d:text").key("element").value("record").key("constraintRef").value("rmc:smList").key("propId").value(propId).endObject().toString();
}
// Submit the JSON request.
final int expectedStatus = 200;
Response rsp = sendRequest(new PostRequest("/api/rma/admin/custompropertydefinitions?element=record", jsonString, APPLICATION_JSON), expectedStatus);
String rspContent = rsp.getContentAsString();
// System.out.println(rspContent);
JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
String urlOfNewPropDef = jsonRsp.getString("url");
String newPropId = jsonRsp.getString("propId");
assertNotNull("urlOfNewPropDef was null.", urlOfNewPropDef);
// GET from the URL we're given to ensure it's valid
rsp = sendRequest(new GetRequest(urlOfNewPropDef), 200);
rspContent = rsp.getContentAsString();
// System.out.println(rspContent);
jsonRsp = new JSONObject(new JSONTokener(rspContent));
JSONObject dataObject = jsonRsp.getJSONObject("data");
assertNotNull("JSON data object was null", dataObject);
JSONObject customPropsObject = dataObject.getJSONObject("customProperties");
assertNotNull("JSON customProperties object was null", customPropsObject);
assertEquals("Wrong customProperties length.", 1, customPropsObject.length());
Object keyToSoleProp = customPropsObject.keys().next();
// System.out.println("New property defn: " + keyToSoleProp);
JSONObject newPropObject = customPropsObject.getJSONObject((String) keyToSoleProp);
assertEquals("Wrong property label.", propertyLabel, newPropObject.getString("label"));
return newPropId;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.
the class RmRestApiTest method checkAuditStatus.
private void checkAuditStatus(boolean expected) throws Exception {
Response rsp = sendRequest(new GetRequest(RMA_AUDITLOG_STATUS_URL), 200);
JSONObject rspObj = new JSONObject(rsp.getContentAsString());
JSONObject data = rspObj.getJSONObject("data");
boolean enabled = data.getBoolean("enabled");
assertEquals("Audit log status does not match expected status.", expected, enabled);
}
Aggregations