use of org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory in project nuxeo-drive-server by nuxeo.
the class TestDefaultTopLevelFolderItemFactory method createTestDocs.
@Before
public void createTestDocs() throws Exception {
// Create and register 2 synchronization roots for Administrator
syncRoot1 = session.createDocument(session.createDocumentModel("/", "syncRoot1", "Folder"));
syncRoot2 = session.createDocument(session.createDocumentModel("/", "syncRoot2", "Folder"));
Principal administrator = session.getPrincipal();
nuxeoDriveManager.registerSynchronizationRoot(administrator, syncRoot1, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, syncRoot2, session);
// Add a child file to syncRoot1
DocumentModel syncRoot1Child = session.createDocumentModel("/syncRoot1", "syncRoot1Child", "File");
Blob blob = new StringBlob("Content of Joe's file.");
blob.setFilename("Joe.odt");
syncRoot1Child.setPropertyValue("file:content", (Serializable) blob);
syncRoot1Child = session.createDocument(syncRoot1Child);
// Flush the session so that the other session instances from the
// FileSystemManager service.
session.save();
// Get default top level folder item factory
defaultTopLevelFolderItemFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
assertTrue(defaultTopLevelFolderItemFactory instanceof DefaultTopLevelFolderItemFactory);
assertEquals("Nuxeo Drive", defaultTopLevelFolderItemFactory.getFolderName());
}
use of org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemAdapterService method testService.
@Test
public void testService() throws Exception {
registerRootAndCreateSomeDocs();
// ------------------------------------------------------
// Check file system item factory descriptors
// ------------------------------------------------------
Map<String, FileSystemItemFactoryDescriptor> fileSystemItemFactoryDescs = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactoryDescriptors();
assertNotNull(fileSystemItemFactoryDescs);
assertEquals(12, fileSystemItemFactoryDescs.size());
FileSystemItemFactoryDescriptor desc = fileSystemItemFactoryDescs.get("defaultSyncRootFolderItemFactory");
assertNotNull(desc);
assertEquals(10, desc.getOrder());
assertEquals("defaultSyncRootFolderItemFactory", desc.getName());
assertNull(desc.getDocType());
assertEquals("DriveSynchronized", desc.getFacet());
FileSystemItemFactory factory = desc.getFactory();
assertTrue(factory instanceof DefaultSyncRootFolderItemFactory);
desc = fileSystemItemFactoryDescs.get("dummyDocTypeFactory");
assertNotNull(desc);
assertEquals(20, desc.getOrder());
assertEquals("dummyDocTypeFactory", desc.getName());
assertEquals("File", desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DummyFileItemFactory);
desc = fileSystemItemFactoryDescs.get("dummyFacetFactory");
assertNotNull(desc);
assertEquals(30, desc.getOrder());
assertEquals("dummyFacetFactory", desc.getName());
assertNull(desc.getDocType());
assertEquals("Folderish", desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DummyFolderItemFactory);
desc = fileSystemItemFactoryDescs.get("defaultFileSystemItemFactory");
assertNotNull(desc);
assertEquals(50, desc.getOrder());
assertEquals("defaultFileSystemItemFactory", desc.getName());
assertNull(desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DefaultFileSystemItemFactory);
desc = fileSystemItemFactoryDescs.get("dummyVirtualFolderItemFactory");
assertNotNull(desc);
assertEquals(100, desc.getOrder());
assertEquals("dummyVirtualFolderItemFactory", desc.getName());
assertNull(desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof VirtualFolderItemFactory);
assertEquals("Dummy Folder", ((VirtualFolderItemFactory) factory).getFolderName());
desc = fileSystemItemFactoryDescs.get("nullMergeTestFactory");
assertNotNull(desc);
assertEquals(200, desc.getOrder());
assertEquals("nullMergeTestFactory", desc.getName());
assertEquals("Note", desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DummyFileItemFactory);
// ------------------------------------------------------
// Check ordered file system item factories
// ------------------------------------------------------
List<FileSystemItemFactoryWrapper> fileSystemItemFactories = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactories();
assertNotNull(fileSystemItemFactories);
assertEquals(7, fileSystemItemFactories.size());
FileSystemItemFactoryWrapper factoryWrapper = fileSystemItemFactories.get(0);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertEquals("Collection", factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("CollectionSyncRootFolderItemFactory"));
factoryWrapper = fileSystemItemFactories.get(1);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertEquals("DriveSynchronized", factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultSyncRootFolderItemFactory"));
factoryWrapper = fileSystemItemFactories.get(2);
assertNotNull(factoryWrapper);
assertEquals("File", factoryWrapper.getDocType());
assertNull(factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFileItemFactory"));
factoryWrapper = fileSystemItemFactories.get(3);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertEquals("Folderish", factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFolderItemFactory"));
factoryWrapper = fileSystemItemFactories.get(4);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertNull(factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultFileSystemItemFactory"));
factoryWrapper = fileSystemItemFactories.get(5);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertNull(factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyVirtualFolderItemFactory"));
factoryWrapper = fileSystemItemFactories.get(6);
assertNotNull(factoryWrapper);
assertEquals("Note", factoryWrapper.getDocType());
assertNull(factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFileItemFactory"));
// ------------------------------------------------------
// Check #getFileSystemItem(DocumentModel doc)
// ------------------------------------------------------
// File => should use the dummyDocTypeFactory bound to the
// DummyFileItemFactory class
FileSystemItem fsItem = fileSystemItemAdapterService.getFileSystemItem(file);
assertNotNull(fsItem);
assertTrue(fsItem instanceof DummyFileItem);
assertEquals("dummyDocTypeFactory#test#" + file.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Dummy file with id " + file.getId(), fsItem.getName());
assertFalse(fsItem.isFolder());
assertEquals("Joe", fsItem.getCreator());
assertEquals("Joe", fsItem.getLastContributor());
// Folder => should use the dummyFacetFactory bound to the
// DummyFolderItemFactory class
fsItem = fileSystemItemAdapterService.getFileSystemItem(folder);
assertNotNull(fsItem);
assertTrue(fsItem instanceof DummyFolderItem);
assertTrue(((FolderItem) fsItem).getCanCreateChild());
assertEquals("dummyFacetFactory#test#" + folder.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Dummy folder with id " + folder.getId(), fsItem.getName());
assertTrue(fsItem.isFolder());
assertEquals("Jack", fsItem.getCreator());
assertEquals("Jack", fsItem.getLastContributor());
// Custom => should use the defaultFileSystemItemFactory bound to the
// DefaultFileSystemItemFactory class
fsItem = fileSystemItemAdapterService.getFileSystemItem(custom);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FileItem);
assertEquals("defaultFileSystemItemFactory#test#" + custom.getId(), fsItem.getId());
assertEquals("/org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#/" + syncRootItemId + "/" + fsItem.getId(), fsItem.getPath());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Bonnie's file.txt", fsItem.getName());
assertFalse(fsItem.isFolder());
assertEquals("Bonnie", fsItem.getCreator());
assertEquals("Bonnie", fsItem.getLastContributor());
Blob fileFsItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Bonnie's file.txt", fileFsItemBlob.getFilename());
assertEquals("Content of the custom document's blob.", fileFsItemBlob.getString());
// -------------------------------------------------------------------
// Check #getFileSystemItem(DocumentModel doc, boolean includeDeleted,
// boolean relaxSyncRootConstraint)
// -------------------------------------------------------------------
fsItem = fileSystemItemAdapterService.getFileSystemItem(custom, false, true);
assertNotNull(fsItem);
assertEquals("test#" + custom.getId(), fsItem.getId());
// ------------------------------------------------------
// Check #getFileSystemItem(DocumentModel doc, FolderItem parentItem)
// ------------------------------------------------------
// File => should use the dummyDocTypeFactory bound to the
// DummyFileItemFactory class
fsItem = fileSystemItemAdapterService.getFileSystemItem(file, syncRootItem);
assertNotNull(fsItem);
assertEquals(syncRootItemId, fsItem.getParentId());
// -------------------------------------------------------------
// Check #getFileSystemItemFactoryForId(String id)
// -------------------------------------------------------------
// Default factory
String fsItemId = "defaultFileSystemItemFactory#test#someId";
FileSystemItemFactory fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
assertNotNull(fsItemFactory);
assertEquals("defaultFileSystemItemFactory", fsItemFactory.getName());
assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultFileSystemItemFactory"));
assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
// Top level folder item factory
fsItemId = "org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#";
fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
assertNotNull(fsItemFactory);
assertTrue(fsItemFactory.getName().endsWith("DefaultTopLevelFolderItemFactory"));
assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultTopLevelFolderItemFactory"));
assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
// Factory with #canHandleFileSystemItemId returning false
fsItemId = "dummyDocTypeFactory#test#someId";
try {
fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
fail("No fileSystemItemFactory should be found FileSystemItem id.");
} catch (NuxeoDriveContribException e) {
assertEquals("No fileSystemItemFactory found for FileSystemItem with id dummyDocTypeFactory#test#someId. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\"> and make sure there is at least one defining a FileSystemItemFactory class for which the #canHandleFileSystemItemId(String id) method returns true.", e.getMessage());
}
// Non parsable id
fsItemId = "nonParsableId";
try {
fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
fail("No fileSystemItemFactory should be found for FileSystemItem id.");
} catch (NuxeoDriveContribException e) {
assertEquals("No fileSystemItemFactory found for FileSystemItem with id nonParsableId. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\"> and make sure there is at least one defining a FileSystemItemFactory class for which the #canHandleFileSystemItemId(String id) method returns true.", e.getMessage());
}
// Non existent factory name
fsItemId = "nonExistentFactoryName#test#someId";
try {
fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
fail("No fileSystemItemFactory should be found for FileSystemItem id.");
} catch (NuxeoDriveContribException e) {
assertEquals("No fileSystemItemFactory found for FileSystemItem with id nonExistentFactoryName#test#someId. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\"> and make sure there is at least one defining a FileSystemItemFactory class for which the #canHandleFileSystemItemId(String id) method returns true.", e.getMessage());
}
// -------------------------------------------------------------
// Check #getTopLevelFolderItemFactory()
// -------------------------------------------------------------
TopLevelFolderItemFactory topLevelFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
assertNotNull(topLevelFactory);
assertTrue(topLevelFactory.getClass().getName().endsWith("DefaultTopLevelFolderItemFactory"));
assertTrue(topLevelFactory instanceof DefaultTopLevelFolderItemFactory);
// -------------------------------------------------------------
try {
fileSystemItemAdapterService.getVirtualFolderItemFactory("nonExistentFactory");
fail("No VirtualFolderItemFactory should be found for factory name.");
} catch (NuxeoDriveContribException e) {
assertEquals("No factory named nonExistentFactory. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\">.", e.getMessage());
}
try {
fileSystemItemAdapterService.getVirtualFolderItemFactory("defaultFileSystemItemFactory");
fail("No VirtualFolderItemFactory should be found for factory name.");
} catch (NuxeoDriveContribException e) {
assertEquals("Factory class org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory for factory defaultFileSystemItemFactory is not a VirtualFolderItemFactory.", e.getMessage());
}
VirtualFolderItemFactory virtualFolderItemFactory = fileSystemItemAdapterService.getVirtualFolderItemFactory("dummyVirtualFolderItemFactory");
assertNotNull(virtualFolderItemFactory);
assertTrue(virtualFolderItemFactory.getClass().getName().endsWith("DummyVirtualFolderItemFactory"));
// -------------------------------------------------------------
// Check #getActiveFileSystemItemFactories()
// -------------------------------------------------------------
Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
assertEquals(7, activeFactories.size());
assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
assertTrue(activeFactories.contains("defaultSyncRootFolderItemFactory"));
assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
assertTrue(activeFactories.contains("dummyDocTypeFactory"));
assertTrue(activeFactories.contains("dummyFacetFactory"));
assertTrue(activeFactories.contains("dummyVirtualFolderItemFactory"));
assertTrue(activeFactories.contains("nullMergeTestFactory"));
}
Aggregations