⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmoverename2.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        CmsObject cms = getCmsObject();
        echo("Testing to move a file over a deleted one");

        // Creating paths
        String deletedFile = "/folder1/page1.html";
        String sourceFile = "/folder1/page2.html";

        cms.lockResource("/");
        cms.setDateLastModified("/", System.currentTimeMillis(), true);
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        cms.lockResource(deletedFile);
        cms.deleteResource(deletedFile, CmsResource.DELETE_PRESERVE_SIBLINGS);

        try {
            cms.moveResource(sourceFile, deletedFile);
            fail("should fail to move a file over a deleted one");
        } catch (Exception e) {
            // ok
        }
    }

    /**
     * Tests moving a sibling.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testMoveSibling() throws Exception {

        CmsObject cms = getCmsObject();
        echo("Testing moving a sibling");

        String resName = "index.html";
        String sibName = "folder1/sib.html";
        String sib2Name = "folder1/sib2.html";

        // create sibling
        cms.copyResource(resName, sibName, CmsResource.COPY_AS_SIBLING);
        OpenCms.getPublishManager().publishResource(cms, sibName);
        OpenCms.getPublishManager().waitWhileRunning();

        // store state for later
        storeResources(cms, resName);
        storeResources(cms, sibName);

        // check the initial lock state
        assertLock(cms, resName, CmsLockType.UNLOCKED);
        assertLock(cms, sibName, CmsLockType.UNLOCKED);

        // lock the sibling
        cms.lockResource(sibName);

        // check the lock state
        assertLock(cms, resName, CmsLockType.SHARED_EXCLUSIVE);
        assertLock(cms, sibName, CmsLockType.EXCLUSIVE);

        // move the sibling
        cms.moveResource(sibName, sib2Name);

        // check the lock state
        assertLock(cms, resName, CmsLockType.SHARED_EXCLUSIVE);
        assertLock(cms, sib2Name, CmsLockType.EXCLUSIVE);

        // unlock the resource to enable the filter
        cms.unlockResource(sib2Name);
        assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_EQUAL);

        setMapping(sib2Name, sibName);
        assertFilter(cms, sib2Name, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
        assertState(cms, sib2Name, CmsResourceState.STATE_CHANGED);
        assertProject(cms, sib2Name, cms.getRequestContext().currentProject());
    }

    /**
     * Tests to publish a moved deleted folder with a unpublished moved resource.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testPublishMovedDeletedFolderWithMovedResource() throws Exception {

        CmsObject cms = getCmsObject();
        echo("Testing to publish a moved deleted folder with a unpublished moved resource");

        String folder = "/folder1/subfolder12/";
        String folderDest = "/moved_subfolder12/";
        String source = "index.html";
        String destination = "def.html";

        // move the resource outside of the folder
        cms.lockResource(folder + source);
        cms.moveResource(folder + source, destination);

        // check lock
        assertFalse(cms.getLockedResources(folder, CmsLockFilter.FILTER_ALL).contains(folder + source));

        // move the folder
        cms.lockResource(folder);
        cms.moveResource(folder, folderDest);

        // check lock
        assertFalse(cms.getLockedResources("/folder1", CmsLockFilter.FILTER_ALL).contains(folder));

        try {
            // undoing the changes to a deleted folder must cause an exception
            cms.undoChanges(destination, CmsResource.UNDO_MOVE_CONTENT);
            fail("undoing the changes to a deleted folder must cause an exception");
        } catch (CmsVfsResourceNotFoundException e) {
            // ok
        }

        // delete it
        cms.deleteResource(folderDest, CmsResource.DELETE_PRESERVE_SIBLINGS);

        // publish the deleted folder
        cms.unlockResource(folderDest);
        OpenCms.getPublishManager().publishResource(cms, folderDest);
        OpenCms.getPublishManager().waitWhileRunning();

        // publish the moved file
        cms.unlockResource(destination);
        OpenCms.getPublishManager().publishResource(cms, destination);
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Tests renaming a file to the same name with a different case.<p> 
     * 
     * @throws Exception if the test fails
     */
    public void testRenameFileUpperLowerCase() throws Exception {

        CmsObject cms = getCmsObject();
        echo("Testing to rename a file to the same name with a different case");

        // Creating paths
        String source = "/folder2/image1.gif";
        String destination = "/folder2/Image1.GIF";

        storeResources(cms, source);

        // now move from the old to the new name
        cms.lockResource(source);
        cms.moveResource(source, destination);

        // check lock
        assertFalse(cms.getLockedResources("/folder2", CmsLockFilter.FILTER_ALL).contains(source));

        try {
            // source resource must be gone
            cms.readResource(source, CmsResourceFilter.ALL);
            fail("New resource still available after move operation!");
        } catch (CmsVfsResourceNotFoundException e) {
            // this is expected
        }

        // destination resource

        // project must be current project
        assertProject(cms, destination, cms.getRequestContext().currentProject());
        // state must be "changed"
        assertState(cms, destination, CmsResource.STATE_CHANGED);
        // assert lock state
        assertLock(cms, destination, CmsLockType.EXCLUSIVE);
        // set filter mapping
        setMapping(destination, source);
        // now assert the filter for the rest of the attributes        
        assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
    }

    /**
     * Tests renaming a folder to the same name with a different case.<p> 
     * 
     * @throws Exception if the test fails
     */
    public void testRenameFolderUpperLowerCase() throws Exception {

        CmsObject cms = getCmsObject();
        echo("Testing to rename a folder to the same name with a different case");

        // Creating paths
        String source = "/folder1/subfolder11/subsubfolder111";
        String destination = "/folder1/subfolder11/SubSubFolder111";

        storeResources(cms, source);

        // now move from the old to the new name
        cms.lockResource(source);
        cms.moveResource(source, destination);

        // check lock
        assertFalse(cms.getLockedResources("/folder1", CmsLockFilter.FILTER_ALL).contains(source));

        // source resource must be gone for default read
        try {
            cms.readResource(source, CmsResourceFilter.ALL);
            fail("New resource still available after move operation!");
        } catch (CmsVfsResourceNotFoundException e) {
            // this is expected
        }

        // try to read the destination folder
        cms.readResource(destination);

        // project must be current project
        assertProject(cms, destination, cms.getRequestContext().currentProject());
        // state must be "changed"
        assertState(cms, destination, CmsResource.STATE_CHANGED);
        // assert lock state
        assertLock(cms, destination, CmsLockType.EXCLUSIVE);
        // folders don't have siblings
        assertSiblingCount(cms, destination, 1);

        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Tests renaming a new folder with content.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testRenameNewFolder() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing rename a new folder with content");

        String source = "/folder1";
        String newFolder = "/newfolder";
        String newFolder2 = "/testfolder";

        cms.createResource(newFolder, CmsResourceTypeFolder.getStaticTypeId());

        cms.lockResource(source);
        cms.moveResource(source, newFolder + source);

        // check lock
        assertFalse(cms.getLockedResources("/", CmsLockFilter.FILTER_ALL).contains(source));

        cms.moveResource(newFolder, newFolder2);

        // check lock
        assertFalse(cms.getLockedResources("/", CmsLockFilter.FILTER_ALL).contains(newFolder));

        try {
            cms.readResource(source, CmsResourceFilter.ALL);
            fail("source folder still there.");
        } catch (CmsException e) {
            // ok
        }

        try {
            cms.readResource(newFolder, CmsResourceFilter.ALL);
            fail("new folder still there.");
        } catch (CmsException e) {
            // ok
        }

        try {
            cms.readResource(newFolder2);
        } catch (CmsVfsResourceNotFoundException e) {
            fail("folder not found.");
        }

        assertState(cms, newFolder2, CmsResource.STATE_NEW);
        assertState(cms, newFolder2 + source, CmsResource.STATE_CHANGED);

        cms.undoChanges(newFolder2 + source, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);

        // check lock
        assertFalse(cms.getLockedResources(newFolder2, CmsLockFilter.FILTER_ALL).contains(newFolder2 + source));

        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -