Search in sources :

Example 81 with Response

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

the class SOLRWebScriptTest method DISABLED_testGetContent.

public void DISABLED_testGetContent() throws Exception {
    long nodeId = -1l;
    String propertyName = ContentModel.PROP_CONTENT.toString();
    buildTransactions3();
    String url = "/api/solr/content?nodeId=" + nodeId + "&propertyName=" + propertyName;
    TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
    Response response = sendRequest(req, Status.STATUS_OK, admin);
    if (logger.isDebugEnabled()) {
        logger.debug("content1 = " + response.getContentAsString());
    }
    assertEquals("Content length is incorrect", "test content".length(), response.getContentLength());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer)

Example 82 with Response

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

the class SOLRWebScriptTest method getNodesMetaData.

private JSONArray getNodesMetaData(List<Long> nodeIds, int maxResults, int numMetaDataNodes) throws Exception {
    StringBuilder url = new StringBuilder("/api/solr/metadata");
    JSONObject json = new JSONObject();
    if (nodeIds != null && nodeIds.size() > 0) {
        JSONArray array = new JSONArray();
        for (Long nodeId : nodeIds) {
            array.put(nodeId);
        }
        json.put("nodeIds", array);
    }
    json.put("maxResults", maxResults);
    TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url.toString(), json.toString(), "application/json");
    long startTime = System.currentTimeMillis();
    Response response = sendRequest(req, Status.STATUS_OK, admin);
    long endTime = System.currentTimeMillis();
    String content = response.getContentAsString();
    if (logger.isDebugEnabled()) {
        logger.debug("nodesMetaData = " + content);
    }
    JSONObject jsonResponse = null;
    try {
        jsonResponse = new JSONObject(content);
    } catch (JSONException e) {
        fail(e.getMessage());
    }
    JSONArray nodes = jsonResponse.getJSONArray("nodes");
    logger.debug("Got metadata for " + nodes.length() + " nodes in " + (endTime - startTime) + " ms");
    assertEquals("Number of returned nodes is incorrect", numMetaDataNodes, nodes.length());
    return nodes;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 83 with Response

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

the class SOLRWebScriptTest method getTransactions.

private JSONArray getTransactions(long fromCommitTime) throws Exception {
    String url = "/api/solr/transactions?fromCommitTime=" + fromCommitTime;
    TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
    long startTime = System.currentTimeMillis();
    Response response = sendRequest(req, Status.STATUS_OK, admin);
    long endTime = System.currentTimeMillis();
    if (logger.isDebugEnabled()) {
        logger.debug(response.getContentAsString());
    }
    JSONObject json = new JSONObject(response.getContentAsString());
    JSONArray transactions = json.getJSONArray("transactions");
    logger.debug("Got " + transactions.length() + " txns in " + (endTime - startTime) + " ms");
    return transactions;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 84 with Response

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

the class CustomModelImportTest method testValidUpload_ExtModuleOnly.

public void testValidUpload_ExtModuleOnly() throws Exception {
    File zipFile = getResourceFile("validExtModule.zip");
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
    Response response = sendRequest(postRequest, 403);
    AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
    response = sendRequest(postRequest, 200);
    JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
    assertFalse(json.has("modelName"));
    String extModule = json.getString("shareExtModule");
    Document document = XMLUtil.parse(extModule);
    NodeList nodes = document.getElementsByTagName("id");
    assertEquals(1, nodes.getLength());
    assertNotNull(nodes.item(0).getTextContent());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 85 with Response

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

the class CustomModelImportTest method testValidUpload_ModelAndExtModule.

public void testValidUpload_ModelAndExtModule() throws Exception {
    File zipFile = getResourceFile("validModelAndExtModule.zip");
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
    Response response = sendRequest(postRequest, 403);
    AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
    response = sendRequest(postRequest, 200);
    JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
    String importedModelName = json.getString("modelName");
    importedModels.add(importedModelName);
    String extModule = json.getString("shareExtModule");
    Document document = XMLUtil.parse(extModule);
    NodeList nodes = document.getElementsByTagName("id");
    assertEquals(1, nodes.getLength());
    assertNotNull(nodes.item(0).getTextContent());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) ZipFile(java.util.zip.ZipFile) File(java.io.File)

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