use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testLinkCRUD.
// note: app:folderlink & app:filelink both extend cm:link (which in turn extends cm:cmobject)
// (see applicationModel.xml / contentModel.xml)
@Test
public void testLinkCRUD() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
UserInfo expectedUser = new UserInfo(user1);
String myChildrenUrl = getNodeChildrenUrl(myNodeId);
// create folder f1
Folder folderResp = createFolder(myNodeId, "f1 " + RUNID);
String f1Id = folderResp.getId();
// create empty file d1 in f1
Document d1 = new Document();
d1.setName("d1.txt");
d1.setNodeType(TYPE_CM_CONTENT);
HttpResponse response = post(getNodeChildrenUrl(f1Id), toJsonAsStringNonNull(d1), 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String d1Id = documentResp.getId();
// create folder f2
folderResp = createFolder(myNodeId, "f2 " + RUNID);
String f2Id = folderResp.getId();
// create folder link node in f2 (pointing to f1)
String nodeName = "f1 link";
String nodeType = "app:folderlink";
Map<String, Object> props = new HashMap<>();
props.put("cm:destination", f1Id);
Node nodeResp = createNode(f2Id, nodeName, nodeType, props);
String n1Id = nodeResp.getId();
Node n1 = new Node();
n1.setName(nodeName);
n1.setNodeType(nodeType);
n1.setIsFolder(true);
// note: parent of the link (not where it is pointing)
n1.setParentId(f2Id);
n1.setAspectNames(Collections.singletonList("cm:auditable"));
n1.setProperties(props);
n1.setCreatedByUser(expectedUser);
n1.setModifiedByUser(expectedUser);
n1.expected(nodeResp);
// get node info
response = getSingle(NodesEntityResource.class, n1Id, null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
n1.expected(nodeResp);
// create file link node in f2 pointing to d1
nodeName = "d1 link";
nodeType = "app:filelink";
props = new HashMap<>();
props.put("cm:destination", d1Id);
nodeResp = createNode(f2Id, nodeName, nodeType, props);
String n2Id = nodeResp.getId();
Node n2 = new Node();
n2.setName(nodeName);
n2.setNodeType(nodeType);
n2.setIsFolder(false);
// note: parent of the link (not where it is pointing)
n2.setParentId(f2Id);
n2.setAspectNames(Collections.singletonList("cm:auditable"));
n2.setProperties(props);
n2.setCreatedByUser(expectedUser);
n2.setModifiedByUser(expectedUser);
n2.expected(nodeResp);
// get node info
response = getSingle(NodesEntityResource.class, n2Id, null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
n2.expected(nodeResp);
// update node - rename
String updatedName = "f1 link renamed";
Node nUpdate = new Node();
nUpdate.setName(updatedName);
response = put(URL_NODES, n1Id, toJsonAsStringNonNull(nUpdate), null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
n1.setName(updatedName);
n1.expected(nodeResp);
// filtering, via where clause (nodeType + optionally including sub-types)
List<String> linkIds = Arrays.asList(n1Id, n2Id);
Map<String, String> params = new HashMap<>();
params.put("where", "(nodeType='cm:link')");
Paging paging = getPaging(0, Integer.MAX_VALUE);
response = getAll(getNodeChildrenUrl(f2Id), paging, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
// filter by including sub-types - note: includesubtypes is case-insensitive
params = new HashMap<>();
params.put("where", "(nodeType='cm:link INCLUDESUBTYPES')");
paging = getPaging(0, Integer.MAX_VALUE);
response = getAll(getNodeChildrenUrl(f2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(linkIds.size(), nodes.size());
assertTrue(linkIds.contains(nodes.get(0).getId()));
assertTrue(linkIds.contains(nodes.get(1).getId()));
params = new HashMap<>();
params.put("where", "(nodeType='cm:link includeSubTypes')");
paging = getPaging(0, Integer.MAX_VALUE);
response = getAll(getNodeChildrenUrl(f2Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(linkIds.size(), nodes.size());
assertTrue(linkIds.contains(nodes.get(0).getId()));
assertTrue(linkIds.contains(nodes.get(1).getId()));
// delete link
deleteNode(n1Id);
// -ve test - delete - cannot delete nonexistent link
deleteNode(n1Id, 404);
// -ve test - create - name is mandatory
Node invalid = new Node();
invalid.setNodeType("cm:link");
post(myChildrenUrl, toJsonAsStringNonNull(invalid), 400);
// -ve test - create - node type is mandatory
invalid = new Node();
invalid.setName("my node");
post(myChildrenUrl, toJsonAsStringNonNull(invalid), 400);
// -ve test - create - unsupported node type
invalid = new Node();
invalid.setName("my node");
invalid.setNodeType("sys:base");
post(myChildrenUrl, toJsonAsStringNonNull(invalid), 400);
// -ve test - create - duplicate name
post(getNodeChildrenUrl(f2Id), toJsonAsStringNonNull(n2), 409);
// -ve test - unknown nodeType when filtering
params = new HashMap<>();
params.put("where", "(nodeType='my:unknown'");
getAll(getNodeChildrenUrl(f2Id), paging, params, 400);
// -ver test - invalid node type localname format and suffix is not ' includesubtypes'
params = new HashMap<>();
params.put("where", "(nodeType='cm:link ')");
getAll(getNodeChildrenUrl(f2Id), paging, params, 400);
params = new HashMap<>();
params.put("where", "(nodeType='cm:link blah')");
getAll(getNodeChildrenUrl(f2Id), paging, params, 400);
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testRetrieveNodePermissions.
private void testRetrieveNodePermissions() throws Exception {
setRequestContext(user1);
// create folder with an empty document
String postUrl = createFolder();
String docId = createDocument(postUrl);
Map params = new HashMap<>();
params.put("include", "permissions");
// update permissions
Document dUpdate = new Document();
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
locallySetPermissions.add(new NodePermissions.NodePermission(groupB, PermissionService.CONSUMER, AccessStatus.DENIED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// update node
HttpResponse response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// Check if permission are retrieved if 'include=permissions' is not
// sent in the request
response = getSingle(NodesEntityResource.class, documentResp.getId(), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertNull("Permissions should not be retrieved unless included!", documentResp.getPermissions());
// Call again with 'include=permissions'
response = getSingle(NodesEntityResource.class, documentResp.getId(), params, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// Check that all permissions are retrieved
assertNotNull(documentResp.getPermissions());
assertTrue("Locally set permissions were not set properly!", documentResp.getPermissions().getLocallySet().size() == 2);
// Check inherit default true
assertTrue("Inheritance flag was not retrieved!", documentResp.getPermissions().getIsInheritanceEnabled());
// Check inherited permissions (for ROLE_OWNER and user1)
assertNotNull(documentResp.getPermissions().getInherited());
assertTrue(documentResp.getPermissions().getInherited().size() == 2);
assertNotNull(documentResp.getPermissions().getSettable());
assertTrue(documentResp.getPermissions().getSettable().size() == 5);
Set<String> expectedSettable = new HashSet<>(Arrays.asList("Coordinator", "Collaborator", "Contributor", "Consumer", "Editor"));
assertTrue("Incorrect list of settable permissions returned!", documentResp.getPermissions().getSettable().containsAll(expectedSettable));
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testListChildrenWithinMyFiles.
/**
* Tests list children.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testListChildrenWithinMyFiles() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
String rootChildrenUrl = getNodeChildrenUrl(Nodes.PATH_ROOT);
String folder0Name = "folder " + RUNID + " 0";
String folder0Id = createFolder(myNodeId, folder0Name, null).getId();
String childrenUrl = getNodeChildrenUrl(folder0Id);
Map<String, Object> props = new HashMap<>(1);
props.put("cm:title", "This is folder 1");
String folder1 = "folder " + RUNID + " 1";
String folder1_Id = createFolder(folder0Id, folder1, props).getId();
String contentF1 = "content" + RUNID + " in folder 1";
String contentF1_Id = createTextFile(folder1_Id, contentF1, "The quick brown fox jumps over the lazy dog 1.").getId();
props = new HashMap<>(1);
props.put("cm:title", "This is folder 2");
String folder2 = "folder " + RUNID + " 2";
String folder2_Id = createFolder(folder0Id, folder2, props).getId();
String contentF2 = "content" + RUNID + " in folder 2.txt";
String contentF2_Id = createTextFile(folder2_Id, contentF2, "The quick brown fox jumps over the lazy dog 2.").getId();
String content1 = "content" + RUNID + " 1.txt";
String content1_Id = createTextFile(folder0Id, content1, "The quick brown fox jumps over the lazy dog.").getId();
props = new HashMap<>();
props.put(PROP_OWNER, user1);
props.put("cm:lastThumbnailModification", Collections.singletonList("doclib:1444660852296"));
Node nodeUpdate = new Node();
nodeUpdate.setProperties(props);
put(URL_NODES, content1_Id, toJsonAsStringNonNull(nodeUpdate), null, 200);
List<String> folderIds = Arrays.asList(folder1_Id, folder2_Id);
List<String> contentIds = Arrays.asList(content1_Id);
Paging paging = getPaging(0, 100);
HttpResponse response = getAll(childrenUrl, paging, 200);
List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(3, nodes.size());
// Order by folders and modified date first
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
response = getAll(childrenUrl, paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(3, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertEquals(folder1, nodes.get(1).getName());
Document node = nodes.get(2);
assertEquals(content1, node.getName());
assertEquals(TYPE_CM_CONTENT, node.getNodeType());
assertEquals(content1_Id, node.getId());
UserInfo createdByUser = node.getCreatedByUser();
assertEquals(user1, createdByUser.getId());
assertEquals(UserInfo.getTestDisplayName(user1), createdByUser.getDisplayName());
UserInfo modifiedByUser = node.getModifiedByUser();
assertEquals(user1, modifiedByUser.getId());
assertEquals(UserInfo.getTestDisplayName(user1), modifiedByUser.getDisplayName());
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, node.getContent().getMimeType());
assertNotNull(node.getContent().getMimeTypeName());
assertNotNull(node.getContent().getEncoding());
assertTrue(node.getContent().getSizeInBytes() > 0);
// request without "include"
Map<String, String> params = new HashMap<>();
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
for (Node n : nodes) {
assertNull("There shouldn't be a 'properties' object in the response.", n.getProperties());
assertNull("There shouldn't be a 'isLink' object in the response.", n.getIsLink());
assertNull("There shouldn't be a 'path' object in the response.", n.getPath());
assertNull("There shouldn't be a 'aspectNames' object in the response.", n.getAspectNames());
}
// request with include - example 1
params = new HashMap<>();
params.put("include", "isLink");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
for (Node n : nodes) {
assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink());
}
// request with include - example 2
params = new HashMap<>();
params.put("include", "aspectNames,properties,path,isLink");
response = getAll(childrenUrl, paging, params, 200);
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class);
for (Node n : nodes) {
// eg. cm:title, see above
assertNotNull("There should be a 'properties' object in the response.", n.getProperties());
assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink());
assertNotNull("There should be a 'path' object in the response.", n.getPath());
assertNotNull("There should be a 'aspectNames' object in the response.", n.getAspectNames());
}
// request specific property via include
params = new HashMap<>();
params.put("include", "cm:lastThumbnailModification");
params.put("orderBy", "isFolder DESC,modifiedAt DESC");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(3, nodes.size());
assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(0).getProperties());
assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(1).getProperties());
assertNotNull("There should be a 'properties' object in the response.", nodes.get(2).getProperties());
Set<Entry<String, Object>> propsSet = nodes.get(2).getProperties().entrySet();
assertEquals(1, propsSet.size());
Entry<String, Object> entry = propsSet.iterator().next();
assertEquals("cm:lastThumbnailModification", entry.getKey());
assertEquals("doclib:1444660852296", ((List<?>) entry.getValue()).get(0));
// filtering, via where clause - folders only
params = new HashMap<>();
params.put("where", "(" + Nodes.PARAM_ISFOLDER + "=true)");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(2, nodes.size());
assertTrue(nodes.get(0).getIsFolder());
assertFalse(nodes.get(0).getIsFile());
assertTrue(folderIds.contains(nodes.get(0).getId()));
assertTrue(nodes.get(1).getIsFolder());
assertFalse(nodes.get(1).getIsFile());
assertTrue(folderIds.contains(nodes.get(1).getId()));
// filtering, via where clause - content only
params = new HashMap<>();
params.put("where", "(" + Nodes.PARAM_ISFILE + "=true)");
response = getAll(childrenUrl, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
assertEquals(1, nodes.size());
assertFalse(nodes.get(0).getIsFolder());
assertTrue(nodes.get(0).getIsFile());
assertTrue(contentIds.contains(nodes.get(0).getId()));
// list children via relativePath
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1);
response = getAll(childrenUrl, paging, params, 200);
JSONObject jsonResponse = response.getJsonResponse();
nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
assertEquals(1, nodes.size());
assertEquals(contentF1_Id, nodes.get(0).getId());
JSONObject jsonList = (JSONObject) jsonResponse.get("list");
assertNotNull(jsonList);
JSONObject jsonSrcObj = (JSONObject) jsonResponse.get("source");
assertNull(jsonSrcObj);
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder0Name + "/" + folder2);
response = getAll(rootChildrenUrl, paging, params, 200);
jsonResponse = response.getJsonResponse();
nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
assertEquals(1, nodes.size());
assertEquals(contentF2_Id, nodes.get(0).getId());
jsonList = (JSONObject) jsonResponse.get("list");
assertNotNull(jsonList);
jsonSrcObj = (JSONObject) jsonResponse.get("source");
assertNull(jsonSrcObj);
// list children via relativePath and also return the source entity
params = new HashMap<>();
params.put(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder0Name + "/" + folder2);
params.put("includeSource", "true");
params.put("include", "path,isLink");
params.put("fields", "id");
response = getAll(rootChildrenUrl, paging, params, 200);
jsonResponse = response.getJsonResponse();
nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
assertEquals(1, nodes.size());
Document doc = nodes.get(0);
assertEquals(contentF2_Id, doc.getId());
assertNotNull(doc.getPath());
assertEquals(Boolean.FALSE, doc.getIsLink());
assertNull(doc.getName());
jsonList = (JSONObject) jsonResponse.get("list");
assertNotNull(jsonList);
// source is not affected by include (or fields for that matter) - returns the default node response
Folder src = RestApiUtil.parsePojo("source", jsonList, Folder.class);
assertEquals(folder2_Id, src.getId());
assertNull(src.getPath());
assertNull(src.getIsLink());
assertNotNull(src.getName());
assertNotNull(src.getAspectNames());
assertNotNull(src.getProperties());
// -ve test - Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter.
params = Collections.singletonMap("orderBy", Nodes.PARAM_ISFOLDER + " DESC,cm" + System.currentTimeMillis() + ":modified DESC");
getAll(childrenUrl, paging, params, 400);
paging = getPaging(0, 10);
// -ve test - list folder children for unknown node should return 404
getAll(getNodeChildrenUrl(UUID.randomUUID().toString()), paging, 404);
// -ve test - user2 tries to access user1's home folder
setRequestContext(user2);
getAll(getNodeChildrenUrl(myNodeId), paging, 403);
setRequestContext(user1);
// -ve test - try to list children using relative path to unknown node
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/unknown");
getAll(rootChildrenUrl, paging, params, 404);
// -ve test - try to list children using relative path to node for which user does not have read permission (expect 404 instead of 403)
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user2);
getAll(rootChildrenUrl, paging, params, 404);
// -ve test - list folder children with relative path to unknown node should return 400
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
getAll(getNodeChildrenUrl(content1_Id), paging, params, 400);
// filtering, via where clause - negated comparison
params = new HashMap<>();
params.put("where", "(NOT " + Nodes.PARAM_ISFILE + "=true)");
getAll(childrenUrl, paging, params, 400);
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdatePermissionAddDuplicate.
/**
* Test add duplicate permissions
*
* @throws Exception
*/
private void testUpdatePermissionAddDuplicate() throws Exception {
// create folder with an empty document
String postUrl = createFolder();
String dId = createDocument(postUrl);
// update permissions
Document dUpdate = new Document();
// Add same permission with different access status
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.DENIED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// "Duplicate node permissions, there is more than one permission with
// the same authority and name!"
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
// Add the same permission with same access status
locallySetPermissions.clear();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// "Duplicate node permissions, there is more than one permission with
// the same authority and name!"
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdateFileWithBinaryUpload.
/**
* Tests update file content
* <p>PUT:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/content}
*/
@Test
public void testUpdateFileWithBinaryUpload() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
String folderName = "f1-testUpdateFileWithBinaryUpload-" + RUNID;
Folder folderResp = createFolder(myNodeId, folderName);
String f1_nodeId = folderResp.getId();
String anoNodeName = "another";
createFolder(f1_nodeId, anoNodeName);
Document doc = new Document();
final String docName = "testdoc.txt";
doc.setName(docName);
doc.setNodeType(TYPE_CM_CONTENT);
doc.setProperties(Collections.singletonMap("cm:title", (Object) "test title"));
ContentInfo contentInfo = new ContentInfo();
doc.setContent(contentInfo);
// create an empty file within F1 folder
HttpResponse response = post(getNodeChildrenUrl(f1_nodeId), toJsonAsStringNonNull(doc), 201);
Document docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(docName, docResp.getName());
assertNotNull(docResp.getContent());
assertEquals(0, docResp.getContent().getSizeInBytes().intValue());
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, docResp.getContent().getMimeType());
// Default encoding
assertEquals("UTF-8", docResp.getContent().getEncoding());
// Update the empty node's content
String content = "The quick brown fox jumps over the lazy dog.";
ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
BinaryPayload payload = new BinaryPayload(txtFile);
// Try to update a folder!
putBinary(getNodeContentUrl(f1_nodeId), payload, null, null, 400);
// Try to update a non-existent file
putBinary(getNodeContentUrl(UUID.randomUUID().toString()), payload, null, null, 404);
final String url = getNodeContentUrl(docResp.getId());
// Update the empty file
response = putBinary(url, payload, null, null, 200);
docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(docName, docResp.getName());
assertNotNull(docResp.getId());
assertNotNull(docResp.getCreatedAt());
assertNotNull(docResp.getCreatedByUser());
assertNotNull(docResp.getModifiedAt());
assertNotNull(docResp.getModifiedByUser());
assertFalse(docResp.getIsFolder());
assertTrue(docResp.getIsFile());
assertNull(docResp.getIsLink());
assertEquals(TYPE_CM_CONTENT, docResp.getNodeType());
assertNotNull(docResp.getParentId());
assertEquals(f1_nodeId, docResp.getParentId());
assertNotNull(docResp.getProperties());
assertNotNull(docResp.getAspectNames());
contentInfo = docResp.getContent();
assertNotNull(contentInfo);
assertNotNull(contentInfo.getEncoding());
assertTrue(contentInfo.getSizeInBytes() > 0);
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
assertNotNull(contentInfo.getMimeTypeName());
assertEquals("ISO-8859-1", contentInfo.getEncoding());
// path is not part of the default response
assertNull(docResp.getPath());
// Download the file
response = getSingle(url, user1, null, 200);
assertEquals(content, response.getResponse());
// Update the node's content again. Also make the response return the path!
content = "The quick brown fox jumps over the lazy dog updated !";
inputStream = new ByteArrayInputStream(content.getBytes());
txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
payload = new BinaryPayload(txtFile);
response = putBinary(url + "?include=path", payload, null, null, 200);
docResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
assertEquals(docName, docResp.getName());
assertNotNull(docResp.getContent());
assertTrue(docResp.getContent().getSizeInBytes().intValue() > 0);
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, docResp.getContent().getMimeType());
assertEquals("ISO-8859-1", docResp.getContent().getEncoding());
PathInfo pathInfo = docResp.getPath();
assertNotNull(pathInfo);
assertTrue(pathInfo.getIsComplete());
List<ElementInfo> pathElements = pathInfo.getElements();
assertNotNull(pathElements);
assertTrue(pathElements.size() > 0);
// check the last element is F1
assertEquals(folderResp.getName(), pathElements.get(pathElements.size() - 1).getName());
// Download the file
response = getSingle(url, user1, null, 200);
assertEquals(content, response.getResponse());
// Update the node's content again. Also rename the file !
content = "The quick brown fox jumps over the lazy dog updated again !";
inputStream = new ByteArrayInputStream(content.getBytes());
txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
payload = new BinaryPayload(txtFile);
String docName2 = "hello-world.txt";
Map params = new HashMap<>();
params.put(Nodes.PARAM_NAME, docName2);
response = putBinary(url, payload, null, params, 200);
docResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
assertEquals(docName2, docResp.getName());
// Download the file
response = getSingle(url, user1, null, 200);
assertEquals(content, response.getResponse());
// -ve - optional "name" is invalid
params = new HashMap<>();
params.put(Nodes.PARAM_NAME, "hello/world.txt");
payload = new BinaryPayload(txtFile);
putBinary(url, payload, null, params, 422);
// -ve - optional "name" already exists ...
params = new HashMap<>();
params.put(Nodes.PARAM_NAME, anoNodeName);
payload = new BinaryPayload(txtFile);
putBinary(url, payload, null, params, 409);
// -ve - try to update content using multi-part form data
payload = new BinaryPayload(txtFile, "multipart/form-data", null);
putBinary(url, payload, null, null, 415);
// -ve - try to invalid media type argument (when parsing request)
payload = new BinaryPayload(txtFile, "/jpeg", null);
putBinary(url, payload, null, null, 415);
}
Aggregations