Search in sources :

Example 61 with Response

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

the class ReplicationRestApiTest method testReplicationDefinitionsPost.

public void testReplicationDefinitionsPost() throws Exception {
    Response response;
    // Not allowed if you're not an admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
    response = sendRequest(new PostRequest(URL_DEFINITIONS, "", JSON), Status.STATUS_UNAUTHORIZED);
    assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
    AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
    response = sendRequest(new PostRequest(URL_DEFINITIONS, "", JSON), Status.STATUS_UNAUTHORIZED);
    assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
    // Ensure there aren't any to start with
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    assertEquals(0, replicationService.loadReplicationDefinitions().size());
    // If you don't give it name + description, it won't like you
    JSONObject json = new JSONObject();
    response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_BAD_REQUEST);
    assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
    json.put("name", "New Definition");
    response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_BAD_REQUEST);
    assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
    // If it has both, it'll work
    json.put("description", "Testing");
    response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    // Check we got the right information back
    String jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("New Definition", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // Check that the right stuff ended up in the repository
    ReplicationDefinition rd = replicationService.loadReplicationDefinition("New Definition");
    assertEquals("New Definition", rd.getReplicationName());
    assertEquals("Testing", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals(null, rd.getTargetName());
    assertEquals(0, rd.getPayload().size());
    assertEquals(true, rd.isEnabled());
    // Post with the full set of options
    json = new JSONObject();
    json.put("name", "Test");
    json.put("description", "Test Description");
    json.put("targetName", "Target");
    json.put("enabled", false);
    JSONArray payloadRefs = new JSONArray();
    payloadRefs.put(repositoryHelper.getCompanyHome().toString());
    payloadRefs.put(dataDictionary.toString());
    json.put("payload", payloadRefs);
    response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    // Check the response for this
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test", json.get("name"));
    assertEquals("Test Description", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals("Target", json.get("targetName"));
    assertEquals(2, json.getJSONArray("payload").length());
    JSONObject payload = json.getJSONArray("payload").getJSONObject(0);
    assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Company Home", payload.get("name"));
    assertEquals("/Company Home", payload.get("path"));
    payload = json.getJSONArray("payload").getJSONObject(1);
    assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Data Dictionary", payload.get("name"));
    assertEquals("/Company Home/Data Dictionary", payload.get("path"));
    // Check the database for this
    rd = replicationService.loadReplicationDefinition("Test");
    assertEquals("Test", rd.getReplicationName());
    assertEquals("Test Description", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals("Target", rd.getTargetName());
    assertEquals(false, rd.isEnabled());
    assertEquals(2, rd.getPayload().size());
    assertEquals(repositoryHelper.getCompanyHome(), rd.getPayload().get(0));
    assertEquals(dataDictionary, rd.getPayload().get(1));
    // Ensure that the original one wasn't changed by anything
    rd = replicationService.loadReplicationDefinition("New Definition");
    assertEquals("New Definition", rd.getReplicationName());
    assertEquals("Testing", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals(null, rd.getTargetName());
    assertEquals(0, rd.getPayload().size());
    assertEquals(true, rd.isEnabled());
    // Ensure we can't create with a duplicate name
    json = new JSONObject();
    json.put("name", "Test");
    json.put("description", "New Duplicate");
    json.put("targetName", "New Duplicate Target");
    response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_BAD_REQUEST);
    assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
    // Ensure that even though we got BAD REQUEST back, nothing changed
    rd = replicationService.loadReplicationDefinition("New Definition");
    assertEquals("New Definition", rd.getReplicationName());
    assertEquals("Testing", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals(null, rd.getTargetName());
    assertEquals(0, rd.getPayload().size());
    assertEquals(true, rd.isEnabled());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) JSONArray(org.json.JSONArray)

Example 62 with Response

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

the class ReplicationRestApiTest method testReplicationDefinitionPut.

public void testReplicationDefinitionPut() throws Exception {
    Response response;
    // Not allowed if you're not an admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
    response = sendRequest(new PutRequest(URL_DEFINITION + "MadeUp", "", JSON), Status.STATUS_UNAUTHORIZED);
    assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
    AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
    response = sendRequest(new PutRequest(URL_DEFINITION + "MadeUp", "", JSON), Status.STATUS_UNAUTHORIZED);
    assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
    // Ensure there aren't any to start with
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    assertEquals(0, replicationService.loadReplicationDefinitions().size());
    // You need to specify a real definition
    response = sendRequest(new PutRequest(URL_DEFINITION + "MadeUp", "", JSON), Status.STATUS_NOT_FOUND);
    assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
    // Create one, and change it
    ReplicationDefinition rd = replicationService.createReplicationDefinition("Test", "Testing");
    replicationService.saveReplicationDefinition(rd);
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", "{}", JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    // Check we got the right information back on it
    String jsonStr = response.getContentAsString();
    JSONObject json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test", json.get("name"));
    assertEquals("Testing", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // Ensure we didn't get any unexpected data back
    JSONArray keys = json.names();
    for (int i = 0; i < keys.length(); i++) {
        String key = keys.getString(0);
        if (key.equals("name") || key.equals("description") || key.equals("status") || key.equals("startedAt") || key.equals("endedAt") || key.equals("failureMessage") || key.equals("executionDetails") || key.equals("payload") || key.equals("transferLocalReport") || key.equals("transferRemoteReport") || key.equals("enabled") || key.equals("targetName") || key.equals("schedule")) {
        // All good
        } else {
            fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
        }
    }
    // Change some details, and see them updated in both
    // the JSON and on the object in the repo
    json = new JSONObject();
    json.put("description", "Updated Description");
    json.put("enabled", false);
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test", json.get("name"));
    assertEquals("Updated Description", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals(JSONObject.NULL, json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    rd = replicationService.loadReplicationDefinition("Test");
    assertEquals("Test", rd.getReplicationName());
    assertEquals("Updated Description", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals(null, rd.getTargetName());
    assertEquals(0, rd.getPayload().size());
    assertEquals(false, rd.isEnabled());
    // Create a 2nd definition, and check that the correct
    // one gets updated
    rd = replicationService.createReplicationDefinition("Test2", "Testing2");
    rd.setTargetName("Target");
    replicationService.saveReplicationDefinition(rd);
    json = new JSONObject();
    json.put("description", "Updated Description 2");
    json.put("enabled", false);
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test2", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    // Check the response we got
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test2", json.get("name"));
    assertEquals("Updated Description 2", json.get("description"));
    assertEquals("New", json.get("status"));
    assertEquals(JSONObject.NULL, json.get("startedAt"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals(JSONObject.NULL, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(false, json.get("enabled"));
    assertEquals("Target", json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // Check the 1st definition
    rd = replicationService.loadReplicationDefinition("Test");
    assertEquals("Test", rd.getReplicationName());
    assertEquals("Updated Description", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals(null, rd.getTargetName());
    assertEquals(0, rd.getPayload().size());
    assertEquals(false, rd.isEnabled());
    // Check the 2nd definition
    rd = replicationService.loadReplicationDefinition("Test2");
    assertEquals("Test2", rd.getReplicationName());
    assertEquals("Updated Description 2", rd.getDescription());
    assertEquals(ActionStatus.New, rd.getExecutionStatus());
    assertEquals(null, rd.getExecutionStartDate());
    assertEquals(null, rd.getExecutionEndDate());
    assertEquals(null, rd.getExecutionFailureMessage());
    assertEquals(null, rd.getLocalTransferReport());
    assertEquals(null, rd.getRemoteTransferReport());
    assertEquals("Target", rd.getTargetName());
    assertEquals(0, rd.getPayload().size());
    assertEquals(false, rd.isEnabled());
    // Mark it as running, then change some details and
    // see it change as expected
    rd = replicationService.loadReplicationDefinition("Test");
    actionTrackingService.recordActionExecuting(rd);
    replicationService.saveReplicationDefinition(rd);
    String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
    String actionId = rd.getId();
    int instanceId = ((ActionImpl) rd).getExecutionInstance();
    json = new JSONObject();
    json.put("enabled", true);
    json.put("targetName", "Another Target");
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test", json.get("name"));
    assertEquals("Updated Description", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals("Another Target", json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // Change the payload, and see the right information in
    // the response JSON for it
    JSONArray payloadRefs = new JSONArray();
    payloadRefs.put(repositoryHelper.getCompanyHome().toString());
    payloadRefs.put(dataDictionary.toString());
    json = new JSONObject();
    json.put("payload", payloadRefs);
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test", json.get("name"));
    assertEquals("Updated Description", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals("Another Target", json.get("targetName"));
    assertEquals(2, json.getJSONArray("payload").length());
    JSONObject payload = json.getJSONArray("payload").getJSONObject(0);
    assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Company Home", payload.get("name"));
    assertEquals("/Company Home", payload.get("path"));
    payload = json.getJSONArray("payload").getJSONObject(1);
    assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
    assertEquals(true, payload.get("isFolder"));
    assertEquals("Data Dictionary", payload.get("name"));
    assertEquals("/Company Home/Data Dictionary", payload.get("path"));
    // Remove the payload again
    json = new JSONObject();
    payloadRefs = new JSONArray();
    json.put("payload", payloadRefs);
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Test", json.get("name"));
    assertEquals("Updated Description", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals("Another Target", json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // Rename to a taken name, won't be allowed
    json = new JSONObject();
    json.put("name", "Test2");
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_BAD_REQUEST);
    assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
    // Rename to a spare name, will be updated
    json = new JSONObject();
    json.put("name", "Renamed");
    response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Renamed", json.get("name"));
    assertEquals("Updated Description", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals("Another Target", json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
    // Check the repo too
    assertEquals(null, replicationService.loadReplicationDefinition("Test"));
    assertNotNull(replicationService.loadReplicationDefinition("Renamed"));
    // Rename can both rename + change details
    json = new JSONObject();
    json.put("name", "Renamed Again");
    json.put("description", "Was Renamed");
    json.put("targetName", "New Target");
    response = sendRequest(new PutRequest(URL_DEFINITION + "Renamed", json.toString(), JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
    jsonStr = response.getContentAsString();
    json = new JSONObject(jsonStr).getJSONObject("data");
    assertNotNull(json);
    assertEquals("Renamed Again", json.get("name"));
    assertEquals("Was Renamed", json.get("description"));
    assertEquals("Running", json.get("status"));
    assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
    assertEquals(JSONObject.NULL, json.get("endedAt"));
    assertEquals(JSONObject.NULL, json.get("failureMessage"));
    assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
    assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
    assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
    assertEquals(true, json.get("enabled"));
    assertEquals("New Target", json.get("targetName"));
    assertEquals(0, json.getJSONArray("payload").length());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) ReplicationDefinition(org.alfresco.service.cmr.replication.ReplicationDefinition) JSONArray(org.json.JSONArray) ActionImpl(org.alfresco.repo.action.ActionImpl) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 63 with Response

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

the class RuleServiceTest method testGetRuleset.

public void testGetRuleset() throws Exception {
    JSONObject parentRule = createRule(testWorkNodeRef);
    String[] parentRuleIds = new String[] { parentRule.getJSONObject("data").getString("id") };
    JSONObject jsonRule = createRule(testNodeRef);
    String[] ruleIds = new String[] { jsonRule.getJSONObject("data").getString("id") };
    Action linkRulesAction = actionService.createAction(LinkRules.NAME);
    linkRulesAction.setParameterValue(LinkRules.PARAM_LINK_FROM_NODE, testNodeRef);
    actionService.executeAction(linkRulesAction, testNodeRef2);
    Response linkedFromResponse = sendRequest(new GetRequest(formatRulesetUrl(testNodeRef)), 200);
    JSONObject linkedFromResult = new JSONObject(linkedFromResponse.getContentAsString());
    checkRuleset(linkedFromResult, 1, ruleIds, 1, parentRuleIds, true, false);
    Response linkedToResponse = sendRequest(new GetRequest(formatRulesetUrl(testNodeRef2)), 200);
    JSONObject linkedToResult = new JSONObject(linkedToResponse.getContentAsString());
    checkRuleset(linkedToResult, 1, ruleIds, 1, parentRuleIds, false, true);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) Action(org.alfresco.service.cmr.action.Action) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 64 with Response

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

the class RuleServiceTest method testGetActionDefinitions.

public void testGetActionDefinitions() throws Exception {
    Response response = sendRequest(new GetRequest(URL_ACTIONDEFINITIONS), 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 actionDefinition = data.getJSONObject(i);
        assertTrue(actionDefinition.has("name"));
        assertTrue(actionDefinition.has("displayLabel"));
        assertTrue(actionDefinition.has("description"));
        assertTrue(actionDefinition.has("adHocPropertiesAllowed"));
        assertTrue(actionDefinition.has("parameterDefinitions"));
        assertTrue(actionDefinition.has("applicableTypes"));
    }
}
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 65 with Response

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

the class RuleServiceTest method testGetActionConditionDefinitions.

public void testGetActionConditionDefinitions() throws Exception {
    Response response = sendRequest(new GetRequest(URL_ACTIONCONDITIONDEFINITIONS), 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 actionConditionDefinition = data.getJSONObject(i);
        assertTrue(actionConditionDefinition.has("name"));
        assertTrue(actionConditionDefinition.has("displayLabel"));
        assertTrue(actionConditionDefinition.has("description"));
        assertTrue(actionConditionDefinition.has("adHocPropertiesAllowed"));
        assertTrue(actionConditionDefinition.has("parameterDefinitions"));
    }
}
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)

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