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

📄 testpublishing.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestPublishing.java,v $
 * Date   : $Date: 2007-09-07 11:10:29 $
 * Version: $Revision: 1.26 $
 *
 * 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.CmsPublishList;
import org.opencms.db.CmsPublishedResource;
import org.opencms.file.history.CmsHistoryFile;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypeImage;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsEncoder;
import org.opencms.lock.CmsLockFilter;
import org.opencms.main.CmsException;
import org.opencms.main.CmsMultiException;
import org.opencms.main.OpenCms;
import org.opencms.publish.CmsPublishJobFinished;
import org.opencms.report.CmsShellReport;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestLogAppender;
import org.opencms.test.OpenCmsTestProperties;
import org.opencms.test.OpenCmsTestResourceFilter;
import org.opencms.xml.page.CmsXmlPage;
import org.opencms.xml.page.CmsXmlPageFactory;

import java.util.List;
import java.util.Locale;

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

/**
 * Unit tests for OpenCms publishing.<p>
 * 
 * @author Michael Emmerich 
 * 
 * @version $Revision: 1.26 $
 */
public class TestPublishing extends OpenCmsTestCase {

    /**
     * Default JUnit constructor.<p>
     * 
     * @param arg0 JUnit parameters
     */
    public TestPublishing(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(TestPublishing.class.getName());

        suite.addTest(new TestPublishing("testPublishResourceGalore"));
        suite.addTest(new TestPublishing("testPublishResourceWithRelatedGalore"));
        suite.addTest(new TestPublishing("testPublishProjectGalore"));
        suite.addTest(new TestPublishing("testPublishStructureProperty"));
        suite.addTest(new TestPublishing("testPublishResourceProperty"));
        suite.addTest(new TestPublishing("testPublishSiblings"));
        suite.addTest(new TestPublishing("testPublishCopySibling"));
        suite.addTest(new TestPublishing("testPublishNewFiles"));
        suite.addTest(new TestPublishing("testPublishNewFilesInNewFolder"));
        suite.addTest(new TestPublishing("testPublishChangedFiles"));
        suite.addTest(new TestPublishing("testPublishLockedFiles"));
        suite.addTest(new TestPublishing("testPublishDeletedFiles"));
        suite.addTest(new TestPublishing("testPublishProjectLastmodified"));
        suite.addTest(new TestPublishing("testPublishProjectLastmodifiedFolder"));
        suite.addTest(new TestPublishing("testPublishTemporaryProject"));
        suite.addTest(new TestPublishing("testPublishMovedFiles"));
        suite.addTest(new TestPublishing("testPublishRelatedFiles"));
        suite.addTest(new TestPublishing("testPublishRelatedFilesInFolder"));
        suite.addTest(new TestPublishing("testPublishRelatedFilesInNewFolder"));
        suite.addTest(new TestPublishing("testPublishContentDate"));
        suite.addTest(new TestPublishing("testPublishDeletedSiblings"));
        suite.addTest(new TestPublishing("testPublishDeletedSiblings2"));
        suite.addTest(new TestPublishing("testPublishReplacedFile"));

        TestSetup wrapper = new TestSetup(suite) {

            protected void setUp() {

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

            protected void tearDown() {

                removeOpenCms();
            }
        };

        return wrapper;
    }

    /**
     * Test publishing changed files.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishChangedFiles() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish changed files");

        String resource1 = "/folder2/image1_new.gif";
        String resource2 = "/folder2/image1_sibling1.gif";
        String resource3 = "/folder2/image1_sibling2.gif";
        String resource4 = "/folder2/image1_sibling3.gif";

        CmsProject onlineProject = cms.readProject("Online");
        CmsProject offlineProject = cms.readProject("Offline");

        CmsProperty prop1;
        CmsProperty prop2;
        CmsProperty prop3;
        CmsProperty prop4;

        // make changes to the resources 
        // do not need to make any changes to resource3 and resource4 as they are
        // siblings of resource2!

        cms.lockResource(resource1);
        cms.lockResource(resource2);

        cms.writePropertyObject(resource1, new CmsProperty("Title", resource1, null));
        cms.writePropertyObject(resource2, new CmsProperty("Title", resource2, null));
        cms.writePropertyObject(resource3, new CmsProperty("Title", resource3, null));
        cms.writePropertyObject(resource4, new CmsProperty("Title", resource4, null));

        // unlock all resources
        cms.unlockResource(resource1);
        cms.unlockResource(resource2);

        storeResources(cms, resource1);
        storeResources(cms, resource2);
        storeResources(cms, resource3);
        storeResources(cms, resource4);

        // publish a modified resource without siblings
        //
        OpenCms.getPublishManager().publishResource(cms, resource1);
        OpenCms.getPublishManager().waitWhileRunning();

        // the online file must the offline changes
        cms.getRequestContext().setCurrentProject(onlineProject);
        prop1 = cms.readPropertyObject(resource1, "Title", false);

        if (!prop1.getValue().equals((resource1))) {
            fail("Property not published for " + resource1);
        }
        assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);

        // check if the file in the offline project is unchancged now
        cms.getRequestContext().setCurrentProject(offlineProject);
        assertState(cms, resource1, CmsResource.STATE_UNCHANGED);

        // publish a modified resource with siblings, but keeping the siblings unpublished
        //
        OpenCms.getPublishManager().publishResource(cms, resource2);
        OpenCms.getPublishManager().waitWhileRunning();

        // the online file must the offline changes
        cms.getRequestContext().setCurrentProject(onlineProject);
        prop2 = cms.readPropertyObject(resource2, "Title", false);
        prop3 = cms.readPropertyObject(resource3, "Title", false);
        prop4 = cms.readPropertyObject(resource4, "Title", false);

        if (!prop2.getValue().equals((resource2))) {
            fail("Property not published for " + resource2);
        }
        if (prop3.getValue().equals((resource3))) {
            fail("Property  published for " + resource3);
        }
        if (prop4.getValue().equals((resource4))) {
            fail("Property  published for " + resource4);
        }

        assertFilter(cms, resource2, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);

        // check if the file in the offline project is unchancged now
        cms.getRequestContext().setCurrentProject(offlineProject);
        assertState(cms, resource2, CmsResource.STATE_UNCHANGED);
        assertState(cms, resource3, CmsResource.STATE_CHANGED);
        assertState(cms, resource4, CmsResource.STATE_CHANGED);

        // publish a modified resource with siblings, publish the siblings as well
        //
        OpenCms.getPublishManager().publishResource(
            cms,
            resource3,
            true,
            new CmsShellReport(cms.getRequestContext().getLocale()));
        OpenCms.getPublishManager().waitWhileRunning();

        // the online file must the offline changes
        cms.getRequestContext().setCurrentProject(onlineProject);
        prop3 = cms.readPropertyObject(resource3, "Title", false);
        prop4 = cms.readPropertyObject(resource4, "Title", false);

        if (!prop3.getValue().equals((resource3))) {
            fail("Property  not published for " + resource3);
        }
        if (!prop4.getValue().equals((resource4))) {
            fail("Property  not published for " + resource4);
        }

        assertFilter(cms, resource3, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
        assertFilter(cms, resource4, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);

        // check if the file in the offline project is unchancged now
        cms.getRequestContext().setCurrentProject(offlineProject);
        assertState(cms, resource3, CmsResource.STATE_UNCHANGED);
        assertState(cms, resource4, CmsResource.STATE_UNCHANGED);
    }

    /**
     * Tests the behaviour during publishing depending on the content date.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishContentDate() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing the behaviour during publishing depending on the content date");

        String resName = "/newtext.txt";

        // test creating content
        long time = System.currentTimeMillis();
        synchronized (this) {
            wait(50);
        }
        CmsResource offlineResource = cms.createResource(resName, CmsResourceTypePlain.getStaticTypeId(), null, null);
        CmsFile offlineFile = cms.readFile(offlineResource);
        offlineFile.setContents("abc".getBytes());
        offlineFile = cms.writeFile(offlineFile);
        synchronized (this) {
            wait(50);
        }
        assertTrue(offlineResource.getDateContent() < System.currentTimeMillis());
        assertDateContentAfter(cms, resName, time);

        // test publishing new content
        OpenCms.getPublishManager().publishResource(cms, resName);
        OpenCms.getPublishManager().waitWhileRunning();

        CmsProject onlineProject = cms.readProject("Online");
        cms.getRequestContext().setCurrentProject(onlineProject);
        assertDateContentAfter(cms, resName, offlineResource.getDateContent());
        synchronized (this) {
            wait(50);
        }
        assertTrue(cms.readResource(offlineResource.getStructureId()).getDateContent() < System.currentTimeMillis());

        // test modifying the content
        CmsProject offlineProject = cms.readProject("Offline");
        cms.getRequestContext().setCurrentProject(offlineProject);

        cms.lockResource(resName);
        offlineFile = cms.readFile(offlineResource);
        time = System.currentTimeMillis();
        synchronized (this) {
            wait(50);
        }
        offlineFile.setContents("xyz".getBytes());
        offlineFile = cms.writeFile(offlineFile);
        offlineFile = cms.readFile(resName);
        assertTrue(offlineFile.getDateContent() < System.currentTimeMillis());
        assertDateContentAfter(cms, resName, time);

        // check the online project before publishing
        cms.getRequestContext().setCurrentProject(onlineProject);

⌨️ 快捷键说明

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