📄 testlinkparseableresourcetypes.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/types/TestLinkParseableResourceTypes.java,v $
* Date : $Date: 2007-09-12 08:43:27 $
* Version: $Revision: 1.6 $
*
* 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.types;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsResource;
import org.opencms.file.TestLinkValidation;
import org.opencms.importexport.CmsVfsImportExportHandler;
import org.opencms.main.CmsException;
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.xml.page.CmsXmlPage;
import org.opencms.xml.page.CmsXmlPageFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Unit tests for the link parseable resource types.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.6 $
*/
public class TestLinkParseableResourceTypes extends OpenCmsTestCase {
/**
* Default JUnit constructor.<p>
*
* @param arg0 JUnit parameters
*/
public TestLinkParseableResourceTypes(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(TestLinkParseableResourceTypes.class.getName());
suite.addTest(new TestLinkParseableResourceTypes("testInitialSetup"));
suite.addTest(new TestLinkParseableResourceTypes("testCopyResource"));
suite.addTest(new TestLinkParseableResourceTypes("testCreateResource"));
suite.addTest(new TestLinkParseableResourceTypes("testCreateSibling"));
suite.addTest(new TestLinkParseableResourceTypes("testMoveResource"));
suite.addTest(new TestLinkParseableResourceTypes("testReplaceLinkParseableResource"));
suite.addTest(new TestLinkParseableResourceTypes("testReplaceNonLinkParseableResource"));
suite.addTest(new TestLinkParseableResourceTypes("testChTypeLinkParseable"));
suite.addTest(new TestLinkParseableResourceTypes("testChTypeNonLinkParseable"));
suite.addTest(new TestLinkParseableResourceTypes("testWriteFile"));
suite.addTest(new TestLinkParseableResourceTypes("testImportResourceLinkParseable"));
suite.addTest(new TestLinkParseableResourceTypes("testImportResourceNonLinkParseable"));
suite.addTest(new TestLinkParseableResourceTypes("testDeleteResource"));
suite.addTest(new TestLinkParseableResourceTypes("testDeleteFolder"));
suite.addTest(new TestLinkParseableResourceTypes("testUndoChanges"));
TestSetup wrapper = new TestSetup(suite) {
protected void setUp() {
setupOpenCms("simpletest", "/sites/default/");
}
protected void tearDown() {
removeOpenCms();
}
};
return wrapper;
}
/**
* Test chType method, change type link parseable with non link parseable.<p>
*
* @throws Throwable if something goes wrong
*/
public void testChTypeLinkParseable() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing 'chType' method, change type link parseable with non link parseable");
String sourceName = "/index_created.html";
String targetName = "/folder1/image2.gif";
CmsResource target = cms.readResource(targetName);
List relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
int sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
cms.lockResource(sourceName);
cms.chtype(sourceName, CmsResourceTypeBinary.getStaticTypeId());
CmsResource changed = cms.readResource(sourceName);
assertRelationOperation(cms, changed, target, sources - 1, 0);
// check the online project
CmsProject project = cms.getRequestContext().currentProject();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
assertRelationOperation(cms, changed, target, sources, 1);
cms.getRequestContext().setCurrentProject(project);
cms.unlockResource(sourceName);
OpenCms.getPublishManager().publishResource(cms, sourceName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
assertRelationOperation(cms, changed, target, sources - 1, 0);
}
/**
* Test chType method, change type non link parseable with link parseable.<p>
*
* @throws Throwable if something goes wrong
*/
public void testChTypeNonLinkParseable() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing 'chType' method, change type non link parseable with link parseable");
String sourceName = "/index_created.html";
String targetName = "/folder1/image2.gif";
CmsResource target = cms.readResource(targetName);
List relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
int sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
cms.lockResource(sourceName);
cms.chtype(sourceName, CmsResourceTypeXmlPage.getStaticTypeId());
CmsResource changed = cms.readResource(sourceName);
assertRelationOperation(cms, changed, target, sources + 1, 1);
// check the online project
CmsProject project = cms.getRequestContext().currentProject();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
assertRelationOperation(cms, changed, target, sources, 0);
cms.getRequestContext().setCurrentProject(project);
cms.unlockResource(sourceName);
OpenCms.getPublishManager().publishResource(cms, sourceName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
assertRelationOperation(cms, changed, target, sources + 1, 1);
}
/**
* Test copyResource method.<p>
*
* @throws Throwable if something goes wrong
*/
public void testCopyResource() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing 'copyResource' method");
String sourceName = "/index.html";
CmsResource source = cms.readResource(sourceName);
String targetName = "/folder1/image2.gif";
CmsResource target = cms.readResource(targetName);
List relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
int sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
String copyName = "/index_copy.html";
cms.lockResource(sourceName);
cms.copyResource(sourceName, copyName);
CmsResource copy = cms.readResource(copyName);
assertRelationOperation(cms, source, target, sources + 1, 1);
assertRelationOperation(cms, copy, target, sources + 1, 1);
// check the online project
CmsProject project = cms.getRequestContext().currentProject();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
cms.getRequestContext().setCurrentProject(project);
cms.unlockResource(copyName);
OpenCms.getPublishManager().publishResource(cms, copyName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
assertRelationOperation(cms, source, target, sources + 1, 1);
assertRelationOperation(cms, copy, target, sources + 1, 1);
}
/**
* Test createResource method.<p>
*
* @throws Throwable if something goes wrong
*/
public void testCreateResource() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing 'createResource' method");
String sourceName = "/index.html";
CmsResource source = cms.readResource(sourceName);
String targetName = "/folder1/image2.gif";
CmsResource target = cms.readResource(targetName);
List relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
int sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
String createdName = "/index_created.html";
cms.createResource(createdName, source.getTypeId(), cms.readFile(source).getContents(), null);
CmsResource created = cms.readResource(createdName);
assertRelationOperation(cms, source, target, sources + 1, 1);
assertRelationOperation(cms, created, target, sources + 1, 1);
// check the online project
CmsProject project = cms.getRequestContext().currentProject();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
cms.getRequestContext().setCurrentProject(project);
cms.unlockResource(createdName);
OpenCms.getPublishManager().publishResource(cms, createdName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
assertRelationOperation(cms, source, target, sources + 1, 1);
assertRelationOperation(cms, created, target, sources + 1, 1);
}
/**
* Test createSibling method.<p>
*
* @throws Throwable if something goes wrong
*/
public void testCreateSibling() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing 'createSibling' method");
String sourceName = "/index.html";
CmsResource source = cms.readResource(sourceName);
String targetName = "/folder1/image2.gif";
CmsResource target = cms.readResource(targetName);
List relations = cms.getRelationsForResource(targetName, CmsRelationFilter.TARGETS);
assertTrue(relations.isEmpty());
int sources = cms.getRelationsForResource(targetName, CmsRelationFilter.SOURCES).size();
String siblingName = "/index_sibling.html";
cms.lockResource(sourceName);
cms.createSibling(sourceName, siblingName, null);
CmsResource sibling = cms.readResource(siblingName);
assertRelationOperation(cms, source, target, sources + 1, 1);
assertRelationOperation(cms, sibling, target, sources + 1, 1);
// check the online project
CmsProject project = cms.getRequestContext().currentProject();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -