Search in sources :

Example 46 with ServerConfiguration

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

the class ContentDiskDriverTest method testScenarioMountainLionWord2011EditByEditor_ALF_16257.

// testScenarioMacLionTextEditByEditorForAlf16257
/**
 * 0. MacWord1.docx exist in folder where user has Editor permissions
 * 1. as Editor rename MacWord1.docx to backup Word Work File L_5.tmp
 * 2. as Editor create temporary file in temporary directory and move it to working dir
 * 3. as Editor rename Word Work File D_2.tmp to MacWord1.docx
 */
public void testScenarioMountainLionWord2011EditByEditor_ALF_16257() throws Exception {
    logger.debug("testScenarioMountainLionWord2011 Edit By Editor ALF-16257");
    final String FILE_NAME = "MacWord1.docx";
    final String FILE_OLD_TEMP = "Word Work File L_5.tmp";
    final String FILE_NEW_TEMP = "Word Work File D_2.tmp";
    class TestContext {

        NetworkFile firstFileHandle;

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

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

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            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 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/ContentDiskDriverTest3.doc");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            // 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);
    /**
     * b) rename the old file, should fire doubleRenameShuffle scenario
     */
    logger.debug("b) rename old file");
    RunAsWork<Void> renameOldFileCB = new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(file1NodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            testContext.mimetype = data.getMimetype();
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    doTransactionWorkAsEditor(renameOldFileCB, tran);
    /**
     * c) as Editor Save the new file in .TemporaryItems
     * and move it to working directory (should be detected by scenario)
     * Write ContentDiskDriverTest3.doc,
     */
    logger.debug("c) create temp file in temp dir");
    RunAsWork<Void> writeFileCB = 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.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest3.doc");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NEW_TEMP);
            return null;
        }
    };
    doTransactionWorkAsEditor(writeFileCB, tran);
    /**
     * d) Move the new file into place, stuff should get shuffled
     */
    logger.debug("d) move new file into place");
    RunAsWork<Void> moveNewFileCB = new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    doTransactionWorkAsEditor(moveNewFileCB, tran);
    /**
     * e) Delete the old file
     */
    logger.debug("e) delete the old file");
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

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

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

Example 47 with ServerConfiguration

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

the class ContentDiskDriverTest method testScenarioDeleteViaNodeService.

// testScenarioSmultronSave
/**
 * This time we create a file through the ContentDiskDriver and then delete it
 * through the repo.   We check its no longer found by the driver.
 */
public void testScenarioDeleteViaNodeService() throws Exception {
    logger.debug("testScenarioDeleteViaNodeService");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    int openAction = FileAction.CreateNotExist;
    final String FILE_NAME = "testDeleteFileViaNodeService.new";
    final String FILE_PATH = "\\" + FILE_NAME;
    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> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            byte[] stuff = "Hello World".getBytes();
            file.writeFile(stuff, stuff.length, 0, 0);
            file.close();
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
            assertNotNull("can't find new node", newNode);
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * Step 1: Delete the new node via the node service
     */
    RetryingTransactionCallback<Void> deleteNodeCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
            assertNotNull("can't find new node", newNode);
            nodeService.deleteNode(newNode);
            return null;
        }
    };
    tran.doInTransaction(deleteNodeCB, false, true);
    try {
        getNodeForPath(testConnection, FILE_PATH);
        fail("getNode for path unexpectedly succeeded");
    } catch (IOException ie) {
    // expect to go here
    }
    /**
     * Delete file by path - file should no longer exist
     */
    try {
        driver.deleteFile(testSession, testConnection, FILE_PATH);
        fail("delete unexpectedly succeeded");
    } catch (IOException ie) {
    // expect to go here
    }
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) IOException(java.io.IOException) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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