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);
}
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");
}
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;
}
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);
}
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"));
}
Aggregations