Search in sources :

Example 71 with GetRequest

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

the class CalendarRestApiTest method getEntries.

private JSONObject getEntries(String username, String from) throws Exception {
    String url = URL_EVENTS_LIST + "?site=" + SITE_SHORT_NAME_CALENDAR;
    if (username != null) {
        url = URL_USER_SITE_EVENTS_LIST;
    }
    if (from != null) {
        if (url.indexOf('?') > 0) {
            url += "&";
        } else {
            url += "?";
        }
        url += "from=" + from;
    }
    Response response = sendRequest(new GetRequest(url), 200);
    JSONObject result = validateAndParseJSON(response.getContentAsString());
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 72 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.

the class RMCaveatConfigScriptTest method testGetRMConstraintValues.

public void testGetRMConstraintValues() throws Exception {
    createUser("fbloggs");
    createUser("jrogers");
    createUser("jdoe");
    /**
     * Delete the list to remove any junk then recreate it.
     */
    {
        if (caveatConfigService.getRMConstraint(RM_LIST) != null) {
            caveatConfigService.deleteRMConstraint(RM_LIST);
        }
        caveatConfigService.addRMConstraint(RM_LIST, "my title", new String[0]);
        List<String> values = new ArrayList<String>();
        values.add("NOFORN");
        values.add("FGI");
        caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "fbloggs", values);
        caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jrogers", values);
        caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jdoe", values);
    }
    /**
     * Positive test Get the constraint
     */
    {
        String url = URL_RM_CONSTRAINTS + "/" + RM_LIST_URI_ELEM + "/values";
        Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
        JSONObject top = new JSONObject(response.getContentAsString());
        JSONObject data = top.getJSONObject("data");
        System.out.println(response.getContentAsString());
        String constraintName = data.getString("constraintName");
        assertNotNull("constraintName is null", constraintName);
        String constraintTitle = data.getString("constraintTitle");
        assertNotNull("constraintTitle is null", constraintTitle);
        JSONArray values = data.getJSONArray("values");
        assertTrue("details array does not contain 2 elements", values.length() == 2);
        boolean fgiFound = false;
        boolean nofornFound = false;
        for (int i = 0; i < values.length(); i++) {
            JSONObject value = values.getJSONObject(i);
            if (value.getString("valueName").equalsIgnoreCase("FGI")) {
                fgiFound = true;
            }
            if (value.getString("valueName").equalsIgnoreCase("NOFORN")) {
                nofornFound = true;
            }
        }
        assertTrue("fgi not found", fgiFound);
        assertTrue("noforn not found", nofornFound);
    }
    deleteUser("fbloggs");
    deleteUser("jrogers");
    deleteUser("jdoe");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) List(java.util.List) ArrayList(java.util.ArrayList)

Example 73 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.

the class RmRestApiTest method testGetDodCustomTypes.

public void testGetDodCustomTypes() throws IOException, JSONException {
    final int expectedStatus = 200;
    Response rsp = sendRequest(new GetRequest("/api/rma/admin/dodcustomtypes"), expectedStatus);
    String rspContent = rsp.getContentAsString();
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
    // System.out.println(rspContent);
    JSONObject dataObj = (JSONObject) jsonRsp.get("data");
    assertNotNull("JSON 'data' object was null", dataObj);
    JSONArray customTypesObj = (JSONArray) dataObj.get("dodCustomTypes");
    assertNotNull("JSON 'dodCustomTypes' object was null", customTypesObj);
    assertEquals("Wrong DOD custom types count.", 4, customTypesObj.length());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 74 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.

the class RmRestApiTest method postCustomPropertyDefinition.

/**
 * Creates a new property definition using a POST call.
 * GETs the resultant property definition.
 *
 * @param propertyLabel the label to use
 * @param propId the propId to use - null to have one generated.
 * @return the propId of the new property definition
 */
private String postCustomPropertyDefinition(String propertyLabel, String propId) throws JSONException, IOException, UnsupportedEncodingException {
    String jsonString;
    if (propId == null) {
        jsonString = new JSONStringer().object().key("label").value(propertyLabel).key("description").value("Dynamically defined test property").key("mandatory").value(false).key("dataType").value("d:text").key("element").value("record").key("constraintRef").value("rmc:smList").endObject().toString();
    } else {
        jsonString = new JSONStringer().object().key("label").value(propertyLabel).key("description").value("Dynamically defined test property").key("mandatory").value(false).key("dataType").value("d:text").key("element").value("record").key("constraintRef").value("rmc:smList").key("propId").value(propId).endObject().toString();
    }
    // Submit the JSON request.
    final int expectedStatus = 200;
    Response rsp = sendRequest(new PostRequest("/api/rma/admin/custompropertydefinitions?element=record", jsonString, APPLICATION_JSON), expectedStatus);
    String rspContent = rsp.getContentAsString();
    // System.out.println(rspContent);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rspContent));
    String urlOfNewPropDef = jsonRsp.getString("url");
    String newPropId = jsonRsp.getString("propId");
    assertNotNull("urlOfNewPropDef was null.", urlOfNewPropDef);
    // GET from the URL we're given to ensure it's valid
    rsp = sendRequest(new GetRequest(urlOfNewPropDef), 200);
    rspContent = rsp.getContentAsString();
    // System.out.println(rspContent);
    jsonRsp = new JSONObject(new JSONTokener(rspContent));
    JSONObject dataObject = jsonRsp.getJSONObject("data");
    assertNotNull("JSON data object was null", dataObject);
    JSONObject customPropsObject = dataObject.getJSONObject("customProperties");
    assertNotNull("JSON customProperties object was null", customPropsObject);
    assertEquals("Wrong customProperties length.", 1, customPropsObject.length());
    Object keyToSoleProp = customPropsObject.keys().next();
    // System.out.println("New property defn: " + keyToSoleProp);
    JSONObject newPropObject = customPropsObject.getJSONObject((String) keyToSoleProp);
    assertEquals("Wrong property label.", propertyLabel, newPropObject.getString("label"));
    return newPropId;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONObject(org.json.JSONObject) JSONStringer(org.json.JSONStringer)

Example 75 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project records-management by Alfresco.

the class RmRestApiTest method checkAuditStatus.

private void checkAuditStatus(boolean expected) throws Exception {
    Response rsp = sendRequest(new GetRequest(RMA_AUDITLOG_STATUS_URL), 200);
    JSONObject rspObj = new JSONObject(rsp.getContentAsString());
    JSONObject data = rspObj.getJSONObject("data");
    boolean enabled = data.getBoolean("enabled");
    assertEquals("Audit log status does not match expected status.", expected, enabled);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)182 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)171 JSONObject (org.json.JSONObject)141 JSONArray (org.json.JSONArray)89 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)25 HashMap (java.util.HashMap)23 JSONTokener (org.json.JSONTokener)23 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)21 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Serializable (java.io.Serializable)13 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)13 QName (org.alfresco.service.namespace.QName)13 ArrayList (java.util.ArrayList)12 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)12 Date (java.util.Date)11 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)11 JSONStringer (org.json.JSONStringer)7 Calendar (java.util.Calendar)6 UserTransaction (javax.transaction.UserTransaction)6