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

📄 testhistory.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestHistory.java,v $
 * Date   : $Date: 2007-09-07 12:01:33 $
 * Version: $Revision: 1.7 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.file;

import org.opencms.db.CmsResourceState;
import org.opencms.file.history.CmsHistoryFile;
import org.opencms.file.history.I_CmsHistoryResource;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.main.OpenCms;
import org.opencms.relations.CmsRelation;
import org.opencms.relations.CmsRelationFilter;
import org.opencms.relations.CmsRelationType;
import org.opencms.report.CmsShellReport;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;
import org.opencms.test.OpenCmsTestResourceConfigurableFilter;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Locale;

import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;

/**
 * Unit tests for history operation.<p>
 * 
 * @author Michael Moossen
 * 
 * @version $Revision: 1.7 $
 * 
 * @since 6.9.1
 */
public class TestHistory extends OpenCmsTestCase {

    /**
     * Default JUnit constructor.<p>
     * 
     * @param arg0 JUnit parameters
     */
    public TestHistory(String arg0) {

        super(arg0);
    }

    /**
     * Test suite for this test class.<p>
     * 
     * @return the test suite
     */
    public static Test suite() {

        OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);

        TestSuite suite = new TestSuite();
        suite.setName(TestHistory.class.getName());

        suite.addTest(new TestHistory("testFileRestore"));
        suite.addTest(new TestHistory("testFileRestoreIteration"));
        suite.addTest(new TestHistory("testSiblingsRestoration"));
        suite.addTest(new TestHistory("testSiblingsEdition"));
        suite.addTest(new TestHistory("testSiblingsV7HistoryIssue2"));
        suite.addTest(new TestHistory("testSiblingVersions"));
        suite.addTest(new TestHistory("testSiblingRestoreIteration"));
        suite.addTest(new TestHistory("testCreateAndDeleteFile"));
        suite.addTest(new TestHistory("testCreateAndDeleteFolder"));
        suite.addTest(new TestHistory("testMoveFile"));
        suite.addTest(new TestHistory("testPathHistory"));
        suite.addTest(new TestHistory("testFileHistory"));
        suite.addTest(new TestHistory("testFileHistoryFileWithSibling"));
        suite.addTest(new TestHistory("testFileVersions"));
        suite.addTest(new TestHistory("testVersioningLimit"));
        suite.addTest(new TestHistory("testSiblingsV7HistoryIssue"));

        TestSetup wrapper = new TestSetup(suite) {

            protected void setUp() {

                setupOpenCms("simpletest", "/sites/default/");
            }

            protected void tearDown() {

                removeOpenCms();
            }
        };

        return wrapper;
    }

    /**
     * Test a create and edit siblings scenario.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testSiblingsEdition() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing history with siblings edition");

        // first we create a complete new folder as base for the test
        String folder = "/siblings_edition/";
        cms.createResource(folder, CmsResourceTypeFolder.getStaticTypeId());
        OpenCms.getPublishManager().publishResource(cms, folder);
        OpenCms.getPublishManager().waitWhileRunning();

        // 1. create first sibling
        String s1name = folder + "s1.txt";
        CmsResource s1 = cms.createResource(
            s1name,
            CmsResourceTypePlain.getStaticTypeId(),
            "first sibling".getBytes(),
            null);

        // check the history
        assertHistory(cms, s1name, 1);

        // 2. publish s1
        OpenCms.getPublishManager().publishResource(cms, s1name);
        OpenCms.getPublishManager().waitWhileRunning();

        // check the history
        assertHistory(cms, s1name, 1);
        I_CmsHistoryResource histRes = cms.readResource(s1.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());

        // remember pub tag to be able to check the next operations
        int basePubTag = histRes.getPublishTag();

        // 3. create second sibling
        String s2name = folder + "s2.txt";
        CmsResource s2 = cms.createSibling(s1name, s2name, null);

        // check the history
        assertHistory(cms, s1name, 1);
        assertHistory(cms, s2name, 2);

        // 4. publish s2
        OpenCms.getPublishManager().publishResource(cms, s2name);
        OpenCms.getPublishManager().waitWhileRunning();

        // check the history for s1
        assertHistory(cms, s1name, 1);
        histRes = cms.readResource(s1.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag, histRes.getPublishTag());

        // check the history for s2
        assertHistory(cms, s2name, 2);
        histRes = cms.readResource(s2.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag, histRes.getPublishTag());
        histRes = cms.readResource(s2.getStructureId(), 2);
        assertEquals(1, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag + 1, histRes.getPublishTag());

        // 5. make a resource change
        cms.lockResource(s1name);
        cms.writePropertyObject(s1name, new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, null, "resource change"));

        // check history
        assertHistory(cms, s1name, 2);
        assertHistory(cms, s2name, 3);

        // 6. make a structure change on s2
        cms.changeLock(s2name);
        cms.writePropertyObject(s2name, new CmsProperty(
            CmsPropertyDefinition.PROPERTY_NAVTEXT,
            "structure change",
            null));

        // check history
        assertHistory(cms, s1name, 2);
        assertHistory(cms, s2name, 3);

        // 7. publish s1
        OpenCms.getPublishManager().publishResource(cms, s1name);
        OpenCms.getPublishManager().waitWhileRunning();

        // check the history for s1
        assertHistory(cms, s1name, 2);
        histRes = cms.readResource(s1.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag, histRes.getPublishTag());
        histRes = cms.readResource(s1.getStructureId(), 2);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(2, histRes.getResourceVersion());
        assertEquals(basePubTag + 2, histRes.getPublishTag());

        // check the history for s2
        assertHistory(cms, s2name, 4);
        histRes = cms.readResource(s2.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag, histRes.getPublishTag());
        histRes = cms.readResource(s2.getStructureId(), 2);
        assertEquals(1, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag + 1, histRes.getPublishTag());
        histRes = cms.readResource(s2.getStructureId(), 3);
        assertEquals(1, histRes.getStructureVersion());
        assertEquals(2, histRes.getResourceVersion());
        assertEquals(basePubTag + 2, histRes.getPublishTag());

        // 8. publish s2
        OpenCms.getPublishManager().publishResource(cms, s2name);
        OpenCms.getPublishManager().waitWhileRunning();

        // check the history for s1
        assertHistory(cms, s1name, 2);
        histRes = cms.readResource(s1.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag, histRes.getPublishTag());
        histRes = cms.readResource(s1.getStructureId(), 2);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(2, histRes.getResourceVersion());
        assertEquals(basePubTag + 2, histRes.getPublishTag());

        // check the history for s2
        assertHistory(cms, s2name, 4);
        histRes = cms.readResource(s2.getStructureId(), 1);
        assertEquals(0, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag, histRes.getPublishTag());
        histRes = cms.readResource(s2.getStructureId(), 2);
        assertEquals(1, histRes.getStructureVersion());
        assertEquals(1, histRes.getResourceVersion());
        assertEquals(basePubTag + 1, histRes.getPublishTag());
        histRes = cms.readResource(s2.getStructureId(), 3);
        assertEquals(1, histRes.getStructureVersion());
        assertEquals(2, histRes.getResourceVersion());
        assertEquals(basePubTag + 2, histRes.getPublishTag());
        histRes = cms.readResource(s2.getStructureId(), 4);
        assertEquals(2, histRes.getStructureVersion());
        assertEquals(2, histRes.getResourceVersion());
        assertEquals(basePubTag + 3, histRes.getPublishTag());

        // 9. change structure on s1
        cms.lockResource(s1name);
        cms.setDateExpired(s1name, System.currentTimeMillis(), false);

        // check history
        assertHistory(cms, s1name, 3);

⌨️ 快捷键说明

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