use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testJsonForcedFields.
public void testJsonForcedFields() throws Exception {
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
JSONArray jsonFields = new JSONArray();
jsonFields.put("cm:name");
jsonFields.put("cm:title");
jsonFields.put("cm:publisher");
jsonFields.put("cm:wrong");
jsonPostData.put("fields", jsonFields);
JSONArray jsonForcedFields = new JSONArray();
jsonForcedFields.put("cm:publisher");
jsonForcedFields.put("cm:wrong");
jsonPostData.put("force", jsonForcedFields);
// Submit the JSON request.
String jsonPostString = jsonPostData.toString();
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 200);
String jsonResponseString = rsp.getContentAsString();
JSONObject jsonParsedObject = new JSONObject(new JSONTokener(jsonResponseString));
assertNotNull(jsonParsedObject);
JSONObject rootDataObject = (JSONObject) jsonParsedObject.get("data");
JSONObject definitionObject = (JSONObject) rootDataObject.get("definition");
JSONArray fieldsArray = (JSONArray) definitionObject.get("fields");
assertEquals("Expected 3 fields", 3, fieldsArray.length());
// get the name and title definitions
JSONObject nameField = (JSONObject) fieldsArray.get(0);
JSONObject titleField = (JSONObject) fieldsArray.get(1);
String nameFieldDataKey = nameField.getString("dataKeyName");
String titleFieldDataKey = titleField.getString("dataKeyName");
// get the data and check it
JSONObject formDataObject = (JSONObject) rootDataObject.get("formData");
assertNotNull("Expected to find cm:name data", formDataObject.get(nameFieldDataKey));
assertNotNull("Expected to find cm:title data", formDataObject.get(titleFieldDataKey));
assertEquals(TEST_FORM_TITLE, formDataObject.get("prop_cm_title"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testJsonContentParsesCorrectly.
public void testJsonContentParsesCorrectly() throws Exception {
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
String jsonPostString = jsonPostData.toString();
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 200);
String jsonResponseString = rsp.getContentAsString();
Object jsonObject = new JSONUtils().toObject(jsonResponseString);
assertNotNull("JSON object was null.", jsonObject);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testJsonSelectedFields.
public void testJsonSelectedFields() throws Exception {
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
JSONArray jsonFields = new JSONArray();
jsonFields.put("cm:name");
jsonFields.put("cm:title");
jsonFields.put("cm:publisher");
jsonPostData.put("fields", jsonFields);
// Submit the JSON request.
String jsonPostString = jsonPostData.toString();
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 200);
String jsonResponseString = rsp.getContentAsString();
JSONObject jsonParsedObject = new JSONObject(new JSONTokener(jsonResponseString));
assertNotNull(jsonParsedObject);
JSONObject rootDataObject = (JSONObject) jsonParsedObject.get("data");
JSONObject definitionObject = (JSONObject) rootDataObject.get("definition");
JSONArray fieldsArray = (JSONArray) definitionObject.get("fields");
assertEquals("Expected 2 fields", 2, fieldsArray.length());
// get the name and title definitions
JSONObject nameField = (JSONObject) fieldsArray.get(0);
JSONObject titleField = (JSONObject) fieldsArray.get(1);
String nameFieldDataKey = nameField.getString("dataKeyName");
String titleFieldDataKey = titleField.getString("dataKeyName");
// get the data and check it
JSONObject formDataObject = (JSONObject) rootDataObject.get("formData");
assertNotNull("Expected to find cm:name data", formDataObject.get(nameFieldDataKey));
assertNotNull("Expected to find cm:title data", formDataObject.get(titleFieldDataKey));
assertEquals(TEST_FORM_TITLE, formDataObject.get("prop_cm_title"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class GroupsTest method getDataArray.
private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException {
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
return data;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class GroupsTest method testCreateRootGroup.
/**
* Detailed test of create root group
* Detailed test of delete root group
*/
public void testCreateRootGroup() throws Exception {
String myGroupName = "GT_CRG";
String myDisplayName = "GT_CRGDisplay";
/**
* Negative test - try to create a group without admin authority
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myDisplayName);
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR);
}
this.authenticationComponent.setSystemUserAsCurrentUser();
try {
/**
* Create a root group
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myDisplayName);
Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
JSONObject top = new JSONObject(response.getContentAsString());
JSONObject rootGroup = top.getJSONObject("data");
assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName"));
assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName"));
}
/**
* Negative test Create a root group that already exists
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myDisplayName);
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
}
/**
* Delete the root group
*/
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK);
/**
* Attempt to delete the root group again - should fail
*/
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND);
} finally {
/**
* Delete the root group
*/
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0);
}
}
Aggregations