Search in sources :

Example 66 with Response

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

the class RuleServiceTest method testGetRuleDetails.

public void testGetRuleDetails() throws Exception {
    JSONObject jsonRule = createRule(testNodeRef);
    String ruleId = jsonRule.getJSONObject("data").getString("id");
    Response response = sendRequest(new GetRequest(formateRuleUrl(testNodeRef, ruleId)), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    checkRuleComplete(result);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 67 with Response

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

the class RuleServiceTest method createRule.

private JSONObject createRule(NodeRef ruleOwnerNodeRef, String title) throws Exception {
    JSONObject jsonRule = buildTestRule(title);
    Response response = sendRequest(new PostRequest(formatRulesUrl(ruleOwnerNodeRef, false), jsonRule.toString(), "application/json"), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 68 with Response

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

the class RuleServiceTest method testGetRuleTypes.

public void testGetRuleTypes() throws Exception {
    Response response = sendRequest(new GetRequest(URL_RULETYPES), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertNotNull(result);
    assertTrue(result.has("data"));
    JSONArray data = result.getJSONArray("data");
    for (int i = 0; i < data.length(); i++) {
        JSONObject ruleType = data.getJSONObject(i);
        assertTrue(ruleType.has("name"));
        assertTrue(ruleType.has("displayLabel"));
        assertTrue(ruleType.has("url"));
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint)

Example 69 with Response

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

the class RuleServiceTest method testUpdateRule.

public void testUpdateRule() throws Exception {
    JSONObject jsonRule = createRule(testNodeRef);
    String ruleId = jsonRule.getJSONObject("data").getString("id");
    Response getResponse = sendRequest(new GetRequest(formateRuleUrl(testNodeRef, ruleId)), 200);
    JSONObject before = new JSONObject(getResponse.getContentAsString());
    // do some changes
    before.put("description", "this is modified description for test_rule");
    // do some changes for action object
    JSONObject beforeAction = before.getJSONObject("action");
    // no changes for actions list
    beforeAction.remove("actions");
    // clear conditions
    beforeAction.put("conditions", new JSONArray());
    Response putResponse = sendRequest(new PutRequest(formateRuleUrl(testNodeRef, ruleId), before.toString(), "application/json"), 200);
    JSONObject after = new JSONObject(putResponse.getContentAsString());
    // sent and retrieved objects should be the same (except ids and urls)
    // this means that all changes was saved
    checkUpdatedRule(before, after);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 70 with Response

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

the class RuleServiceTest method testGetActionConstraint.

public void testGetActionConstraint() throws Exception {
    List<ParameterConstraint> constraints = actionService.getParameterConstraints();
    if (constraints.size() == 0) {
        return;
    }
    String name = constraints.get(0).getName();
    Response response = sendRequest(new GetRequest(formateActionConstraintUrl(name)), 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertNotNull(result);
    assertTrue(result.has("data"));
    JSONObject data = result.getJSONObject("data");
    assertTrue(data.has("name"));
    assertTrue(data.has("values"));
    JSONArray values = data.getJSONArray("values");
    for (int i = 0; i < values.length(); i++) {
        JSONObject value = values.getJSONObject(i);
        assertTrue(value.has("value"));
        assertTrue(value.has("displayLabel"));
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) ParameterConstraint(org.alfresco.service.cmr.action.ParameterConstraint)

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