Search in sources :

Example 21 with TreeConnection

use of org.alfresco.jlan.server.filesys.TreeConnection in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testDeleteFile.

/**
 * Unit test of delete file
 */
public void testDeleteFile() throws Exception {
    logger.debug("testDeleteFile");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Step 1 : Create a new file in read/write mode and add some content.
     */
    int openAction = FileAction.CreateNotExist;
    String FILE_PATH = "\\testDeleteFile.new";
    FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    final NetworkFile file = driver.createFile(testSession, testConnection, params);
    assertNotNull("file is null", file);
    assertFalse("file is read only, should be read-write", file.isReadOnly());
    RetryingTransactionCallback<Void> writeStuffCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            byte[] stuff = "Hello World".getBytes();
            file.writeFile(stuff, stuff.length, 0, 0);
            // needed to actually flush content to node
            file.close();
            return null;
        }
    };
    tran.doInTransaction(writeStuffCB);
    /**
     * Step 1: Delete file by path
     */
    driver.deleteFile(testSession, testConnection, FILE_PATH);
    /**
     * Step 2: Negative test - Delete file again
     */
    try {
        driver.deleteFile(testSession, testConnection, FILE_PATH);
        fail("delete a non existent file");
    } catch (IOException fe) {
    // expect to go here
    }
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) IOException(java.io.IOException) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 22 with TreeConnection

use of org.alfresco.jlan.server.filesys.TreeConnection in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testScenarioMSWord2003SaveShuffleWithBackup.

// testScenarioMSWord2003SaveShuffle
/**
 * This test tries to simulate the shuffling that is done by MS Word 2003
 * with backup enabled upon file save
 *
 * a) TEST.DOC
 * b) Save to ~WRDnnnn.TMP
 * c) Delete "Backup of TEST.DOC"
 * d) Rename TEST.DOC to "Backup of TEST.DOC"
 * e) Delete TEST.DOC
 * f) Rename ~WRDnnnn.TMP to TEST.DOC
 *
 * We need to check that properties, aspects, primary assocs, secondary assocs, peer assocs, node type,
 * version history, creation date are maintained.
 */
public void testScenarioMSWord2003SaveShuffleWithBackup() throws Exception {
    logger.debug("testScenarioMSWord2003SaveShuffleWithBackup");
    final String FILE_NAME = "TEST.DOC";
    final String FILE_OLD_TEMP = "Backup of TEST.DOC";
    final String FILE_NEW_TEMP = "~WRD0002.TMP";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile newFileHandle;

        // node ref of test.doc
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord2003SaveShuffleWithBackup";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            // now load up the node with lots of other stuff that we will test to see if it gets preserved during the
            // shuffle.
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            // test non CM namespace property
            nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
            // test CM property not related to an aspect
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_ADDRESSEE, "Fred");
            nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_CREATED);
            // classifiable chosen since its not related to any properties.
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_CLASSIFIABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * Write some content to the test file
     */
    RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            String testContent = "MS Word 2003 shuffle test";
            byte[] testContentBytes = testContent.getBytes();
            testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.firstFileHandle.close();
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * b) Save the new file
     */
    RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.newFileHandle);
            String testContent = "MS Word 2003 shuffle test This is new content";
            byte[] testContentBytes = testContent.getBytes();
            testContext.newFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.newFileHandle.close();
            return null;
        }
    };
    tran.doInTransaction(saveNewFileCB, false, true);
    /**
     * rename the old file
     */
    RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(renameOldFileCB, false, true);
    RetryingTransactionCallback<Void> validateOldFileGoneCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            try {
                driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            } catch (IOException e) {
            // expect to go here since previous step renamed the file.
            }
            return null;
        }
    };
    tran.doInTransaction(validateOldFileGoneCB, false, true);
    /**
     * Move the new file into place, stuff should get shuffled
     */
    RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(moveNewFileCB, false, true);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
            assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
            // assertEquals("noderef changed", testContext.testNodeRef, shuffledNodeRef);
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 23 with TreeConnection

use of org.alfresco.jlan.server.filesys.TreeConnection in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testScenarioFrameMakerShuffle.

// OpenCloseVersionableFile
/**
 * Frame maker save
 * a) Lock File Created    (X.fm.lck)
 * b) Create new file (X.fm.C29)
 * c) Existing file rename out of the way.   (X.backup.fm)
 * d) New file rename into place. (X.fm.C29)
 * e) Old file deleted (open with delete on close)
 * f) Lock file deleted (open with delete on close)
 */
public void testScenarioFrameMakerShuffle() throws Exception {
    logger.debug("testScenarioFramemakerShuffle");
    final String LOCK_FILE = "X.fm.lck";
    final String FILE_NAME = "X.fm";
    final String FILE_OLD_TEMP = "X.backup.fm";
    final String FILE_NEW_TEMP = "X.fm.C29";
    class TestContext {

        NetworkFile firstFileHandle;

        String mimetype;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioFramemakerShuffle";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("a) create new file");
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            /**
             * Create the file we are going to test
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            ClassPathResource fileResource = new ClassPathResource("filesys/X1.fm");
            assertNotNull("unable to find test resource filesys/X1.fm", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * b) Save the new file
     * Write X2.fm to the test file,
     */
    logger.debug("b) move new file into place");
    RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/X2.fm");
            assertNotNull("unable to find test resource filesys/X2.fm", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(file1NodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertNotNull("data is null", data);
            assertEquals("size is wrong", 166912, data.getSize());
            testContext.mimetype = data.getMimetype();
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * c) rename the old file
     */
    logger.debug("c) rename old file");
    RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(renameOldFileCB, false, true);
    /**
     * d) Move the new file into place, stuff should get shuffled
     */
    logger.debug("d) move new file into place");
    RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(moveNewFileCB, false, true);
    /**
     * d) Delete the old file
     */
    logger.debug("d) move new file into place");
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(deleteOldFileCB, false, true);
    logger.debug("e) validate results");
    /**
     * Now validate everything is correct
     */
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertNotNull("data is null", data);
            assertEquals("size is wrong", 123904, data.getSize());
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            assertTrue("file has lost versionable aspect", nodeService.hasAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("mimeType is wrong", testContext.mimetype, data.getMimetype());
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, true);
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 24 with TreeConnection

use of org.alfresco.jlan.server.filesys.TreeConnection in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testSetFileInfo.

/**
 * Test Set Info
 *
 * Three flags set
 * <ol>
 * <li>SetDeleteOnClose</li>
 * <li>SetCreationDate</li>
 * <li>SetModifyDate</li>
 * </ol>
 */
public void testSetFileInfo() throws Exception {
    logger.debug("testSetFileInfo");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    Date now = new Date();
    // CREATE 6 hours ago
    final Date CREATED = new Date(now.getTime() - 1000 * 60 * 60 * 6);
    // Modify one hour ago
    final Date MODIFIED = new Date(now.getTime() - 1000 * 60 * 60 * 1);
    class TestContext {

        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    /**
     * Step 1 : Create a new file in read/write mode and add some content.
     * Call SetInfo to set the creation date
     */
    int openAction = FileAction.CreateNotExist;
    final String FILE_NAME = "testSetFileInfo.txt";
    final String FILE_PATH = "\\" + FILE_NAME;
    // Clean up junk if it exists
    try {
        driver.deleteFile(testSession, testConnection, FILE_PATH);
    } catch (IOException ie) {
    // expect to go here
    }
    final FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    final NetworkFile file = driver.createFile(testSession, testConnection, params);
    assertNotNull("file is null", file);
    assertFalse("file is read only, should be read-write", file.isReadOnly());
    RetryingTransactionCallback<Void> writeStuffCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            byte[] stuff = "Hello World".getBytes();
            driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
            driver.closeFile(testSession, testConnection, file);
            FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
            info.setFileInformationFlags(FileInfo.SetModifyDate);
            info.setModifyDateTime(MODIFIED.getTime());
            driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
            return null;
        }
    };
    tran.doInTransaction(writeStuffCB);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
            testContext.testNodeRef = newNode;
            assertNotNull("can't find new node", newNode);
            Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
            assertNotNull("content is null", content);
            Date modified = (Date) nodeService.getProperty(newNode, ContentModel.PROP_MODIFIED);
            assertEquals("modified time not set correctly", MODIFIED, modified);
            return null;
        }
    };
    tran.doInTransaction(validateCB);
    /**
     * Step 2: Change the created date
     */
    logger.debug("Step 2: Change the created date");
    RetryingTransactionCallback<Void> changeCreatedCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
            info.setFileInformationFlags(FileInfo.SetCreationDate);
            info.setCreationDateTime(CREATED.getTime());
            driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
            return null;
        }
    };
    tran.doInTransaction(changeCreatedCB);
    RetryingTransactionCallback<Void> validateCreatedCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
            testContext.testNodeRef = newNode;
            assertNotNull("can't find new node", newNode);
            Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
            assertNotNull("content is null", content);
            Date created = (Date) nodeService.getProperty(newNode, ContentModel.PROP_CREATED);
            assertEquals("created time not set correctly", CREATED, created);
            return null;
        }
    };
    tran.doInTransaction(validateCreatedCB);
    /**
     * Step 3: Test
     */
    logger.debug("Step 3: test deleteOnClose");
    RetryingTransactionCallback<Void> deleteOnCloseCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NetworkFile f2 = driver.openFile(testSession, testConnection, params);
            FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
            info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
            driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
            file.setDeleteOnClose(true);
            byte[] stuff = "Update".getBytes();
            driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
            driver.closeFile(testSession, testConnection, file);
            return null;
        }
    };
    tran.doInTransaction(deleteOnCloseCB);
    RetryingTransactionCallback<Void> validateDeleteOnCloseCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
            assertNull("can still find new node", newNode);
            return null;
        }
    };
    tran.doInTransaction(validateDeleteOnCloseCB);
// clean up so we could run the test again
// driver.deleteFile(testSession, testConnection, FILE_PATH);
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) IOException(java.io.IOException) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 25 with TreeConnection

use of org.alfresco.jlan.server.filesys.TreeConnection in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testDirListing.

// testScenarioMetadataExtractionForMac
public void testDirListing() throws Exception {
    logger.debug("testDirListing");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    final String FOLDER_NAME = "parentFolder" + System.currentTimeMillis();
    final String HIDDEN_FOLDER_NAME = "hiddenFolder" + System.currentTimeMillis();
    RetryingTransactionCallback<NodeRef> createNodesCB = new RetryingTransactionCallback<NodeRef>() {

        @Override
        public NodeRef execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef parentNode = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, FOLDER_NAME), ContentModel.TYPE_FOLDER).getChildRef();
            nodeService.setProperty(parentNode, ContentModel.PROP_NAME, FOLDER_NAME);
            NodeRef hiddenNode = nodeService.createNode(parentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, HIDDEN_FOLDER_NAME), ForumModel.TYPE_FORUM).getChildRef();
            nodeService.setProperty(hiddenNode, ContentModel.PROP_NAME, HIDDEN_FOLDER_NAME);
            return parentNode;
        }
    };
    final NodeRef parentFolder = tran.doInTransaction(createNodesCB);
    List<String> excludedTypes = new ArrayList<String>();
    excludedTypes.add(ForumModel.TYPE_FORUM.toString());
    cifsHelper.setExcludedTypes(excludedTypes);
    SearchContext result = driver.startSearch(testSession, testConnection, "\\" + FOLDER_NAME + "\\*", 0);
    while (result.hasMoreFiles()) {
        if (result.nextFileName().equals(HIDDEN_FOLDER_NAME)) {
            fail("Exluded types mustn't be shown in cifs");
        }
    }
    RetryingTransactionCallback<Void> deleteNodeCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            nodeService.deleteNode(parentFolder);
            return null;
        }
    };
    tran.doInTransaction(deleteNodeCB, false, true);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) ArrayList(java.util.ArrayList) SearchContext(org.alfresco.jlan.server.filesys.SearchContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Aggregations

SrvSession (org.alfresco.jlan.server.SrvSession)47 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)47 DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)47 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)47 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)46 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)45 NodeRef (org.alfresco.service.cmr.repository.NodeRef)45 FileOpenParams (org.alfresco.jlan.server.filesys.FileOpenParams)44 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)44 IOException (java.io.IOException)31 Serializable (java.io.Serializable)31 QName (org.alfresco.service.namespace.QName)26 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)25 FileNotFoundException (java.io.FileNotFoundException)24 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)24 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)24 PermissionDeniedException (org.alfresco.jlan.server.filesys.PermissionDeniedException)24 ContentData (org.alfresco.service.cmr.repository.ContentData)14 ClassPathResource (org.springframework.core.io.ClassPathResource)12 InputStream (java.io.InputStream)7