use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testGetFormForNonExistentNode.
public void testGetFormForNonExistentNode() throws Exception {
// Create a NodeRef with all digits changed to an 'x' char -
// this should make for a non-existent node.
String missingId = this.referencingDocNodeRef.getId().replaceAll("\\d", "x");
NodeRef missingNodeRef = new NodeRef(this.referencingDocNodeRef.getStoreRef(), missingId);
JSONObject jsonPostData = createItemJSON(missingNodeRef);
String jsonPostString = jsonPostData.toString();
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 404);
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testJsonDefinitionFields.
@SuppressWarnings("unchecked")
public void testJsonDefinitionFields() 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();
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");
for (int i = 0; i < fieldsArray.length(); i++) {
Object nextObj = fieldsArray.get(i);
JSONObject nextJsonObject = (JSONObject) nextObj;
List<String> fieldKeys = new ArrayList<String>();
for (Iterator iter2 = nextJsonObject.keys(); iter2.hasNext(); ) {
fieldKeys.add((String) iter2.next());
}
for (String s : fieldKeys) {
if (s.equals("mandatory") || s.equals("protectedField")) {
assertEquals("JSON booleans should be actual booleans.", java.lang.Boolean.class, nextJsonObject.get(s).getClass());
}
}
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testJsonUpperStructure.
public void testJsonUpperStructure() 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();
JSONObject jsonParsedObject = new JSONObject(new JSONTokener(jsonResponseString));
assertNotNull(jsonParsedObject);
Object dataObj = jsonParsedObject.get("data");
assertEquals(JSONObject.class, dataObj.getClass());
JSONObject rootDataObject = (JSONObject) dataObj;
assertEquals(5, rootDataObject.length());
String item = (String) rootDataObject.get("item");
String submissionUrl = (String) rootDataObject.get("submissionUrl");
String type = (String) rootDataObject.get("type");
JSONObject definitionObject = (JSONObject) rootDataObject.get("definition");
JSONObject formDataObject = (JSONObject) rootDataObject.get("formData");
assertNotNull(item);
assertNotNull(submissionUrl);
assertNotNull(type);
assertNotNull(definitionObject);
assertNotNull(formDataObject);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiGet_Test method testResponseContentType.
public void testResponseContentType() throws Exception {
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
String jsonPostString = jsonPostData.toString();
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 200);
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiJsonPost_Test method testRemoveAssocThatDoesNotExist.
/**
* This test method attempts to remove an association that does not exist. This
* attempt will not succeed, but the test case is to confirm that there is no
* exception thrown back across the REST API.
*/
public void testRemoveAssocThatDoesNotExist() throws Exception {
checkOriginalAssocsBeforeChanges();
// Remove a non-existent association
JSONObject jsonPostData = new JSONObject();
String assocsToRemove = associatedDoc_E.toString();
jsonPostData.put(ASSOC_CM_REFERENCES_REMOVED, assocsToRemove);
String jsonPostString = jsonPostData.toString();
sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
}
Aggregations