use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFolderishCollection2.
/**
* <pre>
* /folder1 -> synchronization root && isMemberOf(collectionFolder)
* |-- collectionFolder
* /collectionSyncRoot -> synchronization root
* /testDoc -> isMemberOf(collectionFolder, collectionSyncRoot)
* </pre>
*/
@Test
public void testFolderishCollection2() throws Exception {
DocumentModel collectionFolder;
DocumentModel collectionSyncRoot;
DocumentModel testDoc;
List<FileSystemItemChange> changes;
try {
log.trace("testFolderishCollection2():" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside a folder (\"folder1\");" + "\nAdd \"folder1\" to the \"collectionFolder\" collection;" + "\nRegister \"folder1\" as a synchronization root;" + "\nCreate a collection \"collectionSyncRoot\" and register it as a synchronization root;" + "\nCreate a document \"testDoc\" and add it to both collections \"collectionFolder\" and \"collectionSyncRoot\".\n");
collectionFolder = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
collectionFolder = session.createDocument(collectionFolder);
collectionManager.addToCollection(collectionFolder, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
collectionSyncRoot = collectionManager.createCollection(session, "collectionSyncRoot", null, "/");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot, session);
testDoc = session.createDocumentModel("/", "testDoc", "File");
testDoc.setPropertyValue("file:content", new StringBlob("The content of testDoc."));
testDoc = session.createDocument(testDoc);
collectionManager.addToCollection(collectionFolder, testDoc, session);
collectionManager.addToCollection(collectionSyncRoot, testDoc, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 12 (among which 10 distinct) changes:
// - addedToCollection for testDoc
// - documentModified for collectionSyncRoot
// - addedToCollection for testDoc
// - documentModified for collectionFolder
// - documentCreated for testDoc
// - rootRegistered for collectionSyncRoot
// - documentCreated for collectionSyncRoot
// - rootRegistered for folder1
// - addedToCollection for folder1
// - documentModified for collectionFolder
// - documentCreated for collectionFolder
// - documentCreated for folder1
changes = getChanges(session.getPrincipal());
assertEquals(12, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionFolder.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testSyncUnsyncRootsAsAnotherUser.
@Test
public void testSyncUnsyncRootsAsAnotherUser() throws Exception {
Principal user1Principal = user1Session.getPrincipal();
List<FileSystemItemChange> changes;
try {
// No sync roots expected for user1
changes = getChanges(user1Principal);
assertNotNull(changes);
assertTrue(changes.isEmpty());
// Register sync roots for user1 as Administrator
nuxeoDriveManager.registerSynchronizationRoot(user1Principal, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(user1Principal, folder2, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// user1 should have 2 sync roots
Set<IdRef> activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(user1Session);
assertNotNull(activeRootRefs);
assertEquals(2, activeRootRefs.size());
assertTrue(activeRootRefs.contains(folder1.getRef()));
assertTrue(activeRootRefs.contains(folder2.getRef()));
// There should be 2 changes detected in the audit
changes = getChanges(user1Principal);
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder2.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder2.getId(), "folder2"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId(), "folder1"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
for (FileSystemItemChange change : changes) {
assertNotNull(change.getFileSystemItem());
}
// Unregister sync roots for user1 as Administrator
nuxeoDriveManager.unregisterSynchronizationRoot(user1Principal, folder1, session);
nuxeoDriveManager.unregisterSynchronizationRoot(user1Principal, folder2, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// user1 should have no sync roots
Set<IdRef> activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(user1Session);
assertNotNull(activeRootRefs);
assertTrue(activeRootRefs.isEmpty());
// There should be 2 changes detected in the audit
changes = getChanges(user1Principal);
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder2.getId(), "deleted", "test", "test#" + folder2.getId(), "folder2"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "deleted", "test", "test#" + folder1.getId(), "folder1"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Not adaptable as a FileSystemItem since unregistered
for (FileSystemItemChange change : changes) {
assertNull(change.getFileSystemItem());
}
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFindSecurityChanges.
@Test
public void testFindSecurityChanges() throws Exception {
List<FileSystemItemChange> changes;
DocumentModel subFolder;
try {
// No sync roots
changes = getChanges();
assertTrue(changes.isEmpty());
// Create a folder in a sync root
subFolder = user1Session.createDocumentModel("/folder1", "subFolder", "Folder");
subFolder = user1Session.createDocument(subFolder);
// Sync roots for user1
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder1, user1Session);
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder2, user1Session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Get changes for user1
changes = getChanges(user1Session.getPrincipal());
// Folder creation and sync root registration events
assertEquals(3, changes.size());
// Permission changes: deny Read
// Deny Read to user1 on a regular doc
setPermissions(subFolder, new ACE(SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING), ACE.BLOCK);
// Deny Read to user1 on a sync root
setPermissions(folder2, new ACE(SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING), ACE.BLOCK);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changes = getChanges(user1Session.getPrincipal());
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder2.getId(), "securityUpdated", "test", "test#" + folder2.getId(), "folder2"));
expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "test#" + subFolder.getId(), "subFolder"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Changed documents are not adaptable as a FileSystemItem since no Read permission
for (FileSystemItemChange change : changes) {
assertNull(change.getFileSystemItem());
}
// Permission changes: grant Read
// Grant Read to user1 on a regular doc
setPermissions(subFolder, new ACE("user1", SecurityConstants.READ));
// Grant Read to user1 on a sync root
setPermissions(folder2, new ACE("user1", SecurityConstants.READ));
} finally {
commitAndWaitForAsyncCompletion();
}
changes = getChanges(user1Session.getPrincipal());
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder2.getId(), "securityUpdated", "test", "defaultSyncRootFolderItemFactory#test#" + folder2.getId(), "folder2"));
expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "securityUpdated", "test", "defaultFileSystemItemFactory#test#" + subFolder.getId(), "subFolder"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Changed documents are adaptable as a FileSystemItem since Read permission
for (FileSystemItemChange change : changes) {
assertNotNull(change.getFileSystemItem());
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFolderishCollection1.
/**
* <pre>
* /folder1 -> isMemberOf(collectionFolder2)
* |-- collectionFolder1
* |-- collectionFolder2
* /collectionSyncRoot -> synchronization root
* /testDoc -> isMemberOf(collectionFolder1, collectionSyncRoot)
* </pre>
*/
@Test
public void testFolderishCollection1() throws Exception {
DocumentModel collectionSyncRoot;
DocumentModel testDoc;
List<FileSystemItemChange> changes;
try {
log.trace("testFolderishCollection1():" + "\nCreate a folder with the Collection facet (\"collectionFolder1\") inside a folder (\"folder1\");" + "\nCreate a folder with the Collection facet (\"collectionFolder2\") inside a folder (\"folder1\");" + "\nAdd \"folder1\" to the \"collectionFolder2\" collection;" + "\nCreate a collection \"collectionSyncRoot\" and register it as a synchronization root;" + "\nCreate a document \"testDoc\" and add it to both collections \"collectionFolder1\" and \"collectionSyncRoot\".\n");
DocumentModel collectionFolder1 = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
collectionFolder1 = session.createDocument(collectionFolder1);
DocumentModel collectionFolder2 = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
collectionFolder2 = session.createDocument(collectionFolder2);
collectionManager.addToCollection(collectionFolder2, folder1, session);
collectionSyncRoot = collectionManager.createCollection(session, "collectionSyncRoot", null, "/");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot, session);
testDoc = session.createDocumentModel("/", "testDoc", "File");
testDoc.setPropertyValue("file:content", new StringBlob("The content of testDoc."));
testDoc = session.createDocument(testDoc);
collectionManager.addToCollection(collectionFolder1, testDoc, session);
collectionManager.addToCollection(collectionSyncRoot, testDoc, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 6 (among which 5 distinct) changes:
// - addedToCollection for testDoc
// - documentModified for collectionSyncRoot
// - addedToCollection for testDoc
// - documentCreated for testDoc
// - rootRegistered for collectionSyncRoot
// - documentCreated for collectionSyncRoot
changes = getChanges(session.getPrincipal());
assertEquals(6, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testRegisterParentSyncRoot.
@Test
public void testRegisterParentSyncRoot() throws Exception {
DocumentModel subFolder;
List<FileSystemItemChange> changes;
try {
// Create a subfolder in folder1
subFolder = session.createDocument(session.createDocumentModel(folder1.getPathAsString(), "subFolder", "Folder"));
// Register subfolder as a sync root
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), subFolder, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 2:
// - rootRegistered for subfolder
// - documentCreated for subFolder
changes = getChanges(session.getPrincipal());
assertEquals(2, changes.size());
// Register folder1 as a sync root
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 2:
// - rootRegistered for folder1
// - deleted for subFolder
changes = getChanges(session.getPrincipal());
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId(), "folder1"));
expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "deleted", "test", "test#" + subFolder.getId(), "subFolder"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
Aggregations