use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdatePermissionsSetFalseInheritFromParent.
/**
* Test set inherit from parent to false
*
* @throws Exception
*/
private void testUpdatePermissionsSetFalseInheritFromParent() throws Exception {
// create folder
String testFolderUrl = createFolder();
String dId = createDocument(testFolderUrl);
// create a new document in testFolder and set inherit to false
Document dUpdate = new Document();
NodePermissions nodePermissionsUpdate = new NodePermissions();
nodePermissionsUpdate.setIsInheritanceEnabled(false);
dUpdate.setPermissions(nodePermissionsUpdate);
HttpResponse response = put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
Map params = new HashMap<>();
params.put("include", "permissions");
response = getSingle(NodesEntityResource.class, documentResp.getId(), params, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertFalse("Inheritance hasn't been disabled!", nodeResp.getPermissions().getIsInheritanceEnabled());
assertNull("Permissions were inherited from parent!", nodeResp.getPermissions().getInherited());
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeVersionsApiTest method testRevert.
/**
* Tests revert (ie. promote older version to become the latest/most recent version).
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/versions/<versionId>/revert}
*/
@Test
public void testRevert() throws Exception {
// As user 1 ...
setRequestContext(user1);
String sharedFolderNodeId = getSharedNodeId();
// create folder
String f1Id = null;
try {
f1Id = createFolder(sharedFolderNodeId, "testRevert-f1-" + System.currentTimeMillis()).getId();
int majorVersion = 1;
int minorVersion = 0;
int verCnt = 1;
String textContentSuffix = "The quick brown fox jumps over the lazy dog ";
String contentName = "content " + System.currentTimeMillis();
String content = textContentSuffix + verCnt;
String updateVerCommentSuffix = "Update comment ";
Map<String, String> params = new HashMap<>();
params.put(Nodes.PARAM_VERSION_COMMENT, updateVerCommentSuffix + verCnt);
// Upload text file - versioning is currently auto enabled on upload (create file via multi-part/form-data)
Document documentResp = createTextFile(f1Id, contentName, content, "UTF-8", params);
String d1Id = documentResp.getId();
// Update the content
int updateCnt = 3;
for (int i = 1; i <= updateCnt; i++) {
verCnt++;
minorVersion++;
// Update
content = textContentSuffix + verCnt;
ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile);
params = new HashMap<>();
params.put(Nodes.PARAM_VERSION_COMMENT, updateVerCommentSuffix + verCnt);
putBinary(getNodeContentUrl(d1Id), payload, null, params, 200);
}
// check version history count - also get properties so that we can check version label etc
params = new HashMap<>();
params.put("include", "properties");
HttpResponse response = getAll(getNodeVersionsUrl(d1Id), null, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(verCnt, nodes.size());
// check version labels and content
checkVersionHistoryAndContent(d1Id, nodes, verCnt, textContentSuffix, updateVerCommentSuffix, majorVersion, minorVersion, false);
int revertMajorVersion = 1;
int revertMinorVersion = 0;
String revertVerCommentSuffix = "Revert comment ";
int revertCnt = 3;
for (int i = 1; i <= revertCnt; i++) {
String revertVersionId = revertMajorVersion + "." + revertMinorVersion;
VersionOptions versionOptions = new VersionOptions();
versionOptions.setMajorVersion(true);
versionOptions.setComment(revertVerCommentSuffix + i);
post(getNodeVersionRevertUrl(d1Id, revertVersionId), toJsonAsStringNonNull(versionOptions), null, 200);
verCnt++;
revertMinorVersion++;
majorVersion++;
}
// check version history count - also get properties so that we can check version label etc
params = new HashMap<>();
params.put("include", "properties");
response = getAll(getNodeVersionsUrl(d1Id), null, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(verCnt, nodes.size());
// check version labels and content - most recently reverted, eg. version labels 4.0, 3.0, 2.0
List<Node> revertedNodes = nodes.subList(0, revertCnt);
checkVersionHistoryAndContent(d1Id, revertedNodes, updateCnt, textContentSuffix, revertVerCommentSuffix, majorVersion, 0, true);
// check version labels and content - the rest of the version history (prior to reverted), eg. version labels 1.3, 1.2, 1.1, 1.0
minorVersion = 3;
List<Node> originalUpdatedNodes = nodes.subList(revertCnt, nodes.size());
checkVersionHistoryAndContent(d1Id, originalUpdatedNodes, updateCnt + 1, textContentSuffix, updateVerCommentSuffix, 1, minorVersion, false);
// Currently, we also allow the most recent version to be reverted (ie. not disallowed by underlying VersionService)
post(getNodeVersionRevertUrl(d1Id, majorVersion + ".0"), "{}", null, 200);
{
setRequestContext(null);
// -ve test - unauthenticated - belts-and-braces ;-)
post(getNodeVersionRevertUrl(d1Id, "1.0"), "{}", null, 401);
setRequestContext(user1);
// -ve test - unknown nodeId
post(getNodeVersionRevertUrl("dummy", "1.0"), "{}", null, 404);
// -ve test - unknown versionId
post(getNodeVersionRevertUrl(d1Id, "15.0"), "{}", null, 404);
// -ve test - permission denied
setRequestContext(user2);
post(getNodeVersionRevertUrl(d1Id, "1.0"), "{}", null, 403);
}
} finally {
if (f1Id != null) {
// some cleanup
setRequestContext(user1);
deleteNode(f1Id, true, 204);
}
}
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeVersionsApiTest method testUpdateFileVersionCreate.
/**
* Test version creation when updating file binary content.
*
* <p>PUT:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/content}
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testUpdateFileVersionCreate() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
Document d1 = new Document();
d1.setName("d1.txt");
d1.setNodeType(TYPE_CM_CONTENT);
// create *empty* text file - as of now, versioning is not enabled by default
HttpResponse response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(d1), 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String docId = documentResp.getId();
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
// no properties (ie. no "cm:versionLabel")
assertNull(documentResp.getProperties());
int cnt = 0;
// updates - no versions
for (int i = 1; i <= 3; i++) {
cnt++;
// Update the empty node's content - no version created
String content = "The quick brown fox jumps over the lazy dog " + cnt;
documentResp = updateTextFile(docId, content, null);
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
// no properties (ie. no "cm:versionLabel")
assertNull(documentResp.getProperties());
}
// Update again - with version comment - versioning is enabled here by using version params ("comment" &/or "majorVersion")
// note: alternatively could add versionable aspect before doing the update (see separate test above)
cnt++;
int majorVersion = 1;
int minorVersion = 0;
String content = "The quick brown fox jumps over the lazy dog " + cnt;
Map<String, String> params = new HashMap<>();
params.put("comment", "my version " + cnt);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion + "." + minorVersion, documentResp.getProperties().get("cm:versionLabel"));
// Update again - with another version comment
cnt++;
minorVersion++;
content = "The quick brown fox jumps over the lazy dog " + cnt;
params = new HashMap<>();
params.put("comment", "my version " + cnt);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion + "." + minorVersion, documentResp.getProperties().get("cm:versionLabel"));
minorVersion = 0;
// Updates - major versions
for (int i = 1; i <= 3; i++) {
cnt++;
majorVersion++;
content = "The quick brown fox jumps over the lazy dog " + cnt;
params = new HashMap<>();
params.put("comment", "my version " + cnt);
params.put("majorVersion", "true");
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion + "." + minorVersion, documentResp.getProperties().get("cm:versionLabel"));
}
// Updates - minor versions
for (int i = 1; i <= 3; i++) {
cnt++;
minorVersion++;
content = "The quick brown fox jumps over the lazy dog " + cnt;
params = new HashMap<>();
params.put("comment", "my version " + cnt);
params.put("majorVersion", "false");
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion + "." + minorVersion, documentResp.getProperties().get("cm:versionLabel"));
}
// Update again - as another major version
cnt++;
majorVersion++;
minorVersion = 0;
content = "The quick brown fox jumps over the lazy dog " + cnt;
params = new HashMap<>();
params.put("comment", "my version " + cnt);
params.put("majorVersion", "true");
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion + "." + minorVersion, documentResp.getProperties().get("cm:versionLabel"));
// Update again - as another (minor) version
// note: no version params (comment &/or majorVersion) needed since versioning is enabled on this content
cnt++;
minorVersion++;
content = "The quick brown fox jumps over the lazy dog " + cnt;
documentResp = updateTextFile(docId, content, null);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion + "." + minorVersion, documentResp.getProperties().get("cm:versionLabel"));
// Remove versionable aspect
List<String> aspectNames = documentResp.getAspectNames();
aspectNames.remove("cm:versionable");
Document dUpdate = new Document();
dUpdate.setAspectNames(aspectNames);
response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
// no properties (ie. no "cm:versionLabel")
assertNull(documentResp.getProperties());
// Updates - no versions
for (int i = 1; i <= 3; i++) {
cnt++;
// Update the empty node's content - no version created
content = "The quick brown fox jumps over the lazy dog " + cnt;
documentResp = updateTextFile(docId, content, null);
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
// no properties (ie. no "cm:versionLabel")
assertNull(documentResp.getProperties());
}
// TODO add tests to also check version comment (when we can list version history)
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeVersionsApiTest method testUploadFileVersionAsMinor.
/**
* Test uploading a new file which starts with a minor version (0.1).
*
* @throws Exception
*/
@Test
public void testUploadFileVersionAsMinor() throws Exception {
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try {
int verCnt = 1;
int cnt = 1;
String versionLabel = "0.1";
String textContentSuffix = "Amazingly few discotheques provide jukeboxes ";
String contentName = "content-2-" + System.currentTimeMillis();
String content = textContentSuffix + cnt;
Map<String, String> params = new HashMap<>();
params.put("majorVersion", "false");
// create a new file with a minor version (ie. 0.1)
Document documentResp = createTextFile(f1Id, contentName, content, "UTF-8", params);
String docId = documentResp.getId();
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(versionLabel, documentResp.getProperties().get("cm:versionLabel"));
// also show that we continue with minor versions
cnt = 2;
versionLabel = updateFileVersions(user1, docId, cnt, textContentSuffix, verCnt, null, versionLabel);
verCnt = verCnt + cnt;
// now create some major versions
cnt = 3;
versionLabel = updateFileVersions(user1, docId, cnt, textContentSuffix, verCnt, true, versionLabel);
verCnt = verCnt + cnt;
assertEquals("3.0", versionLabel);
assertEquals(6, verCnt);
// check version history count
HttpResponse response = getAll(getNodeVersionsUrl(docId), null, null, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(verCnt, nodes.size());
} finally {
// some cleanup
setRequestContext(user1);
deleteNode(f1Id, true, 204);
}
}
use of org.alfresco.rest.api.tests.client.data.Document in project alfresco-remote-api by Alfresco.
the class NodeVersionsApiTest method testUploadFileVersionUpdate.
/**
* Tests api when uploading a file and then updating with a new version
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
*
* <p>PUT:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/content}
*
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/versions}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/versions/<versionId>}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/versions/<versionId>/content}
*/
@Test
public void testUploadFileVersionUpdate() throws Exception {
// As user 1 ...
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try {
int majorVersion = 1;
int minorVersion = 0;
// Upload text file - versioning is currently auto enabled on upload (create file via multi-part/form-data)
int verCnt = 1;
String textContentSuffix = "The quick brown fox jumps over the lazy dog ";
String contentName = "content " + System.currentTimeMillis();
String content = textContentSuffix + verCnt;
Document documentResp = createTextFile(myFolderNodeId, contentName, content, "UTF-8", null);
String d1Id = documentResp.getId();
String versionId = majorVersion + "." + minorVersion;
HttpResponse response = getSingle(URL_NODES, d1Id, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertTrue(nodeResp.getAspectNames().contains("cm:versionable"));
assertEquals(versionId, nodeResp.getProperties().get("cm:versionLabel"));
assertEquals("MAJOR", nodeResp.getProperties().get("cm:versionType"));
Paging paging = getPaging(0, 100);
Map<String, String> params = new HashMap<>();
params.put("include", "properties");
response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(verCnt, nodes.size());
assertEquals(versionId, nodes.get(0).getProperties().get("cm:versionLabel"));
assertEquals("MAJOR", nodes.get(0).getProperties().get("cm:versionType"));
// get version info
response = getSingle(getNodeVersionsUrl(d1Id), versionId, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(versionId, node.getProperties().get("cm:versionLabel"));
assertEquals("MAJOR", node.getProperties().get("cm:versionType"));
// Update the content
int updateCnt = 3;
for (int i = 1; i <= updateCnt; i++) {
verCnt++;
minorVersion++;
// Update
content = textContentSuffix + verCnt;
ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
PublicApiHttpClient.BinaryPayload payload = new PublicApiHttpClient.BinaryPayload(txtFile);
putBinary(getNodeContentUrl(d1Id), payload, null, null, 200);
versionId = majorVersion + "." + minorVersion;
// get live node
response = getSingle(URL_NODES, d1Id, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertTrue(nodeResp.getAspectNames().contains("cm:versionable"));
assertEquals(versionId, nodeResp.getProperties().get("cm:versionLabel"));
assertEquals("MINOR", nodeResp.getProperties().get("cm:versionType"));
// get version node info
response = getSingle(getNodeVersionsUrl(d1Id), versionId, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(versionId, node.getProperties().get("cm:versionLabel"));
assertEquals("MINOR", node.getProperties().get("cm:versionType"));
// check version history count
response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(verCnt, nodes.size());
}
int totalVerCnt = verCnt;
// check total version count - also get properties so that we can check version label etc
params = new HashMap<>();
params.put("include", "properties");
response = getAll(getNodeVersionsUrl(d1Id), paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(totalVerCnt, nodes.size());
checkVersionHistoryAndContent(d1Id, nodes, verCnt, textContentSuffix, null, majorVersion, minorVersion, false);
// delete to trashcan/archive ...
deleteNode(d1Id);
{
// -ve tests
getSingle(NodesEntityResource.class, d1Id, null, 404);
getAll(getNodeVersionsUrl(d1Id), null, null, 404);
}
// ... and then restore again
post(URL_DELETED_NODES + "/" + d1Id + "/restore", null, null, 200);
response = getAll(getNodeVersionsUrl(d1Id), paging, null, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(totalVerCnt, nodes.size());
{
setRequestContext(null);
// -ve test - unauthenticated - belts-and-braces ;-)
getAll(getNodeVersionsUrl(d1Id), paging, null, 401);
setRequestContext(user1);
// -ve test - unknown nodeId
getAll(getNodeVersionsUrl("dummy"), paging, null, 404);
}
} finally {
// some cleanup
setRequestContext(user1);
deleteNode(f1Id, true, 204);
}
}
Aggregations