use of org.nuxeo.drive.fixtures.SimpleFileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class TestGetChangeSummaryMultiRepo method testGetDocumentChangesSummary.
@Test
public void testGetDocumentChangesSummary() throws Exception {
// Register 3 sync roots and create 3 documents: 2 in the 'test'
// repository, 1 in the 'other' repository
DocumentModel doc1;
DocumentModel doc2;
DocumentModel doc3;
Principal administrator = session.getPrincipal();
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder2, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder3, otherSession);
doc1 = session.createDocumentModel("/folder1", "doc1", "File");
doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
doc1 = session.createDocument(doc1);
doc2 = session.createDocumentModel("/folder2", "doc2", "File");
doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
doc2 = session.createDocument(doc2);
doc3 = otherSession.createDocumentModel("/folder3", "doc3", "File");
doc3.setPropertyValue("file:content", new StringBlob("The content of file 3."));
doc3 = otherSession.createDocument(doc3);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// Look in all repositories => should find 3 changes
FileSystemChangeSummary changeSummary = getChangeSummary();
List<FileSystemItemChange> docChanges = changeSummary.getFileSystemChanges();
assertEquals(3, docChanges.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc3.getId(), "documentChanged", "other"));
Set<SimpleFileSystemItemChange> changes = new HashSet<>();
docChanges.forEach(docChange -> {
changes.add(new SimpleFileSystemItemChange(docChange.getDocUuid(), docChange.getEventId(), docChange.getRepositoryId()));
assertNotNull(docChange.getFileSystemItem());
});
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, changes));
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Update documents
doc1.setPropertyValue("dc:description", "Added description to doc1.");
doc2.setPropertyValue("dc:description", "Added description to doc1.");
doc3.setPropertyValue("dc:description", "Added description to doc1.");
session.saveDocument(doc1);
session.saveDocument(doc2);
otherSession.saveDocument(doc3);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
changeSummary = getChangeSummary();
docChanges = changeSummary.getFileSystemChanges();
assertEquals(3, docChanges.size());
}
use of org.nuxeo.drive.fixtures.SimpleFileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class TestGetChangeSummary method testGetChangesSummary.
@Test
public void testGetChangesSummary() throws Exception {
// No sync roots => shouldn't find any changes
FileSystemChangeSummary changeSummary = getChangeSummary();
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Register sync roots and create 2 documents and 1 folder => should find 3 changes
DocumentModel doc1;
DocumentModel doc2;
DocumentModel folder3;
try {
Principal administrator = session.getPrincipal();
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder2, session);
doc1 = session.createDocumentModel("/folder1", "doc1", "File");
doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
doc1 = session.createDocument(doc1);
doc2 = session.createDocumentModel("/folder2", "doc2", "File");
doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
doc2 = session.createDocument(doc2);
folder3 = session.createDocumentModel("/folder2", "folder3", "Folder");
folder3 = session.createDocument(folder3);
session.save();
} finally {
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
}
changeSummary = getChangeSummary();
List<FileSystemItemChange> docChanges = changeSummary.getFileSystemChanges();
assertEquals(3, docChanges.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder3.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentChanged", "test"));
Set<SimpleFileSystemItemChange> changes = new HashSet<>();
docChanges.forEach(docChange -> {
changes.add(new SimpleFileSystemItemChange(docChange.getDocUuid(), docChange.getEventId(), docChange.getRepositoryId()));
assertNotNull(docChange.getFileSystemItem());
});
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, changes));
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
}
Aggregations