Search in sources :

Example 1 with VirtualProtocol

use of org.alfresco.repo.virtual.ref.VirtualProtocol in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtensionTest method testCreateNode.

@Test
public void testCreateNode() throws Exception {
    assertTrue(smartStore.canVirtualize(virtualFolder1NodeRef));
    Reference semiVirtualFolder = smartStore.virtualize(virtualFolder1NodeRef);
    assertNotNull(semiVirtualFolder);
    assertTrue(semiVirtualFolder.getProtocol() instanceof VirtualProtocol);
    Reference firstChild = smartStore.getChildByName(semiVirtualFolder, ContentModel.ASSOC_CONTAINS, "Node1");
    assertNotNull(firstChild);
    Reference secondChild = smartStore.getChildByName(semiVirtualFolder, ContentModel.ASSOC_CONTAINS, "Node2");
    assertNotNull(secondChild);
    authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    // add testfile.txt to first virtual child
    String fileName = "testfile.txt";
    uploadNode(firstChild, fileName);
    assertNotNull(nodeService.getChildByName(firstChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile.txt"));
    uploadNode(firstChild, fileName);
    assertNotNull(nodeService.getChildByName(firstChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile-1.txt"));
    // add testfile.txt to second virtual child
    uploadNode(secondChild, fileName);
    assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile-2.txt"));
    uploadNode(secondChild, fileName);
    assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile-3.txt"));
    // add again to first virtual child starting from the last index found
    // (this is the index that comes from
    // upload-post.js)
    fileName = "testfile-2.txt";
    uploadNode(firstChild, fileName);
    assertNotNull(nodeService.getChildByName(firstChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile-4.txt"));
    // test create node for actual node starting from the last index found
    // (this is the index that comes from
    // upload-post.js)
    fileName = "testfile-5.txt";
    fileAndFolderService.create(virtualFolder1NodeRef, fileName, ContentModel.TYPE_CONTENT);
    assertNotNull(nodeService.getChildByName(virtualFolder1NodeRef, ContentModel.ASSOC_CONTAINS, "testfile-5.txt"));
    fileName = "testfile-6.txt";
    fileAndFolderService.create(virtualFolder1NodeRef, fileName, ContentModel.TYPE_CONTENT);
    assertNotNull(nodeService.getChildByName(virtualFolder1NodeRef, ContentModel.ASSOC_CONTAINS, "testfile-6.txt"));
    // add again to second child starting from the last index found (this is
    // the index that comes from
    // upload-post.js)
    fileName = "testfile-4.txt";
    uploadNode(secondChild, fileName);
    assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile-7.txt"));
    // test situation when file name is of form testfile1-1.txt
    fileName = "testfile1-1.txt";
    fileAndFolderService.create(secondChild.toNodeRef(), fileName, ContentModel.TYPE_CONTENT);
    assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile1-1.txt"));
    fileAndFolderService.create(secondChild.toNodeRef(), fileName, ContentModel.TYPE_CONTENT);
    assertNotNull(nodeService.getChildByName(secondChild.toNodeRef(), ContentModel.ASSOC_CONTAINS, "testfile1-1-1.txt"));
}
Also used : VirtualProtocol(org.alfresco.repo.virtual.ref.VirtualProtocol) Reference(org.alfresco.repo.virtual.ref.Reference) Test(org.junit.Test) VirtualizationIntegrationTest(org.alfresco.repo.virtual.VirtualizationIntegrationTest)

Aggregations

VirtualizationIntegrationTest (org.alfresco.repo.virtual.VirtualizationIntegrationTest)1 Reference (org.alfresco.repo.virtual.ref.Reference)1 VirtualProtocol (org.alfresco.repo.virtual.ref.VirtualProtocol)1 Test (org.junit.Test)1