use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class DeletedNodesTest method testDownloadRendition.
/**
* Tests download rendition.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/deleted-nodes/<nodeId>/renditions/<renditionId>/content}
*/
@Test
public void testDownloadRendition() throws Exception {
setRequestContext(user1);
// Create a folder within the site document's library
Date now = new Date();
String folder1 = "folder" + now.getTime() + "_1";
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
assertNotNull(createdFolder);
String f1Id = createdFolder.getId();
// Create multipart request using an existing file
String fileName = "quick.pdf";
File file = getResourceFile(fileName);
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new MultiPartBuilder.FileData(fileName, file));
MultiPartBuilder.MultiPartRequest reqBody = multiPartBuilder.build();
// Upload quick.pdf file into 'folder'
HttpResponse response = post(getNodeChildrenUrl(f1Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String contentNodeId = document.getId();
Rendition rendition = createAndGetRendition(contentNodeId, "doclib");
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
deleteNode(contentNodeId);
// Download rendition - by default with Content-Disposition header
response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", 200);
assertNotNull(response.getResponseAsBytes());
Map<String, String> responseHeaders = response.getHeaders();
assertNotNull(responseHeaders);
String contentDisposition = responseHeaders.get("Content-Disposition");
assertNotNull(contentDisposition);
assertTrue(contentDisposition.contains("filename=\"doclib\""));
String contentType = responseHeaders.get("Content-Type");
assertNotNull(contentType);
assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
// Download rendition - without Content-Disposition header
// (attachment=false)
Map<String, String> params = new HashMap<>();
params = Collections.singletonMap("attachment", "false");
response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
assertNotNull(response.getResponseAsBytes());
responseHeaders = response.getHeaders();
assertNotNull(responseHeaders);
assertNull(responseHeaders.get("Content-Disposition"));
contentType = responseHeaders.get("Content-Type");
assertNotNull(contentType);
assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
// Download rendition - with Content-Disposition header
// (attachment=true) same as default
params = Collections.singletonMap("attachment", "true");
response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, 200);
assertNotNull(response.getResponseAsBytes());
responseHeaders = response.getHeaders();
assertNotNull(responseHeaders);
String cacheControl = responseHeaders.get("Cache-Control");
assertNotNull(cacheControl);
assertFalse(cacheControl.contains("must-revalidate"));
assertTrue(cacheControl.contains("max-age=31536000"));
contentDisposition = responseHeaders.get("Content-Disposition");
assertNotNull(contentDisposition);
assertTrue(contentDisposition.contains("filename=\"doclib\""));
contentType = responseHeaders.get("Content-Type");
assertNotNull(contentType);
assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
// Test 304 response - doclib rendition (attachment=true)
String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER);
assertNotNull(lastModifiedHeader);
Map<String, String> headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader);
getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, 304);
// -ve tests
// nodeId in the path parameter does not represent a file
deleteNode(f1Id);
getSingle(getDeletedNodeRenditionsUrl(f1Id), "doclib/content", 400);
// nodeId in the path parameter does not exist
getSingle(getDeletedNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib/content", 404);
// renditionId in the path parameter is not registered/available
getSingle(getDeletedNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), 404);
// The rendition does not exist, a placeholder is not available and the
// placeholder parameter has a value of "true"
params = Collections.singletonMap("placeholder", "true");
getSingle(getDeletedNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis() + "/content"), params, 404);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class BasicSearchApiIntegrationTest method testQuery.
/**
* Tests basic api for search
*/
@Test
public void testQuery() throws Exception {
setRequestContext(user1);
String f1Id = null;
try {
// As user 1 ...
// Try to get nodes with search term 'king*' - assume clean repo (ie. none to start with)
HttpResponse response = post(URL_SEARCH, json, null, null, SEARCH_API_NAME, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
String myFolderNodeId = getMyNodeId();
f1Id = createFolder(myFolderNodeId, "king").getId();
response = post(URL_SEARCH, json, null, null, SEARCH_API_NAME, 200);
ExpectedPaging paging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(1, paging.getTotalItems().intValue());
assertFalse(paging.getHasMoreItems());
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(1, nodes.size());
// Just happy if it doesn't error
response = post(URL_SEARCH, SerializerTestHelper.JSON, null, null, SEARCH_API_NAME, 200);
} finally {
// some cleanup
if (f1Id != null) {
deleteNode(f1Id, true, 204);
}
}
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class AbstractBaseApiTest method addSiteMember.
protected SiteMember addSiteMember(String siteId, String userId, final SiteRole siteRole) throws Exception {
SiteMember siteMember = new SiteMember(userId, siteRole.name());
HttpResponse response = publicApiClient.post(getScope(), "sites", siteId, "members", null, siteMember.toJSON().toString());
checkStatus(201, response.getStatusCode());
return SiteMember.parseSiteMember(siteMember.getSiteId(), (JSONObject) response.getJsonResponse().get("entry"));
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class AbstractBaseApiTest method createNode.
protected <T> T createNode(String parentId, String nodeName, String nodeType, Map<String, Object> props, Class<T> returnType) throws Exception {
Node n = new Node();
n.setName(nodeName);
n.setNodeType(nodeType);
n.setProperties(props);
// create node
HttpResponse response = post(getNodeChildrenUrl(parentId), RestApiUtil.toJsonAsStringNonNull(n), 201);
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class AbstractBaseApiTest method createSite.
protected Site createSite(String siteId, String siteTitle, String siteDescription, SiteVisibility siteVisibility, int expectedStatus) throws Exception {
Site site = new Site();
site.setId(siteId);
site.setTitle(siteTitle);
site.setVisibility(siteVisibility);
site.setDescription(siteDescription);
HttpResponse response = publicApiClient.post(getScope(), "sites", null, null, null, toJsonAsStringNonNull(site));
checkStatus(expectedStatus, response.getStatusCode());
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
}
Aggregations