Search in sources :

Example 51 with PostRequest

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

the class SubscriptionServiceRestApiTest method follow.

protected void follow(String user1, String user2) throws Exception {
    JSONArray jsonUsers = new JSONArray();
    jsonUsers.put(user2);
    String url = getUrl(URL_FOLLOW, user1);
    sendRequest(new PostRequest(url, jsonUsers.toString(), "application/json"), Status.STATUS_NO_CONTENT);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONArray(org.json.JSONArray)

Example 52 with PostRequest

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

the class SubscriptionServiceRestApiTest method follows.

protected boolean follows(String user1, String user2) throws Exception {
    JSONArray jsonUsers = new JSONArray();
    jsonUsers.put(user2);
    String url = getUrl(URL_FOLLOWS, user1);
    Response response = sendRequest(new PostRequest(url, jsonUsers.toString(), "application/json"), Status.STATUS_OK);
    JSONArray resultArray = new JSONArray(response.getContentAsString());
    assertEquals(1, resultArray.length());
    JSONObject resultObject = resultArray.getJSONObject(0);
    assertTrue(resultObject.has(user2));
    return resultObject.getBoolean(user2);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 53 with PostRequest

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

the class ThumbnailServiceTest method testCreateThumbnail.

public void testCreateThumbnail() throws Exception {
    // Check for pdfToSWF transformation before doing test
    if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_FLASH, new TransformationOptions()) != null) {
        String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnails";
        JSONObject tn = new JSONObject();
        tn.put("thumbnailName", "webpreview");
        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(0, getArr.length());
    // Do a image transformation (medium)
    String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails";
    JSONObject tn = new JSONObject();
    tn.put("thumbnailName", "medium");
    Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200);
    System.out.println(response.getContentAsString());
    JSONObject result = new JSONObject(response.getContentAsString());
    String thumbnailUrl = result.getString("url").substring(17);
    System.out.println(thumbnailUrl);
    response = sendRequest(new GetRequest(thumbnailUrl), 200);
    // Check getAll whilst we are here
    getAllResp = sendRequest(new GetRequest(getThumbnailsURL(jpgNode)), 200);
    getArr = new JSONArray(getAllResp.getContentAsString());
    assertNotNull(getArr);
    assertEquals(1, getArr.length());
    assertEquals("medium", getArr.getJSONObject(0).get("thumbnailName"));
}
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) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions)

Example 54 with PostRequest

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

the class TransferWebScriptTest method testVerify.

public void testVerify() throws Exception {
    String url = "/api/transfer/test";
    PostRequest req = new PostRequest(url, new JSONObject().toString(), "application/json");
    // First, we'll try the request as a simple, non-admin user (expect a 401)
    AuthenticationUtil.setFullyAuthenticatedUser(USERNAME);
    sendRequest(req, 401);
    // Then we'll have a go as the system user (expect a 200)
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME);
    sendRequest(req, 200);
    // Then we'll disable the transfer receiver and try again as the system user (expect a 404)
    TransferWebScript webscript = (TransferWebScript) getServer().getApplicationContext().getBean("webscript.org.alfresco.repository.transfer.transfer.post");
    webscript.setEnabled(false);
    sendRequest(req, 404);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 55 with PostRequest

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

the class FormRestApiGet_Test method testJsonFormData.

@SuppressWarnings("unchecked")
public void testJsonFormData() throws Exception {
    JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
    String jsonPostString = jsonPostData.toString();
    Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 200);
    String jsonResponseString = rsp.getContentAsString();
    JSONObject jsonParsedObject = new JSONObject(new JSONTokener(jsonResponseString));
    assertNotNull(jsonParsedObject);
    JSONObject rootDataObject = (JSONObject) jsonParsedObject.get("data");
    JSONObject formDataObject = (JSONObject) rootDataObject.get("formData");
    List<String> keys = new ArrayList<String>();
    for (Iterator iter = formDataObject.keys(); iter.hasNext(); ) {
        String nextFieldName = (String) iter.next();
        assertEquals("Did not expect to find a colon char in " + nextFieldName, -1, nextFieldName.indexOf(':'));
        keys.add(nextFieldName);
    }
    // Threshold is a rather arbitrary number. I simply want to ensure that there
    // are *some* entries in the formData hash.
    final int threshold = 5;
    int actualKeyCount = keys.size();
    assertTrue("Expected more than " + threshold + " entries in formData. Actual: " + actualKeyCount, actualKeyCount > threshold);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Aggregations

PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)110 JSONObject (org.json.JSONObject)90 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)84 JSONArray (org.json.JSONArray)28 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)25 JSONTokener (org.json.JSONTokener)23 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)14 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)10 JSONStringer (org.json.JSONStringer)9 File (java.io.File)8 ZipFile (java.util.zip.ZipFile)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JSONObject (org.json.simple.JSONObject)5 IOException (java.io.IOException)4 UserTransaction (javax.transaction.UserTransaction)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 JSONException (org.json.JSONException)4 Serializable (java.io.Serializable)3