Search in sources :

Example 41 with ServerConfiguration

use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testScenarioMacLionTextEditByEditor_ALF_16257.

/**
 * 0. test.txt exist in folder where user has Editor permissions
 * 1. as Editor create temporary file in temporary directory
 * 2. as Editor rename test.txt to test.txt.sb-1eefba7a-rkC6XE
 * 3. as Editor move temporary file to working directory
 */
public void testScenarioMacLionTextEditByEditor_ALF_16257() throws Exception {
    logger.debug("test Collaborator/editor edit txt file on Mac Os Mountain Lion : Alf16257");
    final String FILE_NAME = "test.txt";
    final String FILE_BACKUP = "test.txt.sb-1eefba7a-rkC6XE";
    // the same but in temp dir
    final String FILE_NEW_TEMP = FILE_NAME;
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile newFileHandle;

        // node ref of FILE_NAME
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = TEST_ROOT_DIR + "\\testALF16257txt";
    final String TEST_TEMP_DIR = TEST_DIR + "\\.TemporaryItems";
    final String UPDATED_TEXT = "This is new content";
    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 {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("Step 0 - initialise");
    /**
     * 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);
            // no need to test lots of different properties, that's already been tested above
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            String testContent = "CIFS: Collaborator/editor could not edit file on Mac Os Mountain Lion";
            byte[] testContentBytes = testContent.getBytes();
            testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.firstFileHandle.close();
            // Apply 'Editor' role for test user to test folder
            permissionService.setPermission(getNodeForPath(testConnection, TEST_DIR), ContentDiskDriverTest.TEST_USER_AUTHORITY, PermissionService.EDITOR, true);
            // Apply full control on temporary directory
            permissionService.setPermission(getNodeForPath(testConnection, TEST_TEMP_DIR), PermissionService.ALL_AUTHORITIES, PermissionService.ALL_PERMISSIONS, true);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * a) Save the temp file in the temp dir
     */
    logger.debug("Step a - create a temp file in the temp dir");
    RunAsWork<Void> saveNewFileCB = new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            FileOpenParams createFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.newFileHandle);
            byte[] testContentBytes = UPDATED_TEXT.getBytes();
            driver.writeFile(testSession, testConnection, testContext.newFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.newFileHandle);
            NodeRef tempNodeRef = getNodeForPath(testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP);
            ContentReader reader = contentService.getReader(tempNodeRef, ContentModel.PROP_CONTENT);
            assertNotNull(reader);
            String actualContent = reader.getContentString();
            assertEquals("new contents were not written to temporary file", UPDATED_TEXT, actualContent);
            return null;
        }
    };
    doTransactionWorkAsEditor(saveNewFileCB, tran);
    /**
     * b) rename the target file to a backup file
     */
    logger.debug("Step b - rename the target file as Editor");
    RunAsWork<Void> renameOldFileCB = new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_BACKUP);
            return null;
        }
    };
    doTransactionWorkAsEditor(renameOldFileCB, tran);
    /**
     * c) Move the new file into target dir, stuff should get shuffled
     */
    logger.debug("Step c - move new file into target dir as Editor");
    RunAsWork<Void> moveNewFileCB = new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    doTransactionWorkAsEditor(moveNewFileCB, tran);
    /**
     * Validate
     */
    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));
            ContentReader reader = contentService.getReader(testContext.testNodeRef, ContentModel.PROP_CONTENT);
            assertNotNull(reader);
            String actualContent = reader.getContentString();
            assertEquals("contents were not updated", UPDATED_TEXT, actualContent);
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
    logger.debug("end testScenarioMacLionTextEditByEditor For ALF-16257");
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) 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) 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 42 with ServerConfiguration

use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testExcel2013SaveShuffle.

/**
 * Excel 2013 With Versionable file  (MNT-13078)
 *
 * CreateFile Cherries.xlsx
 * CreateFile ~herries.tmp
 * CreateFile Cherries.xlsx~RF172f241.TMP
 * DeleteFile Cherries.xlsx~RF172f241.TMP
 * RenameFile oldName: Cherries.xls,
 *            newName: Cherries.xlsx~RF172f241.TMP
 * Delete On Close for Cherries.xlsx~RF172f241.TMP
 * RenameFile oldName: ~herries.tmp,
 *            newName: Cherries.xlsx
 */
public void testExcel2013SaveShuffle() throws Exception {
    logger.debug("testScenarioExcel2013SaveShuffle");
    final String FILE_NAME = "Cherries.xlsx";
    final String FILE_ORIGINAL_TITLE = "Original";
    final String FILE_UNUSED_TEMP = "Cherries.xlsx~RF172f241.TMP";
    final String FILE_USED_TEMP = "~herries.tmp";
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSExcel2013SaveShuffle";
    class TestContext {

        NetworkFile firstFileHandle;

        // node ref of test.doc
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    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
    }
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createOriginalFileCB = 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);
            String testContent = "MS Word 2013 shuffle test. This is first file content";
            byte[] testContentBytes = testContent.getBytes();
            testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.firstFileHandle.close();
            // 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);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            // need to remove. Otherwise file will be deleted (not placed into archive spaces store)
            nodeService.removeAspect(testContext.testNodeRef, ContentModel.ASPECT_NO_CONTENT);
            // test non CM namespace property
            nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
            nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_TITLE, FILE_ORIGINAL_TITLE);
            return null;
        }
    };
    tran.doInTransaction(createOriginalFileCB, false, true);
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createUsedTempFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_USED_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            NetworkFile fileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(fileHandle);
            String testContent = "MS Word 2013 shuffle test. This is used file content";
            byte[] testContentBytes = testContent.getBytes();
            fileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            fileHandle.close();
            NodeRef usedRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_USED_TEMP);
            nodeService.addAspect(usedRef, ContentModel.ASPECT_VERSIONABLE, null);
            nodeService.removeAspect(usedRef, ContentModel.ASPECT_NO_CONTENT);
            nodeService.setProperty(usedRef, ContentModel.PROP_TITLE, "Used");
            return null;
        }
    };
    tran.doInTransaction(createUsedTempFileCB, false, true);
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createUnusedTempFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_UNUSED_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            NetworkFile unusedFile = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(unusedFile);
            NodeRef unusedNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_UNUSED_TEMP);
            nodeService.addAspect(unusedNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            nodeService.setProperty(unusedNodeRef, TransferModel.PROP_ENABLED, true);
            nodeService.setProperty(unusedNodeRef, ContentModel.PROP_TITLE, "Unused");
            return null;
        }
    };
    tran.doInTransaction(createUnusedTempFileCB, false, true);
    /**
     * Delete unused temporary file
     */
    RetryingTransactionCallback<Void> deleteUnusedFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            try {
                driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_UNUSED_TEMP);
            } catch (IOException e) {
            // expect to go here since previous step renamed the file.
            }
            return null;
        }
    };
    tran.doInTransaction(deleteUnusedFileCB, false, true);
    /**
     * Rename the original file to unused file
     */
    RetryingTransactionCallback<Void> renameToUnusedFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_UNUSED_TEMP);
            return null;
        }
    };
    tran.doInTransaction(renameToUnusedFileCB, false, true);
    /**
     * Delete unused temporary file
     */
    tran.doInTransaction(deleteUnusedFileCB, false, true);
    /**
     * Rename the used temporary file to original file
     */
    RetryingTransactionCallback<Void> renameToUsedFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_USED_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(renameToUsedFileCB, 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);
            // Check trx:enabled has been shuffled.
            assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
            assertTrue("node doesn't contain property 'TITLE'", props.containsKey(ContentModel.PROP_TITLE));
            assertEquals("propety 'TITLE' isn't correct", FILE_ORIGINAL_TITLE, props.get(ContentModel.PROP_TITLE));
            assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
            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) IOException(java.io.IOException) 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) 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 43 with ServerConfiguration

use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testScenarioMacMountainLionKeynote_MNT_8558.

// testScenarioMacMountainLionPreview_MNT_317
/**
 * This test tries to simulate the cifs shuffling that is done
 * from Save from Mac Mountain Lion by Keynote when document is saved first time
 *
 * a) Temp file created in temporary folder (temp\test.key)
 * b) Original document renamed to backup copy name (test\test.key -> test\test~.key)
 * c) Temp file moved to original name (temp\test.key -> test\test.key)
 */
public void testScenarioMacMountainLionKeynote_MNT_8558() throws Exception {
    logger.debug("testScenarioMacMountainLionKeynote_MNT_8558");
    final String FILE_NAME = "test.key";
    final String BCKP_FILE_NAME = "test~.key";
    final String TEMP_FILE_NAME = "test.key";
    final String UPDATED_TEXT = "Mac Mountain Lion Keynote Updated Content";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile tempFileHandle;

        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionKeynote";
    final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionKeynote\\.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 Mountain Lion Keynote 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> renameFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + BCKP_FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(renameFileCB, false, true);
    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);
            return null;
        }
    };
    tran.doInTransaction(moveTempFileCB, 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);
    // Make sure that during second rename test.key->test~.key deleted test~.key is not restored and version history doesn't lost.
    RetryingTransactionCallback<Void> prepareForSecondRunCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + BCKP_FILE_NAME);
            FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
            String testContent = UPDATED_TEXT;
            byte[] testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
            return null;
        }
    };
    tran.doInTransaction(prepareForSecondRunCB, false, true);
    tran.doInTransaction(renameFileCB, false, true);
    tran.doInTransaction(moveTempFileCB, false, true);
    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 44 with ServerConfiguration

use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testMetadataExtraction.

/**
 * This test tries to simulate the shuffling that is done by MS Word 2003
 * with regard to metadata extraction.
 * <p>
 * 1: Setup an inbound rule for ContentMetadataExtractor.
 * 2: Write ContentDiskDriverTest1 file to ContentDiskDriver.docx
 * 3: Check metadata extraction for non update test
 * Simulate a WORD 2003 CIFS shuffle
 * 4: Write ContentDiskDriverTest2 file to ~WRD0003.TMP
 * 5: Rename ContentDiskDriver.docx to ~WRL0003.TMP
 * 6: Rename ~WRD0003.TMP to ContentDiskDriver.docx
 * 7: Check metadata extraction
 */
public void testMetadataExtraction() throws Exception {
    logger.debug("testMetadataExtraction");
    final String FILE_NAME = "ContentDiskDriver.docx";
    final String FILE_OLD_TEMP = "~WRL0003.TMP";
    final String FILE_NEW_TEMP = "~WRD0003.TMP";
    class TestContext {

        NodeRef testDirNodeRef;

        NodeRef testNodeRef;

        NetworkFile firstFileHandle;

        NetworkFile secondFileHandle;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testMetadataExtraction";
    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> deleteGarbageDirCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteDirectory(testSession, testConnection, TEST_DIR);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageDirCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("create Test directory" + TEST_DIR);
    RetryingTransactionCallback<Void> createTestDirCB = 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);
            testContext.testDirNodeRef = getNodeForPath(testConnection, TEST_DIR);
            assertNotNull("testDirNodeRef is null", testContext.testDirNodeRef);
            UserTransaction txn = transactionService.getUserTransaction();
            return null;
        }
    };
    tran.doInTransaction(createTestDirCB);
    logger.debug("Create rule on test dir");
    RetryingTransactionCallback<Void> createRuleCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            Rule rule = new Rule();
            rule.setRuleType(RuleType.INBOUND);
            rule.applyToChildren(true);
            rule.setRuleDisabled(false);
            rule.setTitle("Extract Metadata from content");
            rule.setDescription("ContentDiskDriverTest");
            Map<String, Serializable> props = new HashMap<String, Serializable>(1);
            Action extractAction = actionService.createAction("extract-metadata", props);
            ActionCondition noCondition1 = actionService.createActionCondition(NoConditionEvaluator.NAME);
            extractAction.addActionCondition(noCondition1);
            ActionCondition noCondition2 = actionService.createActionCondition(NoConditionEvaluator.NAME);
            CompositeAction compAction = actionService.createCompositeAction();
            compAction.setTitle("Extract Metadata");
            compAction.setDescription("Content Disk Driver Test - Extract Metadata");
            compAction.addAction(extractAction);
            compAction.addActionCondition(noCondition2);
            rule.setAction(compAction);
            ruleService.saveRule(testContext.testDirNodeRef, rule);
            logger.debug("rule created");
            return null;
        }
    };
    tran.doInTransaction(createRuleCB, false, true);
    /**
     * Create a file in the test directory
     */
    logger.debug("create test file in test directory");
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the file we are going to use 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);
            // 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);
            assertNotNull("testContext.testNodeRef is null", testContext.testNodeRef);
            // test non CM namespace property
            nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    logger.debug("step b: write content to test file");
    /**
     * Write ContentDiskDriverTest1.docx to the test file,
     */
    RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest1.docx");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest1.docx", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            logger.debug("close the file, firstFileHandle");
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    logger.debug("Step c: validate metadata has been extracted.");
    /**
     * c: check simple case of meta-data extraction has worked.
     */
    RetryingTransactionCallback<Void> validateFirstExtractionCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            Map<QName, Serializable> props = nodeService.getProperties(testContext.testNodeRef);
            assertTrue("Enabled property has been lost", props.containsKey(TransferModel.PROP_ENABLED));
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertEquals("size is wrong", 11302, data.getSize());
            assertEquals("mimeType is wrong", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", data.getMimetype());
            // These metadata values should be extracted.
            assertEquals("description is not correct", "This is a test file", nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_DESCRIPTION));
            assertEquals("title is not correct", "ContentDiskDriverTest", nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_TITLE));
            assertEquals("author is not correct", "mrogers", nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_AUTHOR));
            return null;
        }
    };
    tran.doInTransaction(validateFirstExtractionCB, false, true);
    /**
     * d: Save the new file as an update file in the test directory
     */
    logger.debug("Step d: create update file in test directory " + FILE_NEW_TEMP);
    RetryingTransactionCallback<Void> createUpdateFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the file we are going to use to test
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(createUpdateFileCB, false, true);
    RetryingTransactionCallback<Void> writeFile2CB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest2.docx");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest2.docx", 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.secondFileHandle.writeFile(buffer, i, 0, offset);
                    offset += i;
                    i = is.read(buffer, 0, buffer.length);
                }
            } finally {
                is.close();
            }
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(writeFile2CB, false, true);
    /**
     * rename the old file
     */
    logger.debug("move old file out of the way.");
    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);
    /**
     * Check the old file has gone.
     */
    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);
    // /**
    // * Check metadata extraction on intermediate new file
    // */
    // RetryingTransactionCallback<Void> validateIntermediateCB = new RetryingTransactionCallback<Void>() {
    // 
    // @Override
    // public Void execute() throws Throwable
    // {
    // NodeRef updateNodeRef = driver.getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP);
    // 
    // Map<QName, Serializable> props = nodeService.getProperties(updateNodeRef);
    // 
    // // These metadata values should be extracted from file2.
    // assertEquals("intermediate file description is not correct", "Content Disk Test 2", props.get(ContentModel.PROP_DESCRIPTION));
    // assertEquals("intermediate file title is not correct", "Updated", props.get(ContentModel.PROP_TITLE));
    // assertEquals("intermediate file author is not correct", "mrogers", props.get(ContentModel.PROP_AUTHOR));
    // 
    // return null;
    // }
    // };
    // 
    // tran.doInTransaction(validateIntermediateCB, true, true);
    /**
     * Move the new file into place, stuff should get shuffled
     */
    logger.debug("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);
    logger.debug("validate update has run correctly.");
    RetryingTransactionCallback<Void> validateUpdateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            // Check trx:enabled has been shuffled and not lost.
            assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertEquals("mimeType is wrong", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", data.getMimetype());
            assertEquals("size is wrong", 11265, data.getSize());
            return null;
        }
    };
    tran.doInTransaction(validateUpdateCB, true, true);
}
Also used : Serializable(java.io.Serializable) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) FileAction(org.alfresco.jlan.server.filesys.FileAction) Action(org.alfresco.service.cmr.action.Action) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) HashMap(java.util.HashMap) 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) UserTransaction(javax.transaction.UserTransaction) SrvSession(org.alfresco.jlan.server.SrvSession) QName(org.alfresco.service.namespace.QName) InputStream(java.io.InputStream) IOException(java.io.IOException) 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) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) Rule(org.alfresco.service.cmr.rule.Rule) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 45 with ServerConfiguration

use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testEmptyContent.

// testZeroByteRules
/**
 * Test that files can be created with empty content and that
 * existing content can be over-wrriten by empty content.
 */
public void testEmptyContent() throws Exception {
    logger.debug("testEmptyContent");
    final String FILE_NAME_ZERO = "Zero.docx";
    final String FILE_NAME_NON_ZERO = "NonZero.docx";
    class TestContext {

        NodeRef testDirNodeRef;

        NodeRef testZeroNodeRef;

        NodeRef testNonZeroNodeRef;

        NetworkFile firstFileHandle;

        NetworkFile secondFileHandle;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testEmptyContent";
    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> deleteGarbageDirCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteDirectory(testSession, testConnection, TEST_DIR);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageDirCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("create Test directory" + TEST_DIR);
    RetryingTransactionCallback<Void> createTestDirCB = 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);
            testContext.testDirNodeRef = getNodeForPath(testConnection, TEST_DIR);
            assertNotNull("testDirNodeRef is null", testContext.testDirNodeRef);
            return null;
        }
    };
    tran.doInTransaction(createTestDirCB);
    /**
     * Create a file in the test directory
     */
    logger.debug("create test file in test directory");
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the zero byte file we are going to use to test
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            testContext.testZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_ZERO);
            assertNotNull("testContext.testNodeRef is null", testContext.testZeroNodeRef);
            logger.debug("close the file, firstFileHandle");
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            /**
             * Create the non zero byte file we are going to use to test
             */
            FileOpenParams createFileParams2 = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_NON_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams2);
            assertNotNull(testContext.secondFileHandle);
            testContext.testNonZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_NON_ZERO);
            assertNotNull("testContext.testNodeRef is null", testContext.testNonZeroNodeRef);
            // Write hello world into the second file
            byte[] stuff = "Hello World".getBytes();
            driver.writeFile(testSession, testConnection, testContext.secondFileHandle, stuff, 0, stuff.length, 0);
            logger.debug("close the second non zero file, secondFileHandle");
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * d: check both files have content properties.
     */
    RetryingTransactionCallback<Void> checkContentPropsCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            assertNotNull("content missing create non zero file.", nodeService.getProperty(testContext.testNonZeroNodeRef, ContentModel.PROP_CONTENT));
            assertNotNull("content missing create zero byte file.", nodeService.getProperty(testContext.testZeroNodeRef, ContentModel.PROP_CONTENT));
            return null;
        }
    };
    tran.doInTransaction(checkContentPropsCB, false, true);
    RetryingTransactionCallback<Void> truncateFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Truncate the non zero byte file we are going to use to test
             */
            FileOpenParams createFileParams2 = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_NON_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.secondFileHandle = driver.openFile(testSession, testConnection, createFileParams2);
            assertNotNull(testContext.secondFileHandle);
            testContext.testNonZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_NON_ZERO);
            assertNotNull("testContext.testNodeRef is null", testContext.testNonZeroNodeRef);
            driver.truncateFile(testSession, testConnection, testContext.secondFileHandle, 0);
            logger.debug("close the second non zero file, secondFileHandle");
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(truncateFileCB, false, true);
    /**
     * d: check both files have content properties.
     */
    RetryingTransactionCallback<Void> checkContentProps2CB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            ContentReader reader = contentService.getReader(testContext.testNonZeroNodeRef, ContentModel.PROP_CONTENT);
            String s = reader.getContentString();
            assertEquals("content not truncated", "", s);
            ContentReader reader2 = contentService.getReader(testContext.testZeroNodeRef, ContentModel.PROP_CONTENT);
            String s2 = reader2.getContentString();
            assertEquals("content not empty", "", s2);
            return null;
        }
    };
    tran.doInTransaction(checkContentProps2CB, 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) 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) 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)

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