mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Updated REST API URLs following discussion last week with Roy
- To get a form definition we now POST to /api/formdefinitions - To persist a form we now POST to /api/item_kind/item_id/formprocessor git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -52,9 +52,8 @@ public abstract class AbstractTestFormRestApi extends BaseWebScriptTest
|
||||
protected static final String APPLICATION_JSON = "application/json";
|
||||
protected static final String TEST_FORM_DESCRIPTION = "Test form description";
|
||||
protected static final String TEST_FORM_TITLE = "Test form title";
|
||||
protected String referencingNodeDefUrl;
|
||||
protected static final String FORM_DEF_URL = "/api/formdefinitions";
|
||||
protected String referencingNodeUpdateUrl;
|
||||
protected String containingNodeDefUrl;
|
||||
protected String containingNodeUpdateUrl;
|
||||
protected String containingNodeUrl;
|
||||
protected NodeRef referencingDocNodeRef;
|
||||
@@ -154,24 +153,13 @@ public abstract class AbstractTestFormRestApi extends BaseWebScriptTest
|
||||
|
||||
// Create and store the urls to the referencingNode
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("/api/form/definition/node/workspace/").append(referencingDocNodeRef.getStoreRef().getIdentifier())
|
||||
.append("/").append(referencingDocNodeRef.getId());
|
||||
this.referencingNodeDefUrl = builder.toString();
|
||||
|
||||
builder = new StringBuilder();
|
||||
builder.append("/api/form/node/workspace/").append(referencingDocNodeRef.getStoreRef().getIdentifier())
|
||||
.append("/").append(referencingDocNodeRef.getId());
|
||||
builder.append("/api/node/workspace/").append(referencingDocNodeRef.getStoreRef().getIdentifier())
|
||||
.append("/").append(referencingDocNodeRef.getId()).append("/formprocessor");
|
||||
this.referencingNodeUpdateUrl = builder.toString();
|
||||
|
||||
// Create and store the urls to the containing node
|
||||
builder = new StringBuilder();
|
||||
builder.append("/api/form/definition/node/workspace/").append(containerNodeRef.getStoreRef().getIdentifier())
|
||||
.append("/").append(containerNodeRef.getId());
|
||||
this.containingNodeDefUrl = builder.toString();
|
||||
|
||||
builder = new StringBuilder();
|
||||
builder.append("/api/form/node/workspace/").append(containerNodeRef.getStoreRef().getIdentifier())
|
||||
.append("/").append(containerNodeRef.getId());
|
||||
builder.append("/api/node/workspace/").append(containerNodeRef.getStoreRef().getIdentifier())
|
||||
.append("/").append(containerNodeRef.getId()).append("/formprocessor");
|
||||
this.containingNodeUpdateUrl = builder.toString();
|
||||
|
||||
// Store the original properties of this node
|
||||
|
@@ -29,6 +29,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
|
||||
import org.alfresco.web.scripts.TestWebScriptServer.Response;
|
||||
import org.alfresco.web.scripts.json.JSONUtils;
|
||||
@@ -38,30 +39,49 @@ import org.json.JSONTokener;
|
||||
|
||||
public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
{
|
||||
public void testResponseContentType() throws Exception
|
||||
protected JSONObject createItemJSON(NodeRef nodeRef) throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
|
||||
jsonPostData.put("itemKind", "node");
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(nodeRef.getStoreRef().getProtocol()).append("/").append(
|
||||
nodeRef.getStoreRef().getIdentifier()).append("/").append(nodeRef.getId());
|
||||
jsonPostData.put("itemId", builder.toString());
|
||||
|
||||
return jsonPostData;
|
||||
}
|
||||
|
||||
public void testResponseContentType() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||
jsonPostString, APPLICATION_JSON), 200);
|
||||
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
|
||||
}
|
||||
|
||||
public void testGetFormForNonExistentNode() throws Exception
|
||||
{
|
||||
// Replace all digits with an 'x' char - this should make for a non-existent node.
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
// 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(referencingNodeDefUrl.replaceAll("\\d", "x"),
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||
jsonPostString, APPLICATION_JSON), 404);
|
||||
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
|
||||
}
|
||||
|
||||
public void testJsonContentParsesCorrectly() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||
jsonPostString, APPLICATION_JSON), 200);
|
||||
String jsonResponseString = rsp.getContentAsString();
|
||||
|
||||
@@ -71,9 +91,9 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
|
||||
public void testJsonUpperStructure() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||
jsonPostString, APPLICATION_JSON), 200);
|
||||
String jsonResponseString = rsp.getContentAsString();
|
||||
|
||||
@@ -101,9 +121,9 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testJsonFormData() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||
jsonPostString, APPLICATION_JSON), 200);
|
||||
String jsonResponseString = rsp.getContentAsString();
|
||||
// At this point the formData names have underscores
|
||||
@@ -135,9 +155,9 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testJsonDefinitionFields() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||
jsonPostString, APPLICATION_JSON), 200);
|
||||
String jsonResponseString = rsp.getContentAsString();
|
||||
|
||||
@@ -172,7 +192,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
|
||||
public void testJsonSelectedFields() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
JSONArray jsonFields = new JSONArray();
|
||||
jsonFields.put("cm:name");
|
||||
jsonFields.put("cm:title");
|
||||
@@ -181,7 +201,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
|
||||
// Submit the JSON request.
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl, jsonPostString,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString,
|
||||
APPLICATION_JSON), 200);
|
||||
|
||||
String jsonResponseString = rsp.getContentAsString();
|
||||
@@ -202,7 +222,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
|
||||
public void testJsonForcedFields() throws Exception
|
||||
{
|
||||
JSONObject jsonPostData = new JSONObject();
|
||||
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||
|
||||
JSONArray jsonFields = new JSONArray();
|
||||
jsonFields.put("cm:name");
|
||||
@@ -218,7 +238,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||
|
||||
// Submit the JSON request.
|
||||
String jsonPostString = jsonPostData.toString();
|
||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl, jsonPostString,
|
||||
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString,
|
||||
APPLICATION_JSON), 200);
|
||||
|
||||
String jsonResponseString = rsp.getContentAsString();
|
||||
|
Reference in New Issue
Block a user