use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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.PostRequest 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.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiJsonPost_Test method testSimpleJsonPostRequest.
public void testSimpleJsonPostRequest() throws IOException, JSONException {
// Retrieve and store the original property value.
Serializable originalDescription = nodeService.getProperty(referencingDocNodeRef, ContentModel.PROP_DESCRIPTION);
assertEquals(TEST_FORM_DESCRIPTION, originalDescription);
// get the original mimetype
String originalMimetype = null;
ContentData content = (ContentData) this.nodeService.getProperty(referencingDocNodeRef, ContentModel.PROP_CONTENT);
if (content != null) {
originalMimetype = content.getMimetype();
}
// Construct some JSON to represent a new value.
JSONObject jsonPostData = new JSONObject();
final String proposedNewDescription = "Modified Description";
jsonPostData.put(PROP_CM_DESCRIPTION, proposedNewDescription);
jsonPostData.put(PROP_MIMETYPE, MimetypeMap.MIMETYPE_HTML);
// Submit the JSON request.
String jsonPostString = jsonPostData.toString();
sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
// The nodeService should give us the modified property.
Serializable modifiedDescription = nodeService.getProperty(referencingDocNodeRef, ContentModel.PROP_DESCRIPTION);
assertEquals(proposedNewDescription, modifiedDescription);
// get the modified mimetype
String modifiedMimetype = null;
content = (ContentData) this.nodeService.getProperty(referencingDocNodeRef, ContentModel.PROP_CONTENT);
if (content != null) {
modifiedMimetype = content.getMimetype();
}
assertEquals(MimetypeMap.MIMETYPE_HTML, modifiedMimetype);
// The Rest API should also give us the modified property.
/*
Response response = sendRequest(new GetRequest(referencingNodeUpdateUrl), 200);
JSONObject jsonGetResponse = new JSONObject(response.getContentAsString());
JSONObject jsonDataObj = (JSONObject)jsonGetResponse.get("data");
assertNotNull(jsonDataObj);
JSONObject formData = (JSONObject)jsonDataObj.get("formData");
assertNotNull(formData);
String retrievedValue = (String)formData.get(PROP_CM_DESCRIPTION);
assertEquals(modifiedDescription, retrievedValue);
String retrievedMimetype = (String)formData.get(PROP_MIMETYPE);
assertEquals(MimetypeMap.MIMETYPE_HTML, modifiedMimetype);*/
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiJsonPost_Test method testAddNewAssociationsToNode.
/**
* This test method attempts to add new associations between existing nodes.
*/
public void testAddNewAssociationsToNode() throws Exception {
List<NodeRef> associatedNodes;
checkOriginalAssocsBeforeChanges();
// Add three additional associations
JSONObject jsonPostData = new JSONObject();
String assocsToAdd = associatedDoc_C + "," + associatedDoc_D + "," + associatedDoc_E;
jsonPostData.put(ASSOC_CM_REFERENCES_ADDED, assocsToAdd);
String jsonPostString = jsonPostData.toString();
sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
// Check the now updated associations via the node service
List<AssociationRef> modifiedAssocs = nodeService.getTargetAssocs(referencingDocNodeRef, RegexQNamePattern.MATCH_ALL);
assertEquals(5, modifiedAssocs.size());
// Extract the target nodeRefs to make them easier to examine
associatedNodes = new ArrayList<NodeRef>(5);
for (AssociationRef assocRef : modifiedAssocs) {
associatedNodes.add(assocRef.getTargetRef());
}
assertTrue(associatedNodes.contains(associatedDoc_A));
assertTrue(associatedNodes.contains(associatedDoc_B));
assertTrue(associatedNodes.contains(associatedDoc_C));
assertTrue(associatedNodes.contains(associatedDoc_D));
assertTrue(associatedNodes.contains(associatedDoc_E));
// The Rest API should also give us the modified assocs.
/*Response response = sendRequest(new GetRequest(referencingNodeUpdateUrl), 200);
String jsonRspString = response.getContentAsString();
JSONObject jsonGetResponse = new JSONObject(jsonRspString);
JSONObject jsonData = (JSONObject)jsonGetResponse.get("data");
assertNotNull(jsonData);
JSONObject jsonFormData = (JSONObject)jsonData.get("formData");
assertNotNull(jsonFormData);
String jsonAssocs = (String)jsonFormData.get(ASSOC_CM_REFERENCES);
// We expect exactly 5 assocs on the test node
assertEquals(5, jsonAssocs.split(",").length);
for (AssociationRef assocRef : modifiedAssocs)
{
assertTrue(jsonAssocs.contains(assocRef.getTargetRef().toString()));
}*/
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.
the class FormRestApiJsonPost_Test method testAddAssocThatAlreadyExists.
/**
* This test method attempts to add the same association twice. 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 testAddAssocThatAlreadyExists() throws Exception {
checkOriginalAssocsBeforeChanges();
// Add an association
JSONObject jsonPostData = new JSONObject();
String assocsToAdd = associatedDoc_C.toString();
jsonPostData.put(ASSOC_CM_REFERENCES_ADDED, assocsToAdd);
String jsonPostString = jsonPostData.toString();
sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
// Try to add the same association again
sendRequest(new PostRequest(referencingNodeUpdateUrl, jsonPostString, APPLICATION_JSON), 200);
}
Aggregations