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

📄 testundochanges.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        echo("Testing undo changes after moving a folder");

        String source = "/folder1/";
        String destination = "/folder1_undo3/";

        storeResources(cms, source);

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

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

        // now ensure source and destionation are in the original state
        assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        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 and a file in the folder edited.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesMovedFolderAfterEdit() throws Throwable {

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

        String source = "/folder1/";
        String destination = "/folder1_undo2/";
        String sourceFile = "page1.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));

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

        // 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
        Iterator subresources = cms.readResources(source, CmsResourceFilter.ALL).iterator();
        while (subresources.hasNext()) {
            CmsResource res = (CmsResource)subresources.next();
            String resName = cms.getSitePath(res);
            // destination + sourceFile changes get lost
            assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
            // project must be current project
            assertProject(cms, resName, cms.getRequestContext().currentProject());
        }
        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 and a file in the folder edited.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesMovedFolderNewFile() throws Throwable {

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

        String source = "/folder1/";
        String destination = "/folder1_undo2/";
        String newFile = "newfile.html";

        storeResources(cms, source, true);

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

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

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

        // 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
        Iterator subresources = cms.readResources(source, CmsResourceFilter.ALL).iterator();
        while (subresources.hasNext()) {
            CmsResource res = (CmsResource)subresources.next();
            String resName = cms.getSitePath(res);
            // newFile should still there
            if (resName.equals(source + newFile)) {
                assertState(cms, source + newFile, CmsResource.STATE_NEW);
            } else {
                assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
                // project must be current project
                assertProject(cms, resName, cms.getRequestContext().currentProject());
            }
        }
        assertFalse(cms.existsResource(destination));
        assertTrue(cms.existsResource(source + newFile));

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

    /**
     * Tests undo changes on a new resource, this must lead to an exception!<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesOnNewResource() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing for exception when trying undo changes on a new resource");

        String source = "/types/new.html";

        // create a new, plain resource
        cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
        assertLock(cms, source, CmsLockType.EXCLUSIVE);

        try {
            cms.undoChanges(source, CmsResource.UNDO_CONTENT);
        } catch (CmsVfsException e) {
            if (!e.getMessageContainer().getKey().equals(org.opencms.db.Messages.ERR_UNDO_CHANGES_FOR_RESOURCE_1)) {
                fail("Did not catch expected exception trying undo changes on a new resource!");
            }
        }
    }

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

        CmsObject cms = getCmsObject();

        // this is the first test, so set up the global storage used for all other
        // tests        
        createStorage(OpenCmsTestResourceStorage.GLOBAL_STORAGE);
        switchStorage(OpenCmsTestResourceStorage.GLOBAL_STORAGE);
        storeResources(cms, "/");
        switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE);

        echo("Testing undoChanges on a file");
        undoChanges(this, cms, "/index.html");
    }

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

        CmsObject cms = getCmsObject();
        echo("Testing undo changes after moving a folder several times");

        String source = "/folder1/";
        String destination = "/folder1_undo4/";
        String source2 = "/subfolder11/";
        String destination2 = "/subfolder11_undo/";

        cms.lockResource(source);
        // move
        cms.moveResource(source, destination);
        // move sub folder
        cms.moveResource(destination + source2, destination2);

        // now try to undo changes on the sub folder
        try {
            cms.undoChanges(destination2, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);
            fail("undo changes should fail, since a parent folder is missing");
        } catch (Exception e) {
            // ok
        }

        // undo changes of parent folder
        cms.undoChanges(destination, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);
        assertFalse(cms.existsResource(destination, CmsResourceFilter.ALL));
        assertTrue(cms.existsResource(source));
        // subfolder should still be moved
        assertFalse(cms.existsResource(destination + source2, CmsResourceFilter.ALL));
        assertTrue(cms.existsResource(destination2));

        // undo changes of sub folder
        cms.undoChanges(destination2, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);
        assertTrue(cms.existsResource(source + source2));
        assertFalse(cms.existsResource(destination2, CmsResourceFilter.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 resource with an ace.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesSharedProperty() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undoChanges on shared property");

        // create the files
        String file = "/a";
        cms.createResource(file, CmsResourceTypePlain.getStaticTypeId());
        // publish the project
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        String sibling = "/b";
        TestSiblings.createSibling(this, cms, file, sibling);
        // write a persistent no-shared property to test with
        CmsProperty property = new CmsProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, "undoChanges navText", null);
        cms.writePropertyObject(sibling, property);
        // write a persistent shared property to test with
        CmsProperty property1 = new CmsProperty(
            CmsPropertyDefinition.PROPERTY_DESCRIPTION,
            null,
            "undoChanges description");
        cms.writePropertyObject(sibling, property1);
        // publish the project
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        // create a global storage and store the resource
        createStorage("undoChanges");
        switchStorage("undoChanges");
        storeResources(cms, file);
        storeResources(cms, sibling);
        switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE);

        // change a shared property
        CmsProperty property2 = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, null, "undoChanges title");
        cms.lockResource(file);
        cms.writePropertyObject(file, property2);
        cms.unlockResource(file);
        //TestProperty.writeProperty(this, cms, file1, property);

        // now undo everything
        cms.lockResource(file);
        cms.undoChanges(file, CmsResource.UNDO_CONTENT);
        cms.unlockResource(file);

        switchStorage("undoChanges");

        // now evaluate the result
        assertFilter(cms, file, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES_ALL);
        // project must be current project
        assertProject(cms, file, cms.getRequestContext().currentProject());

        // 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 sub folder after moving a whole folder.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesSubfolderAfterMoving() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undoChanges on a sub folder after moving a whole folder");

        String source = "/folder1/";
        String destination = "/folder1_undo1/";
        String undo = "subfolder11/";

        cms.lockResource(source);

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

        // now undo all changes on the subfolder
        try {
            cms.undoChanges(destination + undo, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);
            fail("undoing move of subfolder must not be allowed");
        } catch (CmsException e) {
            // expected
        }

        cms.undoChanges(destination, CmsResource.UNDO_MOVE_CONTENT_RECURSIVE);
        // 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 resource with an ace.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testUndoChangesWithAce() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing undoChanges on a resource with an ACE");
        undoChanges(this, cms, "/folder2/index.html");
    }

}

⌨️ 快捷键说明

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