Search in sources :

Example 6 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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 7 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest 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)

Example 8 with PostRequest

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

the class UploadWebScriptTest method buildMultipartPostRequest.

public PostRequest buildMultipartPostRequest(File file, String filename, String siteId, String containerId) throws IOException {
    Part[] parts = { new FilePart("filedata", file.getName(), file, "text/plain", null), new StringPart("filename", filename), new StringPart("description", "description"), new StringPart("siteid", siteId), new StringPart("containerid", containerId) };
    MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new HttpMethodParams());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    multipartRequestEntity.writeRequest(os);
    PostRequest postReq = new PostRequest(UPLOAD_URL, os.toByteArray(), multipartRequestEntity.getContentType());
    return postReq;
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) Part(org.apache.commons.httpclient.methods.multipart.Part) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpMethodParams(org.apache.commons.httpclient.params.HttpMethodParams) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart)

Example 9 with PostRequest

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

the class FacetRestApiTest method testCreateFacetWithLongFormQnameFilterId.

/**
 * The REST API should accept both 'cm:name' and '{http://www.alfresco.org/model/content/1.0}name' forms of filter IDs.
 */
public void testCreateFacetWithLongFormQnameFilterId() throws Exception {
    final JSONObject filter = new JSONObject();
    final String filterName = "filter" + GUID.generate();
    filters.add(filterName);
    filter.put("filterID", filterName);
    // This is the long-form qname that needs to be acceptable.
    filter.put("facetQName", "{http://www.alfresco.org/model/content/1.0}testLongQname");
    filter.put("displayName", "facet-menu.facet.testLongQname");
    filter.put("displayControl", "alfresco/search/FacetFilters/testLongQname");
    filter.put("maxFilters", 5);
    filter.put("hitThreshold", 1);
    filter.put("minFilterValueLength", 4);
    filter.put("sortBy", "ALPHABETICALLY");
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            // Post the filter
            sendRequest(new PostRequest(POST_FACETS_URL, filter.toString(), "application/json"), 200);
            return null;
        }
    }, SEARCH_ADMIN_USER);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 10 with PostRequest

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

the class FormRestApiGet_Test method testJsonForcedFields.

public void testJsonForcedFields() throws Exception {
    JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
    JSONArray jsonFields = new JSONArray();
    jsonFields.put("cm:name");
    jsonFields.put("cm:title");
    jsonFields.put("cm:publisher");
    jsonFields.put("cm:wrong");
    jsonPostData.put("fields", jsonFields);
    JSONArray jsonForcedFields = new JSONArray();
    jsonForcedFields.put("cm:publisher");
    jsonForcedFields.put("cm:wrong");
    jsonPostData.put("force", jsonForcedFields);
    // Submit the JSON request.
    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 definitionObject = (JSONObject) rootDataObject.get("definition");
    JSONArray fieldsArray = (JSONArray) definitionObject.get("fields");
    assertEquals("Expected 3 fields", 3, fieldsArray.length());
    // get the name and title definitions
    JSONObject nameField = (JSONObject) fieldsArray.get(0);
    JSONObject titleField = (JSONObject) fieldsArray.get(1);
    String nameFieldDataKey = nameField.getString("dataKeyName");
    String titleFieldDataKey = titleField.getString("dataKeyName");
    // get the data and check it
    JSONObject formDataObject = (JSONObject) rootDataObject.get("formData");
    assertNotNull("Expected to find cm:name data", formDataObject.get(nameFieldDataKey));
    assertNotNull("Expected to find cm:title data", formDataObject.get(titleFieldDataKey));
    assertEquals(TEST_FORM_TITLE, formDataObject.get("prop_cm_title"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

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