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