Search in sources :

Example 16 with DiskSharedDevice

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

the class ContentDiskDriverTest method testWindows7Explorer.

// testGedit
/**
 * Windows7 Explorer update
 * 0) Existing file mark.jpg
 * a) Create new file (~ark.tmp)
 * b) Existing file rename out of the way.   (mark.jpg~RF5bb356.TMP)
 * c) New file rename into place. (~ark.tmp - mark.jpg)
 * d) Old file opened attributes only
 * e) set delete on close
 * f) close
 */
public void testWindows7Explorer() throws Exception {
    logger.debug("testWindows7Explorer");
    final String FILE_NAME = "mark.jpg";
    final String FILE_OLD_TEMP = "mark.jpg~RF5bb356.TMP";
    final String FILE_NEW_TEMP = "~ark.tmp";
    class TestContext {

        NodeRef testNodeRef;

        NetworkFile firstFileHandle;

        NetworkFile secondFileHandle;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testWindows7Explorer";
    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("0) 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/ContentDiskDriverTestMark.jpg");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTestMark.jpg", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            testContext.testNodeRef = file1NodeRef;
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * a) Save the new file
     */
    logger.debug("a) save new file");
    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.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTestMark2.jpg");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTestMark2.jpg", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.secondFileHandle);
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * b) 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);
    /**
     * c) 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) delete on close the old file");
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams openFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_OLD_TEMP, 0, AccessMode.NTReadAttributesOnly, FileAttribute.NTNormal, 0);
            testContext.secondFileHandle = driver.openFile(testSession, testConnection, openFileParams);
            assertNotNull(testContext.secondFileHandle);
            FileInfo info = new FileInfo();
            info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
            driver.setFileInformation(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP, info);
            testContext.secondFileHandle.setDeleteOnClose(true);
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            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);
            assertTrue("file has lost versionable aspect", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("node ref has changed", shuffledNodeRef, testContext.testNodeRef);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertNotNull("data is null", data);
            assertEquals("size is wrong", 10407, data.getSize());
            assertEquals("mimeType is wrong", "image/jpeg", 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) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) ContentData(org.alfresco.service.cmr.repository.ContentData) 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 17 with DiskSharedDevice

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

the class ContentDiskDriverTest method testScenarioOpenCloseFileTwo.

// testOpenCloseFileScenario
/**
 * Test Open Close File Scenario II  ALF-13401
 * Open Read Only of a file already open for read/write.
 *
 * 1) open(readWrite)
 * 2) write some content.
 * 3) open(readOnly).
 * 4) read some content.
 * 5) close - updates the repo
 */
public void testScenarioOpenCloseFileTwo() throws Exception {
    logger.debug("start of testScenarioOpenCloseFileTwo");
    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();
    class TestContext {

        NodeRef testDirNodeRef;

        NodeRef targetNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String FILE_NAME = "testScenarioOpenFileTwo.txt";
    final String FILE_PATH = TEST_ROOT_DOS_PATH + "\\" + FILE_NAME;
    FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
    driver.createDirectory(testSession, testConnection, dirParams);
    testContext.testDirNodeRef = getNodeForPath(testConnection, TEST_ROOT_DOS_PATH);
    /**
     * 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, FILE_PATH);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    /**
     * Step 1: Now create the file through the node service and open it.
     */
    logger.debug("Step 1) Create File and Open file created by node service");
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            logger.debug("create file and close it immediatly");
            FileOpenParams createFileParams = new FileOpenParams(FILE_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            NetworkFile dummy = driver.createFile(testSession, testConnection, createFileParams);
            driver.closeFile(testSession, testConnection, dummy);
            logger.debug("after create and close");
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    testContext.targetNodeRef = getNodeForPath(testConnection, FILE_PATH);
    FileOpenParams openRO = new FileOpenParams(FILE_PATH, FileAction.CreateNotExist, AccessMode.ReadOnly, FileAttribute.NTNormal, 0);
    FileOpenParams openRW = new FileOpenParams(FILE_PATH, FileAction.CreateNotExist, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    /**
     * First open - read write
     */
    logger.debug("open file1 read only");
    NetworkFile file1 = driver.openFile(testSession, testConnection, openRW);
    assertNotNull(file1);
    final String testString = "Yankee doodle went to town, riding on a donkey.";
    byte[] stuff = testString.getBytes("UTF-8");
    driver.writeFile(testSession, testConnection, file1, stuff, 0, stuff.length, 0);
    logger.debug("open file 2 for read only");
    NetworkFile file2 = driver.openFile(testSession, testConnection, openRO);
    assertNotNull(file2);
    assertTrue("file size is 0", file2.getFileSize() > 0);
    /**
     * Write Some More Content
     */
    driver.writeFile(testSession, testConnection, file1, stuff, 0, stuff.length, 0);
    logger.debug("first close");
    driver.closeFile(testSession, testConnection, file2);
    logger.debug("second close");
    driver.closeFile(testSession, testConnection, file1);
    logger.debug("now validate");
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            Map<QName, Serializable> props = nodeService.getProperties(testContext.targetNodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertNotNull("data is null", data);
            assertEquals("data wrong length", testString.length(), data.getSize());
            ContentReader reader = contentService.getReader(testContext.targetNodeRef, ContentModel.PROP_CONTENT);
            String s = reader.getContentString();
            assertEquals("content not written", testString, s);
            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) ContentReader(org.alfresco.service.cmr.repository.ContentReader) 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) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) 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 18 with DiskSharedDevice

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

the class ContentDiskDriverTest method testGetFileInformation.

/**
 * Test Get File Information
 */
public void testGetFileInformation() throws Exception {
    logger.debug("testGetFileInformation");
    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();
    class TestContext {

        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    /**
     * Test 1 : Get the root info
     */
    FileInfo finfo = driver.getFileInformation(testSession, testConnection, "");
    assertNotNull("root info is null", finfo);
    assertEquals("root has a unexpected file name", "", finfo.getFileName());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SrvSession(org.alfresco.jlan.server.SrvSession) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 19 with DiskSharedDevice

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

the class ContentDiskDriverTest method testSetFileScenario.

// Test Word Save Locked File
/**
 * ALF-10686
 * This scenario is executed by windows explorer.
 *
 * A file is created and the file handle kept open.
 * stuff is written
 * Then the modified date is set
 * Then the file is closed.
 * @throws Exception
 */
public void testSetFileScenario() 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 = "testSetFileScenario.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);
            FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
            info.setFileInformationFlags(FileInfo.SetModifyDate);
            info.setModifyDateTime(MODIFIED.getTime());
            info.setNetworkFile(file);
            driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
            return null;
        }
    };
    tran.doInTransaction(writeStuffCB);
    RetryingTransactionCallback<Void> closeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            // This close is in a different position to the simple setFileInformation scenarios above.
            driver.closeFile(testSession, testConnection, file);
            return null;
        }
    };
    tran.doInTransaction(closeFileCB);
    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);
    // clean up so we could run the test again
    RetryingTransactionCallback<Void> deleteFile = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, FILE_PATH);
            return null;
        }
    };
    tran.doInTransaction(deleteFile, false, true);
}
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 20 with DiskSharedDevice

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

the class ContentDiskDriverTest method testMacDragAndDrop.

// testScenarioMSMacWord20011SaveWithBackup save
/**
 * Simulates a Mac Lion Drag and Drop
 * 0. ALF-15158.diff  already exists and is versionable
 * 1. Delete ALF-15158.diff
 * 2. Create new document ALF-15158.diff
 */
public void testMacDragAndDrop() throws Exception {
    logger.debug("testMacDragAndDrop()");
    final String FILE_NAME = "ALF-15158.diff";
    class TestContext {

        NetworkFile firstFileHandle;

        NodeRef file1NodeRef;
    }
    ;
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\MacDragAndDrop";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "cifs", "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 {
        logger.debug("expect to get exception - cleaning garbage");
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("0) create new file");
    RetryingTransactionCallback<TestContext> createFileCB = new RetryingTransactionCallback<TestContext>() {

        @Override
        public TestContext execute() throws Throwable {
            TestContext ctx = new TestContext();
            /**
             * 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 use (FileA.pptx)
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            ctx.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(ctx.firstFileHandle);
            driver.closeFile(testSession, testConnection, ctx.firstFileHandle);
            ctx.file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(ctx.file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return ctx;
        }
    };
    final TestContext testContext = tran.doInTransaction(createFileCB, false, true);
    /**
     * 1) delete the old file
     */
    logger.debug("1) delete old file");
    RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(renameOldFileCB, false, true);
    /**
     * 2) CreateNewFile and write some new content
     */
    logger.debug("2) write some content");
    RetryingTransactionCallback<Void> restoreFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest3.doc");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
            byte[] buffer = new byte[1000];
            InputStream is = fileResource.getInputStream();
            try {
                long offset = 0;
                int i = is.read(buffer, 0, buffer.length);
                while (i > 0) {
                    testContext.firstFileHandle.writeFile(buffer, i, 0, offset);
                    offset += i;
                    i = is.read(buffer, 0, buffer.length);
                }
            } finally {
                is.close();
            }
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            return null;
        }
    };
    tran.doInTransaction(restoreFileCB, false, true);
    logger.debug("3) 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", 26112, data.getSize());
            assertEquals("mimeType is wrong", "application/msword", data.getMimetype());
            assertTrue("versionable aspect missing", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertTrue("hidden aspect still applied", !nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_HIDDEN));
            assertTrue("temporary aspect still applied", !nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_TEMPORARY));
            assertEquals("Node ref has changed", shuffledNodeRef, testContext.file1NodeRef);
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, true);
    logger.debug("end testMacDragAndDrop");
}
Also used : Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) ContentData(org.alfresco.service.cmr.repository.ContentData) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) SrvSession(org.alfresco.jlan.server.SrvSession) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) 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) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Aggregations

DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)50 SrvSession (org.alfresco.jlan.server.SrvSession)47 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)47 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)47 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)46 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)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 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)25 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)25 FileNotFoundException (java.io.FileNotFoundException)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