Search in sources :

Example 56 with PostRequest

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());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 57 with PostRequest

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());
            }
        }
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JSONObject(org.json.JSONObject)

Example 58 with PostRequest

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);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Example 59 with PostRequest

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());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 60 with PostRequest

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);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Aggregations

PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)110 JSONObject (org.json.JSONObject)90 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)84 JSONArray (org.json.JSONArray)28 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)25 JSONTokener (org.json.JSONTokener)23 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)14 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)10 JSONStringer (org.json.JSONStringer)9 File (java.io.File)8 ZipFile (java.util.zip.ZipFile)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JSONObject (org.json.simple.JSONObject)5 IOException (java.io.IOException)4 UserTransaction (javax.transaction.UserTransaction)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 JSONException (org.json.JSONException)4 Serializable (java.io.Serializable)3