Search in sources :

Example 91 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class DictionaryRestApiTest method testSubClassDetails.

public void testSubClassDetails() throws Exception {
    GetRequest req = new GetRequest(URL_SITES + "/sys/base/subclasses");
    Map<String, String> arguments = new HashMap<String, String>();
    arguments.put("r", "true");
    req.setArgs(arguments);
    Response response = sendRequest(req, 200);
    assertEquals(200, response.getStatus());
    response = sendRequest(req, 200);
    JSONArray result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    arguments.clear();
    arguments.put("r", "false");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    assertEquals(200, response.getStatus());
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    assertEquals(200, response.getStatus());
    arguments.clear();
    arguments.put("r", "false");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    assertEquals(200, response.getStatus());
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    arguments.clear();
    arguments.put("r", "true");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    assertEquals(200, response.getStatus());
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // data with only name along
    arguments.clear();
    arguments.put("r", "true");
    arguments.put("n", "cmobject");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // invalid name and namespaceprefix
    arguments.clear();
    arguments.put("r", "true");
    // name and namespaceprefix are valid one , but its not present in sys_base as a sub-class
    arguments.put("n", "dublincore");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // invalid name and a valid namespaceprefix
    arguments.clear();
    arguments.put("r", "true");
    // name and namespaceprefix are invalid one
    arguments.put("n", "dublincoresara");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) HashMap(java.util.HashMap) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 92 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class DictionaryRestApiTest method testGetClassDetails.

public void testGetClassDetails() throws Exception {
    /**
     *  There are eight scenarios with getting class details , all are optional fields
     *  Classfilter   namespaceprefix   name   Returns
     *  1   yes             yes          yes    single class
     *  2   yes             yes          no     Array of classes [returns array of classes of the particular namespaceprefix]
     *  3   yes             no           no     Array of classes [depends on classfilter, either type or aspect or all classes in the repo]
     *  4   no              no           no     Array of classes [returns all classes of both type and aspects in the entire repository]
     *  5   no              yes          yes    single class [returns a single class of a valid namespaceprefix:name combination]
     *  6   no              yes          no     Array of classes [returns an array of all aspects and types under particular namespaceprefix]
     *  7   no              no           yes    404 error [since name alone doesn't makes any meaning]
     *  8   yes             no           yes    404 error [since name alone doesn't makes any meaning]
     *  Test cases are provided for all the above scenarios
     */
    // check for a aspect under cm with name thumbnailes [case-type:1]
    GetRequest req = new GetRequest(URL_SITES);
    Map<String, String> arguments = new HashMap<String, String>();
    arguments.put("cf", "aspect");
    arguments.put("nsp", "cm");
    arguments.put("n", "thumbnailed");
    req.setArgs(arguments);
    Response response = sendRequest(req, 200);
    JSONArray result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    // check array length
    assertEquals(200, response.getStatus());
    // check for a type under cm with name cmobject [case-type:1]
    arguments.clear();
    arguments.put("cf", "type");
    arguments.put("nsp", "cm");
    arguments.put("n", "cmobject");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a type under cm with name cmobject [case-type:1]
    arguments.clear();
    arguments.put("cf", "all");
    arguments.put("nsp", "cm");
    arguments.put("n", "cmobject");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a type under cm without options=>name, namespaceprefix [case-type:2]
    arguments.clear();
    arguments.put("cf", "type");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    // the above result has all the types under cm, so now check for the presence type cm:cmobject in the array of classes of all types
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a aspect under cm without options=>name [case-type:2]
    arguments.clear();
    arguments.put("cf", "aspect");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    // the above result has all the aspects under cm, so now check for the presence aspect cm:thumnailed in the array of classes of all aspects
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    // check for all aspects under cm without options=>name [case-type:2]
    arguments.clear();
    arguments.put("cf", "all");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for all type under cm without options=>name, namespaceprefix [case-type:3]
    arguments.clear();
    arguments.put("cf", "type");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            System.out.println(result.getJSONObject(i).toString());
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for all aspect under cm without options=>name, namespaceprefix [case-type:3]
    arguments.clear();
    arguments.put("cf", "aspect");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for all aspect and type in the repository when nothing is given [case-type:4]
    arguments.clear();
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for all aspect and type in the repository when nothing is given [case-type:4]
    arguments.clear();
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a classname [namespaceprefix:name => cm:cmobject] without classfilter option [case-type:5]
    arguments.clear();
    arguments.put("nsp", "cm");
    arguments.put("n", "cmobject");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a classname [namespaceprefix:name => cm:thumbnailed] without classfilter option [case-type:5]
    arguments.clear();
    arguments.put("nsp", "cm");
    arguments.put("n", "thumbnailed");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a namespaceprefix [namespaceprefix => cm] without classfilter and name option [case-type:6]
    arguments.clear();
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) {
            validateAspectClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a namespaceprefix [namespaceprefix => cm] without classfilter and name option [case-type:6]
    arguments.clear();
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a namespaceprefix [namespaceprefix => cm] without classfilter and name option [case-type:6]
    arguments.clear();
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    result = new JSONArray(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    for (int i = 0; i < result.length(); i++) {
        if (result.getJSONObject(i).get("name").equals("cm:cmobject")) {
            validateTypeClass(result.getJSONObject(i));
        }
    }
    assertEquals(200, response.getStatus());
    // check for a name alone without classfilter and namespaceprefix option [case-type:7] => returns 404 error
    arguments.clear();
    arguments.put("n", "cmobject");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // check for a type under cm with name cmobject and no namespaceprefix [case-type:8] => returns 404 error
    arguments.clear();
    arguments.put("cf", "type");
    arguments.put("n", "cmobject");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // Test with wrong data
    // check for all aspects under cm without option=>name
    arguments.clear();
    arguments.put("cf", "aspects");
    arguments.put("nsp", "cm");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // check for all types under cm without option=>name
    arguments.clear();
    arguments.put("cf", "types");
    arguments.put("nsp", "cmd");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // check for all dictionary data  without option=>name and option=>namespaceprefix
    arguments.clear();
    arguments.put("cf", "a�&llsara");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // check for all aspect dictionary data  without option=>name and option=>namespaceprefix
    arguments.clear();
    arguments.put("cf", "aspectb");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // check for all types dictionary data  without option=>name and option=>namespaceprefix
    arguments.clear();
    arguments.put("cf", "typesa");
    req.setArgs(arguments);
    response = sendRequest(req, 404);
    assertEquals(404, response.getStatus());
    // check for all types dictionary data  without option=>name and option=>namespaceprefix and option=>classfilter
    arguments.clear();
    req.setArgs(arguments);
    response = sendRequest(req, 200);
    assertEquals(200, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) HashMap(java.util.HashMap) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 93 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class DictionaryRestApiTest method testGetAssociationDef.

public void testGetAssociationDef() throws Exception {
    GetRequest req = new GetRequest(URL_SITES + "/cm/person/association/cm/avatar");
    Response response = sendRequest(req, 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertEquals(200, response.getStatus());
    validateAssociationDef(result);
    req = new GetRequest(URL_SITES + "/wca/form/association/wca/formworkflowdefaults");
    response = sendRequest(req, 200);
    result = new JSONObject(response.getContentAsString());
    validateChildAssociation(result);
    assertEquals(200, response.getStatus());
    req = new GetRequest(URL_SITES + "/wca/form/association/wca/renderingenginetemplates");
    response = sendRequest(req, 200);
    result = new JSONObject(response.getContentAsString());
    validateAssociation(result);
    assertEquals(200, response.getStatus());
    // wrong data
    response = sendRequest(new GetRequest(URL_SITES + "/cm/personalbe/association/cms/avatarsara"), 404);
    assertEquals(404, response.getStatus());
    // ask for an invalid association under wca:form , which returns 404
    response = sendRequest(new GetRequest(URL_SITES + "/wca/form/association/cmsavatarsara"), 404);
    assertEquals(404, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 94 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class DictionaryRestApiTest method testGetClasses.

public void testGetClasses() throws Exception {
    GetRequest req = new GetRequest(URL_SITES);
    Response response = sendRequest(req, 200);
    JSONArray result = new JSONArray(response.getContentAsString());
    assertTrue(result.length() > 0);
    assertEquals(200, response.getStatus());
    validatePropertiesConformity(result);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 95 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class DictionaryRestApiTest method testGetClassDetail.

public void testGetClassDetail() throws Exception {
    GetRequest req = new GetRequest(URL_SITES + "/cm/thumbnailed");
    Response response = sendRequest(req, 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    assertEquals(200, response.getStatus());
    validateAspectClass(result);
    req = new GetRequest(URL_SITES + "/cm/cmobject");
    response = sendRequest(req, 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    assertEquals(200, response.getStatus());
    validateTypeClass(result);
    response = sendRequest(new GetRequest("/api/defclasses/cm/hi"), 404);
    assertEquals(404, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

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