Search in sources :

Example 1 with CollectionSyncRootFolderItem

use of org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem in project nuxeo-drive-server by nuxeo.

the class TestCollectionSyncRootFolderItemFactory method testFactory.

@Test
public void testFactory() throws Exception {
    FileSystemItemFactory collectionSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("collectionSyncRootFolderItemFactory");
    DocumentModel collection = collectionManager.createCollection(session, "testCollection", "Test collection.", "/");
    DocumentModel doc1 = session.createDocumentModel("/", "doc1", "File");
    doc1.setPropertyValue("dc:title", "doc1");
    doc1.setPropertyValue("file:content", new StringBlob("Content of file 1."));
    doc1 = session.createDocument(doc1);
    collectionManager.addToCollection(collection, doc1, session);
    assertTrue(collectionManager.isInCollection(collection, doc1, session));
    DocumentModel doc2 = session.createDocumentModel("/", "doc2", "File");
    doc2.setPropertyValue("dc:title", "doc2");
    doc2.setPropertyValue("file:content", new StringBlob("Content of file 2."));
    doc2 = session.createDocument(doc2);
    collectionManager.addToCollection(collection, doc2, session);
    assertTrue(collectionManager.isInCollection(collection, doc2, session));
    log.trace("Check document that is not a Collection");
    assertFalse(collectionSyncRootFolderItemFactory.isFileSystemItem(session.getRootDocument()));
    log.trace("Check Collection not registered as a sync root");
    assertFalse(collectionSyncRootFolderItemFactory.isFileSystemItem(collection));
    log.trace("Check Collection registered as a sync root");
    nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collection, session);
    assertTrue(collectionSyncRootFolderItemFactory.isFileSystemItem(collection));
    log.trace("Adapt test collection as a FileSystemItem");
    FileSystemItem fsItem = collectionSyncRootFolderItemFactory.getFileSystemItem(collection);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof CollectionSyncRootFolderItem);
    log.trace("Check children");
    FolderItem collectionFSItem = (FolderItem) fsItem;
    List<FileSystemItem> collectionChildren = collectionFSItem.getChildren();
    assertEquals(2, collectionChildren.size());
    FileSystemItem child1 = collectionChildren.get(0);
    assertTrue(child1 instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc1.getId(), child1.getId());
    assertEquals(COLLECTION_SYNC_ROOT_ITEM_ID_PREFIX + collection.getId(), child1.getParentId());
    assertEquals("doc1", child1.getName());
    FileSystemItem child2 = collectionChildren.get(1);
    assertTrue(child2 instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc2.getId(), child2.getId());
    assertEquals(COLLECTION_SYNC_ROOT_ITEM_ID_PREFIX + collection.getId(), child2.getParentId());
    assertEquals("doc2", child2.getName());
    log.trace("Check FolderItem#getCanScrollDescendants");
    assertFalse(collectionFSItem.getCanScrollDescendants());
    log.trace("Check descendants");
    try {
        collectionFSItem.scrollDescendants(null, 10, 1000);
        fail("Should not be able to scroll through the descendants of a CollectionSyncRootFolderItem.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot scroll through the descendants of a collection sync root folder item, please call getChildren() instead.", e.getMessage());
    }
    log.trace("Check FolderItem#getCanCreateChild");
    assertFalse(collectionFSItem.getCanCreateChild());
    log.trace("Check FolderItem#createFile");
    try {
        collectionFSItem.createFile(new StringBlob("Child file content."));
        fail("Should not be able to create a file in a CollectionSyncRootFolderItem.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot create a file in a collection synchronization root.", e.getMessage());
    }
    log.trace("Check FolderItem#createFolder");
    try {
        collectionFSItem.createFolder("Child folder");
        fail("Should not be able to create a folder in a CollectionSyncRootFolderItem.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot create a folder in a collection synchronization root.", e.getMessage());
    }
    log.trace("Test AbstractDocumentBackedFileSystemItem#delete");
    child1.delete();
    doc1 = session.getDocument(doc1.getRef());
    assertFalse(doc1.isTrashed());
    assertFalse(collectionManager.isInCollection(collection, doc1, session));
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) CollectionSyncRootFolderItem(org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) CollectionSyncRootFolderItem(org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 FileItem (org.nuxeo.drive.adapter.FileItem)1 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)1 FolderItem (org.nuxeo.drive.adapter.FolderItem)1 CollectionSyncRootFolderItem (org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem)1 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)1 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)1 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)1 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)1