Search in sources :

Example 1 with SimpleFileSystemItemChange

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());
}
Also used : FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Principal(java.security.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with SimpleFileSystemItemChange

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());
}
Also used : FileSystemChangeSummary(org.nuxeo.drive.service.FileSystemChangeSummary) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) FileSystemItemChange(org.nuxeo.drive.service.FileSystemItemChange) SimpleFileSystemItemChange(org.nuxeo.drive.fixtures.SimpleFileSystemItemChange) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Principal(java.security.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 SimpleFileSystemItemChange (org.nuxeo.drive.fixtures.SimpleFileSystemItemChange)2 FileSystemChangeSummary (org.nuxeo.drive.service.FileSystemChangeSummary)2 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)2 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2