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

📄 testundochanges.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // create starting point
        cms.createResource(folder, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
        cms.createResource(folder + "/" + file, CmsResourceTypePlain.getStaticTypeId());
        cms.createResource(folder + "/" + subfolder, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
        cms.createResource(folder + "/" + subfolder + "/" + file, CmsResourceTypePlain.getStaticTypeId());
        cms.createResource(folder + "/" + subfolder + "/" + subsubfolder, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
        cms.createResource(
            folder + "/" + subfolder + "/" + subsubfolder + "/" + file,
            CmsResourceTypePlain.getStaticTypeId());
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishResource(cms, folder);
        OpenCms.getPublishManager().waitWhileRunning();

        storeResources(cms, "/" + folder, true);

        // a. move /folder/subfolder to /subfolder
        cms.lockResource(folder + "/" + subfolder);
        cms.moveResource(folder + "/" + subfolder, "/" + subfolder);

        // b. move /subfolder/subsubfolder to /subsubfolder
        cms.lockResource(subfolder + "/" + subsubfolder);
        cms.moveResource(subfolder + "/" + subsubfolder, "/" + subsubfolder);

        // c. move /subfolder back to its starting location: /folder/subfolder
        cms.moveResource("/" + subfolder, folder + "/" + subfolder);

        // d. undo changes of move operation for /subsubfolder
        cms.undoChanges("/" + subsubfolder, CmsResource.UNDO_MOVE_CONTENT);

        // check intermediate state
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        assertFilter(cms, "/" + folder + "/", OpenCmsTestResourceFilter.FILTER_EQUAL);
        assertFilter(cms, "/" + folder + "/" + file, OpenCmsTestResourceFilter.FILTER_EQUAL);
        assertFilter(cms, "/" + folder + "/" + subfolder + "/", OpenCmsTestResourceFilter.FILTER_TOUCH);
        assertFilter(cms, "/" + folder + "/" + subfolder + "/" + file, OpenCmsTestResourceFilter.FILTER_TOUCH);
        assertFilter(
            cms,
            "/" + folder + "/" + subfolder + "/" + subsubfolder + "/",
            OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        assertFilter(
            cms,
            "/" + folder + "/" + subfolder + "/" + subsubfolder + "/" + file,
            OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);

        // e. undo changes of move operation for /folder/subfolder
        cms.lockResource(folder + "/" + subfolder);
        cms.undoChanges(folder + "/" + subfolder, CmsResource.UNDO_MOVE_CONTENT);

        // check final state, the same starting state
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        assertFilter(cms, "/" + folder + "/", OpenCmsTestResourceFilter.FILTER_EQUAL);
        assertFilter(cms, "/" + folder + "/" + file, OpenCmsTestResourceFilter.FILTER_EQUAL);
        assertFilter(cms, "/" + folder + "/" + subfolder + "/", OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
        assertFilter(
            cms,
            "/" + folder + "/" + subfolder + "/" + file,
            OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
        assertFilter(
            cms,
            "/" + folder + "/" + subfolder + "/" + subsubfolder + "/",
            OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        assertFilter(
            cms,
            "/" + folder + "/" + subfolder + "/" + subsubfolder + "/" + file,
            OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
    }

    /**
     * Tests undo changes after a resource was deleted and another 
     * resource was copied over the deleted file "as sibling".<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesAfterCopySiblingOverDeleted() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undo changes after overwriting a deleted file with a sibling");

        String source = "/folder1/page2.html";
        String destination = "/folder1/page1.html";

        storeResources(cms, source);
        storeResources(cms, destination);

        cms.lockResource(destination);

        // delete and owerwrite with a sibling
        cms.deleteResource(destination, CmsResource.DELETE_PRESERVE_SIBLINGS);
        assertState(cms, destination, CmsResource.STATE_DELETED);

        cms.copyResource(source, destination, CmsResource.COPY_AS_SIBLING);

        // now undo all changes on the resource
        cms.undoChanges(destination, CmsResource.UNDO_CONTENT);

        // now ensure source and destionation are in the original state
        assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);

        // publishing may reveal problems with the id's
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Test undoChanges method to a single folder.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesFolder() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undoChanges on a folder without recursion");
        undoChangesFolder(this, cms, "/folder2/");
    }

    /**
     * Test undoChanges method to a single folder.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesFolderRecursive() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undoChanges on a folder _with_ recursion");
        undoChangesFolderRecursive(this, cms, "/folder1/");
    }

    /**
     * Tests undo changes for the move operation only.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesMove() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undo changes for the move operation only");

        String source = "/folder1/";
        String destination = "/folder1_undo2/";
        String sourceFile = "page1.html";
        String newFile = "filenew.html";

        storeResources(cms, source, true);

        // move
        cms.lockResource(source);
        cms.moveResource(source, destination);

        // edit
        cms.writePropertyObject(destination + sourceFile, new CmsProperty("test property", "a", "b", true));

        // create new file
        cms.createResource(destination + newFile, CmsResourceTypePlain.getStaticTypeId());
        storeResources(cms, destination + newFile);

        // now undo all changes on the folder
        cms.undoChanges(destination, CmsResource.UNDO_MOVE_CONTENT);

        // now ensure source and destionation are in the original state
        assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        // project must be current project
        assertProject(cms, source, cms.getRequestContext().currentProject());

        setMapping(source + newFile, destination + newFile);
        // test recursivly
        Iterator subresources = cms.readResources(source, CmsResourceFilter.ALL).iterator();
        while (subresources.hasNext()) {
            CmsResource res = (CmsResource)subresources.next();
            String resName = cms.getSitePath(res);
            if (resName.equals(source + newFile)) {
                assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_CREATE_RESOURCE);
            } else {
                assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
            }
            // project must be current project
            assertProject(cms, resName, cms.getRequestContext().currentProject());
        }
        assertTrue(cms.existsResource(source, CmsResourceFilter.ALL));
        assertTrue(cms.existsResource(source + sourceFile));
        assertTrue(cms.existsResource(source + newFile));
        assertFalse(cms.existsResource(destination, CmsResourceFilter.ALL));

        cms.deleteResource(source + newFile, CmsResource.DELETE_REMOVE_SIBLINGS);
        // publishing may reveal problems with the id's
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Tests undo changes for the content changes only.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesMoveContent() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undo changes for the content changes only");

        String source = "/folder1/";
        String destination = "/folder1_undo2/";
        String sourceFile = "page1.html";
        String newFile = "filenew.html";

        storeResources(cms, source, true);

        // move
        cms.lockResource(source);
        cms.moveResource(source, destination);

        // edit
        cms.writePropertyObject(destination + sourceFile, new CmsProperty("test property", "a", "b", true));

        // create new file
        cms.createResource(destination + newFile, CmsResourceTypePlain.getStaticTypeId());

        // now undo all content changes on the folder
        cms.undoChanges(destination, CmsResource.UNDO_CONTENT_RECURSIVE);

        setMapping(destination, source);
        // now ensure source and destionation are in the original state
        assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_CONTENT);
        // project must be current project
        assertProject(cms, destination, cms.getRequestContext().currentProject());
        // test recursivly
        Iterator subresources = cms.readResources(destination, CmsResourceFilter.ALL).iterator();
        while (subresources.hasNext()) {
            CmsResource res = (CmsResource)subresources.next();
            String resName = cms.getSitePath(res);
            if (resName.equals(destination + newFile)) {
                assertState(cms, resName, CmsResource.STATE_NEW);
            } else {
                setMapping(resName, CmsStringUtil.substitute(resName, destination, source));
                assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_CONTENT);
            }
            // project must be current project
            assertProject(cms, resName, cms.getRequestContext().currentProject());
        }
        assertTrue(cms.existsResource(destination));
        assertTrue(cms.existsResource(destination + sourceFile));
        assertTrue(cms.existsResource(destination + newFile));
        assertFalse(cms.existsResource(source, CmsResourceFilter.ALL));

        // now undo move operation on the folder
        cms.undoChanges(destination, CmsResource.UNDO_MOVE_CONTENT);

        resetMapping();
        // now ensure source and destionation are in the original state
        assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        // project must be current project
        assertProject(cms, source, cms.getRequestContext().currentProject());
        // test recursivly
        subresources = cms.readResources(source, CmsResourceFilter.ALL).iterator();
        while (subresources.hasNext()) {
            CmsResource res = (CmsResource)subresources.next();
            String resName = cms.getSitePath(res);
            if (resName.equals(source + newFile)) {
                assertState(cms, resName, CmsResource.STATE_NEW);
            } else {
                assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
            }
            // project must be current project
            assertProject(cms, resName, cms.getRequestContext().currentProject());
        }
        assertTrue(cms.existsResource(source));
        assertTrue(cms.existsResource(source + sourceFile));
        assertTrue(cms.existsResource(source + newFile));
        assertFalse(cms.existsResource(destination, CmsResourceFilter.ALL));

        cms.deleteResource(source + newFile, CmsResource.DELETE_REMOVE_SIBLINGS);
        // publishing may reveal problems with the id's
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Tests undo changes after a file was moved and edited.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesMovedFileAfterEdit() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undo changes after a file was moved and edited");

        String source = "/folder1/page1.html";
        String destination = "/folder1/page1_undo.html";

        storeResources(cms, source, true);

        // move
        cms.lockResource(source);
        cms.moveResource(source, destination);

        // edit
        cms.writePropertyObject(destination, new CmsProperty("test property", "a", "b", true));

        // now undo content changes
        cms.undoChanges(destination, CmsResource.UNDO_CONTENT_RECURSIVE);

        setMapping(destination, source);
        // now ensure destination is in the original state
        assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_CONTENT);
        // project must be current project
        assertProject(cms, destination, cms.getRequestContext().currentProject());
        // file must still be moved
        assertFalse(cms.existsResource(source, CmsResourceFilter.ALL));

        // now undo move operation
        cms.undoChanges(destination, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);

        // now ensure source is in the original state
        assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        // file must be in source location
        assertFalse(cms.existsResource(destination, CmsResourceFilter.ALL));

        // publishing may reveal problems with the id's
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Tests undo changes after a folder was moved.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesMovedFolder() throws Throwable {

        CmsObject cms = getCmsObject();

⌨️ 快捷键说明

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