Search in sources :

Example 6 with DiskSharedDevice

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

the class ContentDiskDriverTest method getDiskSharedDevice.

private DiskSharedDevice getDiskSharedDevice() throws DeviceContextException {
    ContentContext ctx = new ContentContext("testContext", STORE_NAME, ROOT_PATH, repositoryHelper.getCompanyHome());
    DiskSharedDevice share = new DiskSharedDevice("test", driver, ctx);
    return share;
}
Also used : DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 7 with DiskSharedDevice

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

the class ContentDiskDriverTest method testScenarioMacMountainLionPreview_MNT_263.

// testScenarioMountainLionPreview
/**
 * This test tries to simulate the cifs shuffling that is done
 * from Save from Mac Mountain Lion by Preview when document is saved first time
 *
 * a) Temp file created in temporary folder (temp\image.jpg.sb-1e5e1543-ajn3cR)
 * b) Temp file renamed to original name (temp\image.jpg.sb-1e5e1543-ajn3cR -> temp\image.jpg)
 * c) Original document renamed to backup copy name (test\image.jpg -> test\image.jpg.sb-1e5e1543-ajn3cR)
 * d) Renamed temp file moved to original (temp\image.jpg -> test\image.jpg)
 */
public void testScenarioMacMountainLionPreview_MNT_263() throws Exception {
    logger.debug("testScenarioMacMountainLionPreview_MNT_263");
    final String FILE_NAME = "image.jpg";
    final String TEMP_FILE_NAME = "image.jpg.sb-1e5e1543-ajn3cR";
    final String UPDATED_TEXT = "Mac Lion Preview Updated Content";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile tempFileHandle;

        // node ref image.jpg
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionPreview";
    final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionPreview\\.Temporary Items";
    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);
            FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            driver.createDirectory(testSession, testConnection, createTempDirParams);
            /**
             * 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);
            String testContent = "Mac Lion Preview Content";
            byte[] testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.firstFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            /**
             * Create the temp file we are going to use
             */
            FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
            assertNotNull(testContext.tempFileHandle);
            testContent = UPDATED_TEXT;
            testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
            /**
             * Also add versionable to target file
             */
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    RetryingTransactionCallback<Void> renameTempFileCB = new RetryingTransactionCallback<Void>() {

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

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

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

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
            assertEquals("Unexpected content size", contentService.getReader(shuffledNodeRef, ContentModel.PROP_CONTENT).getSize(), UPDATED_TEXT.length());
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) 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) 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 8 with DiskSharedDevice

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

the class ContentDiskDriverTest method testScenarioMacLionTextEdit.

// test set modified scenario
/**
 * This test tries to simulate the cifs shuffling that is done
 * from Save from Mac Lion by TextEdit
 *
 * a) Temp file created in temporary folder (test.txt)
 * b) Resource fork file created in temporary folder (._test.txt)
 * b) Target file deleted
 * c) Temp file moved to target file.
 */
public void testScenarioMacLionTextEdit() throws Exception {
    logger.debug("testScenarioLionTextEdit");
    final String FILE_NAME = "test.txt";
    final String FORK_FILE_NAME = "._test.txt";
    final String TEMP_FILE_NAME = "test.txt";
    final String UPDATED_TEXT = "Mac Lion Text Updated Content";
    class TestContext {

        NetworkFile lockFileHandle;

        NetworkFile firstFileHandle;

        NetworkFile tempFileHandle;

        // node ref of test.doc
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioLionTextEdit";
    final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioLionTextEdit\\.Temporary Items";
    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);
            FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            driver.createDirectory(testSession, testConnection, createTempDirParams);
            /**
             * 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);
            String testContent = "Mac Lion Text";
            byte[] testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.firstFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            /**
             * Create the temp file we are going to use
             */
            FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
            assertNotNull(testContext.tempFileHandle);
            testContent = UPDATED_TEXT;
            testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
            /**
             * Create the temp resource fork file we are going to use
             */
            createFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + FORK_FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.lockFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.lockFileHandle);
            testContext.lockFileHandle.closeFile();
            /**
             * Also add versionable to target file
             */
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * b) Delete the target file
     */
    RetryingTransactionCallback<Void> deleteTargetFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(deleteTargetFileCB, false, true);
    /**
     * c) Move the temp file into place
     */
    RetryingTransactionCallback<Void> moveTempFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
            driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FORK_FILE_NAME, TEST_DIR + "\\" + FORK_FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(moveTempFileCB, false, true);
    /**
     * Validate results.
     */
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
            assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            ContentReader reader = contentService.getReader(shuffledNodeRef, ContentModel.PROP_CONTENT);
            assertNotNull("Reader is null", reader);
            String s = reader.getContentString();
            assertEquals("content not written", UPDATED_TEXT, s);
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) ContentReader(org.alfresco.service.cmr.repository.ContentReader) 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 9 with DiskSharedDevice

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

the class ContentDiskDriverTest method testFileExists.

// testOpenFile
/**
 * Unit test of file exists
 */
public void testFileExists() throws Exception {
    logger.debug("testFileExists");
    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();
    final String FILE_PATH = TEST_ROOT_DOS_PATH + "\\testFileExists.new";
    class TestContext {
    }
    ;
    final TestContext testContext = new TestContext();
    /**
     * Step 1 : Call FileExists for a directory which does not exist
     */
    logger.debug("Step 1, negative test dir does not exist");
    int status = driver.fileExists(testSession, testConnection, TEST_ROOT_DOS_PATH);
    assertEquals(status, 0);
    /**
     * Step 2 : Call FileExists for a file which does not exist
     */
    logger.debug("Step 2, negative test file does not exist");
    status = driver.fileExists(testSession, testConnection, FILE_PATH);
    assertEquals(status, 0);
    /**
     * Step 3: Create a new file in read/write mode and add some content.
     */
    int openAction = FileAction.CreateNotExist;
    FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
    driver.createDirectory(testSession, testConnection, dirParams);
    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> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            byte[] stuff = "Hello World".getBytes();
            file.writeFile(stuff, stuff.length, 0, 0);
            driver.closeFile(testSession, testConnection, file);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    status = driver.fileExists(testSession, testConnection, FILE_PATH);
    assertEquals(status, 1);
    /**
     * Step 4 : Delete the node - check status goes back to 0
     */
    logger.debug("Step 4, successfully delete node");
    driver.deleteFile(testSession, testConnection, FILE_PATH);
    status = driver.fileExists(testSession, testConnection, FILE_PATH);
    assertEquals(status, 0);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) 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 10 with DiskSharedDevice

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

the class ContentDiskDriverTest method testScenarioMSWord2003SaveAsShuffleCheckedOutFile.

// testEmptyFiles
/**
 * Simulates a SaveAs from Word2003 for a checked out file
 *
 * 1. Create new document TESTFILE.DOC, file did not exist
 * 2. CheckOut TESTFILE.DOC
 * 3. Create -WRDnnnn.TMP file, where 'nnnn' is a 4 digit sequence to make the name unique
 * 4. Rename TESTFILE(Working Copy).DOC to Backup of SAVEAS.wbk
 * 5. Rename -WRDnnnn.TMP to TESTFILE(Working Copy).DOC
 * 6  CheckIn working copy.
 * 7. Validate TESTFILE.DOC
 */
public void testScenarioMSWord2003SaveAsShuffleCheckedOutFile() throws Exception {
    logger.debug("testScenarioMSWord2003SaveShuffleLockedFile");
    final String FILE_NAME = "TESTFILE.DOC";
    final String FILE_OLD_TEMP = "SAVEAS.wbk";
    final String FILE_NEW_TEMP = "~WRD0002.TMP";
    class TestContext {

        NetworkFile firstFileHandle;

        String workingFileName;

        NodeRef workingCopy;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSWord2003ShuffleLockedFile";
    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 and check out");
    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 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);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            /**
             * CheckOut the test node
             */
            NodeRef workingCopy = checkOutCheckInService.checkout(shuffledNodeRef);
            assertNotNull("Working copy is null", workingCopy);
            testContext.workingCopy = workingCopy;
            ChildAssociationRef ref = nodeService.getPrimaryParent(workingCopy);
            QName name = ref.getQName();
            testContext.workingFileName = ref.getQName().getLocalName();
            assertNotNull("working file name is null", testContext.workingFileName);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * b) Save the new file
     * Write ContentDiskDriverTest3.doc 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/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(writeFileCB, false, true);
    /**
     * c) rename the old working 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 + "\\" + testContext.workingFileName, 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 + "\\" + testContext.workingFileName);
            return null;
        }
    };
    tran.doInTransaction(moveNewFileCB, false, true);
    logger.debug("e) now check in");
    /**
     * Now Check In
     */
    RetryingTransactionCallback<Void> checkInCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            checkOutCheckInService.checkin(testContext.workingCopy, null);
            return null;
        }
    };
    tran.doInTransaction(checkInCB, 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", 26112, data.getSize());
            assertEquals("mimeType is wrong", "application/msword", data.getMimetype());
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, true);
}
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) QName(org.alfresco.service.namespace.QName) InputStream(java.io.InputStream) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) 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