Search in sources :

Example 16 with Response

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

the class FeedControlTest method testRetrieveFeedControls.

public void testRetrieveFeedControls() throws Exception {
    // Get (retrieve) feed controls
    int expectedStatus = 200;
    Response response = sendRequest(new GetRequest(URL_CONTROLS), expectedStatus);
    JSONArray result = new JSONArray(response.getContentAsString());
    if (logger.isDebugEnabled()) {
        logger.debug(result);
    }
    assertNotNull(result);
    assertEquals(3, result.length());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 17 with Response

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

the class AdminWebScriptTest method testGetRestrictions.

public void testGetRestrictions() throws Exception {
    RepoUsage restrictions = repoAdminService.getRestrictions();
    String url = "/api/admin/restrictions";
    TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
    Response response = sendRequest(req, Status.STATUS_OK, guest);
    JSONObject json = new JSONObject(response.getContentAsString());
    Long maxUsers = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
    assertEquals("Mismatched max users", restrictions.getUsers(), maxUsers);
    Long maxDocuments = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
    assertEquals("Mismatched max documents", restrictions.getDocuments(), maxDocuments);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer) JSONObject(org.json.JSONObject) RepoUsage(org.alfresco.service.cmr.admin.RepoUsage)

Example 18 with Response

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

the class NodeArchiveServiceRestApiTest method testPurgeDeletedItems.

/**
 * This test method purges some deleted nodes from the archive store.
 */
public void testPurgeDeletedItems() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    JSONObject archivedNodesJson = getArchivedNodes();
    JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
    JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
    int archivedNodesLength = archivedNodesArray.length();
    assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
    // Take a specific archived node and purge it.
    JSONObject requiredNodeInArchive = null;
    for (int i = 0; i < archivedNodesLength; i++) {
        JSONObject archivedNode = archivedNodesArray.getJSONObject(i);
        // We ensure in #setUp() that this NodeRef will be in the archive store.
        if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(adminDeletedTestNode.toString())) {
            requiredNodeInArchive = archivedNode;
            break;
        } else if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(user1_DeletedTestNode.toString())) {
            requiredNodeInArchive = archivedNode;
            break;
        } else if (archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF).equals(user2_DeletedTestNode.toString())) {
            requiredNodeInArchive = archivedNode;
            break;
        }
    }
    assertNotNull("Expected node not found in archive", requiredNodeInArchive);
    // So we have identified a specific Node in the archive that we want to delete permanently (purge).
    String nodeRefString = requiredNodeInArchive.getString(AbstractArchivedNodeWebScript.NODEREF);
    assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
    NodeRef nodeRef = new NodeRef(nodeRefString);
    // This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
    // This is its current StoreRef i.e. archive://SpacesStore
    final StoreRef currentStoreRef = nodeRef.getStoreRef();
    String deleteUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
    // Send the DELETE REST call.
    Response rsp = sendRequest(new DeleteRequest(deleteUrl), 200);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    JSONObject dataObj = jsonRsp.getJSONObject("data");
    JSONArray purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
    assertEquals("Only expected one NodeRef to have been purged.", 1, purgedNodesArray.length());
    // Now we'll purge all the other nodes in the archive that came from the same StoreRef.
    String deleteAllUrl = getArchiveUrl(this.nodesOriginalStoreRef);
    rsp = sendRequest(new DeleteRequest(deleteAllUrl), 200);
    jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    dataObj = jsonRsp.getJSONObject("data");
    purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
    // Now retrieve all items from the archive store. There should be none.
    assertEquals("Archive store was unexpectedly not empty", 0, getArchivedNodesCount());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 19 with Response

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

the class NodeArchiveServiceRestApiTest method testRestoreDeletedItems.

/**
 * This test method restores some deleted nodes from the archive store.
 */
public void testRestoreDeletedItems() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    JSONObject archivedNodesJson = getArchivedNodes();
    JSONObject dataJsonObj = archivedNodesJson.getJSONObject("data");
    JSONArray archivedNodesArray = dataJsonObj.getJSONArray(AbstractArchivedNodeWebScript.DELETED_NODES);
    int archivedNodesLength = archivedNodesArray.length();
    assertTrue("Insufficient archived nodes for test to run.", archivedNodesLength > 1);
    // Take a specific archived node and restore it.
    JSONObject firstArchivedNode = archivedNodesArray.getJSONObject(0);
    // So we have identified a specific Node in the archive that we want to restore.
    String nodeRefString = firstArchivedNode.getString(AbstractArchivedNodeWebScript.NODEREF);
    assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
    NodeRef nodeRef = new NodeRef(nodeRefString);
    // This is not the StoreRef where the node originally lived e.g. workspace://SpacesStore
    // This is its current StoreRef i.e. archive://SpacesStore
    final StoreRef currentStoreRef = nodeRef.getStoreRef();
    String restoreUrl = getArchiveUrl(currentStoreRef) + "/" + nodeRef.getId();
    int archivedNodesCountBeforeRestore = getArchivedNodesCount();
    // Send the PUT REST call.
    String jsonString = new JSONStringer().object().key("restoreLocation").value("").endObject().toString();
    Response rsp = sendRequest(new PutRequest(restoreUrl, jsonString, "application/json"), 200);
    assertEquals("Expected archive to shrink by one", archivedNodesCountBeforeRestore - 1, getArchivedNodesCount());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) JSONStringer(org.json.JSONStringer)

Example 20 with Response

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

the class AuditWebScriptTest method testGetAuditSearchService.

public void testGetAuditSearchService() throws Exception {
    // Delete search audit entries (if any)
    String url = "/api/audit/clear/" + APP_SEARCHTEST_NAME;
    TestWebScriptServer.PostRequest postReq = new TestWebScriptServer.PostRequest(url, "", MimetypeMap.MIMETYPE_JSON);
    Response response = sendRequest(postReq, Status.STATUS_OK, admin);
    JSONObject json = new JSONObject(response.getContentAsString());
    assertTrue(json.getInt(AbstractAuditWebScript.JSON_KEY_CLEARED) >= 0);
    // create a file
    this.testRoot = this.repositoryHelper.getCompanyHome();
    String filename = "test_doc" + GUID.generate() + ".txt";
    NodeRef testFile = this.fileFolderService.create(this.testRoot, filename, ContentModel.TYPE_CONTENT).getNodeRef();
    // search the newly created file
    SearchParameters sp = new SearchParameters();
    sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    sp.setQuery("=cm:name:" + filename);
    sp.addStore(testFile.getStoreRef());
    searchService.query(sp);
    // construct the get audit request
    url = "/api/audit/query/" + APP_SEARCHTEST_NAME + "/searchaudit/queryX/searchParametersX?verbose=true";
    TestWebScriptServer.GetRequest getReq = new TestWebScriptServer.GetRequest(url);
    response = sendRequest(getReq, Status.STATUS_OK, admin);
    json = new JSONObject(response.getContentAsString());
    JSONArray jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
    assertEquals("Incorrect number of entries reported", 1, jsonEntries.length());
    JSONObject values = (JSONObject) ((JSONObject) jsonEntries.get(0)).get(AbstractAuditWebScript.JSON_KEY_ENTRY_VALUES);
    assertTrue("Audit entry was not found", values.toString(0).contains("query==cm:name:" + filename));
    // clear audit entries for the application
    auditService.clearAudit(APP_SEARCHTEST_NAME, null, null);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

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