Search in sources :

Example 26 with Response

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

the class SubscriptionServiceRestApiTest method getFollowing.

protected List<String> getFollowing(String user) throws Exception {
    String url = getUrl(URL_FOLLOWING, user);
    Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
    JSONObject resultObject = new JSONObject(response.getContentAsString());
    assertTrue(resultObject.has("people"));
    List<String> result = new ArrayList<String>();
    JSONArray people = resultObject.getJSONArray("people");
    for (int i = 0; i < people.length(); i++) {
        JSONObject person = people.getJSONObject(i);
        assertTrue(person.has("userName"));
        assertTrue(person.has("firstName"));
        assertTrue(person.has("lastName"));
        result.add(person.getString("userName"));
    }
    return result;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray)

Example 27 with Response

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

the class SubscriptionServiceRestApiTest method isSubscriptionListPrivate.

protected boolean isSubscriptionListPrivate(String user) throws Exception {
    String url = getUrl(URL_PRIVATE, user);
    Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
    JSONObject resultObject = new JSONObject(response.getContentAsString());
    assertTrue(resultObject.has("private"));
    return resultObject.getBoolean("private");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 28 with Response

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

the class ThumbnailServiceTest method testThumbnailDefinitions.

public void testThumbnailDefinitions() throws Exception {
    // Check for pdfToSWF transformation before doing test
    if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_FLASH) != null) {
        String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnaildefinitions";
        Response response = sendRequest(new GetRequest(url), 200);
        JSONArray array = new JSONArray(response.getContentAsString());
        assertNotNull(array);
        assertFalse(array.length() == 0);
        boolean hasMedium = false;
        boolean hasWebPreview = false;
        for (int i = 0; i < array.length(); i++) {
            if (array.getString(i).equals("medium") == true) {
                hasMedium = true;
            } else if (array.getString(i).equals("webpreview") == true) {
                hasWebPreview = true;
            }
        }
        assertTrue(hasMedium);
        assertTrue(hasWebPreview);
    }
    String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnaildefinitions";
    Response response = sendRequest(new GetRequest(url), 200);
    JSONArray array = new JSONArray(response.getContentAsString());
    assertNotNull(array);
    assertFalse(array.length() == 0);
    boolean hasMedium = false;
    boolean hasWebPreview = false;
    for (int i = 0; i < array.length(); i++) {
        if (array.getString(i).equals("medium") == true) {
            hasMedium = true;
        } else if (array.getString(i).equals("webpreview") == true) {
            hasWebPreview = true;
        }
    }
    assertTrue(hasMedium);
    assertFalse(hasWebPreview);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 29 with Response

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

the class ThumbnailServiceTest method testUpdateThumbnail.

public void testUpdateThumbnail() throws Exception {
    // Do a image transformation
    String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails";
    JSONObject tn = new JSONObject();
    tn.put("thumbnailName", "doclib");
    Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200);
    System.out.println(response.getContentAsString());
    // Check getAll whilst we are here
    Response getAllResp = sendRequest(new GetRequest(getThumbnailsURL(jpgNode)), 200);
    JSONArray getArr = new JSONArray(getAllResp.getContentAsString());
    assertNotNull(getArr);
    assertEquals(1, getArr.length());
    assertEquals("doclib", getArr.getJSONObject(0).get("thumbnailName"));
    // Now we know that thumbnail was created
    sendRequest(new GetRequest(getThumbnailsURL(jpgNode) + "/incorrectname"), 404);
    // Request for update of thumbnail, that is absent
    sendRequest(new PutRequest(getThumbnailsURL(jpgNode) + "/incorrectname", "", "application/json"), 404);
    // Request for update of correct thumbnail
    sendRequest(new PutRequest(getThumbnailsURL(jpgNode) + "/doclib", "", "application/json"), 200);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 30 with Response

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

the class ThumbnailServiceTest method testCreateAsyncThumbnail.

public void testCreateAsyncThumbnail() throws Exception {
    // Check for pdfToSWF transformation before doing test
    if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_FLASH) != null) {
        String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnails?as=true";
        JSONObject tn = new JSONObject();
        tn.put("thumbnailName", "webpreview");
        Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200);
        assertEquals("", response.getContentAsString().trim());
        getWait(pdfNode, "webpreview");
    }
    // Do a image transformation (medium)
    String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails?as=true";
    JSONObject tn = new JSONObject();
    tn.put("thumbnailName", "medium");
    Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200);
    assertEquals("", response.getContentAsString().trim());
    getWait(jpgNode, "medium");
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

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