Search in sources :

Example 36 with Response

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"));
}
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)

Example 37 with Response

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

Example 38 with Response

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"));
}
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)

Example 39 with Response

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

Example 40 with Response

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

Aggregations

Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)281 JSONObject (org.json.JSONObject)228 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)171 JSONArray (org.json.JSONArray)116 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)84 JSONTokener (org.json.JSONTokener)39 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)37 NodeRef (org.alfresco.service.cmr.repository.NodeRef)34 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)32 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)16 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)16 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 Date (java.util.Date)13 JSONStringer (org.json.JSONStringer)13 UserTransaction (javax.transaction.UserTransaction)12 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)12 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)11 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)11