📄 testmoverename.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/test/org/opencms/file/TestMoveRename.java,v $
* Date : $Date: 2007-08-13 16:29:57 $
* Version: $Revision: 1.19 $
*
* 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.CmsVfsOnlineResourceAlreadyExistsException;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.lock.CmsLockFilter;
import org.opencms.lock.CmsLockType;
import org.opencms.main.CmsException;
import org.opencms.main.CmsPermalinkResourceHandler;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionViolationException;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;
import org.opencms.test.OpenCmsTestResourceFilter;
import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Unit tests for move/rename operation.<p>
*
* @author Alexander Kandzior
* @author Michael Moossen
*
* @version $Revision: 1.19 $
*/
public class TestMoveRename extends OpenCmsTestCase {
/**
* Default JUnit constructor.<p>
*
* @param arg0 JUnit parameters
*/
public TestMoveRename(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(TestMoveRename.class.getName());
suite.addTest(new TestMoveRename("testMoveToDeletedFolder"));
suite.addTest(new TestMoveRename("testPublishDeletedFolderWithMovedResource"));
suite.addTest(new TestMoveRename("testPermaLink"));
suite.addTest(new TestMoveRename("testMoveSingleResource"));
suite.addTest(new TestMoveRename("testMoveSingleNewResource"));
suite.addTest(new TestMoveRename("testMultipleMoveResource"));
suite.addTest(new TestMoveRename("testMoveFolderToOwnSubfolder"));
suite.addTest(new TestMoveRename("testOverwriteMovedResource"));
suite.addTest(new TestMoveRename("testMoveWithoutPermissions"));
suite.addTest(new TestMoveRename("testMoveDeleted"));
TestSetup wrapper = new TestSetup(suite) {
protected void setUp() {
setupOpenCms("simpletest", "/sites/default/");
}
protected void tearDown() {
removeOpenCms();
}
};
return wrapper;
}
/**
* Tests to move a folder with deleted subresources.<p>
*
* @throws Exception if the test fails
*/
public void testMoveDeleted() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing to move a folder with deleted subresources");
// Creating paths
String folder = "/testMoveDeleted/";
String destinationFolder = "/testMoveDeleted2/";
String file = "index.html";
// create the resources
cms.createResource(folder, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
cms.createResource(folder + file, CmsResourceTypePlain.getStaticTypeId());
// publish
OpenCms.getPublishManager().publishResource(cms, folder);
OpenCms.getPublishManager().waitWhileRunning();
// delete the file
cms.lockResource(folder);
cms.deleteResource(folder + file, CmsResource.DELETE_PRESERVE_SIBLINGS);
storeResources(cms, folder, true);
// now move the folder
cms.moveResource(folder, destinationFolder);
// assert the folder
// project must be current project
assertProject(cms, destinationFolder, cms.getRequestContext().currentProject());
// state must be "changed"
assertState(cms, destinationFolder, CmsResource.STATE_CHANGED);
// assert lock state
assertLock(cms, destinationFolder, CmsLockType.EXCLUSIVE);
// set filter mapping
setMapping(destinationFolder, folder);
// now assert the filter for the rest of the attributes
assertFilter(cms, destinationFolder, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
// assert the file
// project must be current project
assertProject(cms, destinationFolder + file, cms.getRequestContext().currentProject());
// state must still be "deleted"
assertState(cms, destinationFolder + file, CmsResource.STATE_DELETED);
// assert lock state
assertLock(cms, destinationFolder + file, CmsLockType.INHERITED);
// now assert the filter for the rest of the attributes
assertFilter(cms, destinationFolder + file, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
}
/**
* Tests to move a folder in its own subfolder.<p>
*
* @throws Exception if the test fails
*/
public void testMoveFolderToOwnSubfolder() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing to move a folder in its own subfolder");
// Creating paths
String source = "/folder1/";
String destination = "/folder1/subfolder11/folder1/";
cms.lockResource(source);
try {
// moving a folder to it's own subfolder must cause an exception
cms.moveResource(source, destination);
fail("to move a folder in its own subfolder is not allowed");
} catch (CmsVfsException e) {
assertSame(e.getMessageContainer().getKey(), Messages.ERR_MOVE_SAME_FOLDER_2);
}
}
/**
* Tests the "move a single new resource" operation.<p>
*
* @throws Throwable if something goes wrong
*/
public void testMoveSingleNewResource() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing move of a new file");
String source = "/folder1/new.html";
String destination = "/folder1/new_move.html";
// create a new, plain resource
cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
assertLock(cms, source, CmsLockType.EXCLUSIVE);
storeResources(cms, source);
cms.moveResource(source, destination);
// check lock
assertFalse(cms.getLockedResources("/folder1", CmsLockFilter.FILTER_ALL).contains(source));
// source resource must be gone
try {
cms.readResource(source, CmsResourceFilter.ALL);
fail("New resource still available after move operation!");
} catch (CmsVfsResourceNotFoundException e) {
// this is expected
}
// destination resource
// project must be current project
assertProject(cms, destination, cms.getRequestContext().currentProject());
// state must be "changed"
assertState(cms, destination, CmsResource.STATE_NEW);
// assert lock state
assertLock(cms, destination, CmsLockType.EXCLUSIVE);
// set filter mapping
setMapping(destination, source);
// now assert the filter for the rest of the attributes
assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
}
/**
* Tests the "move single resource" operation.<p>
*
* @throws Throwable if something goes wrong
*/
public void testMoveSingleResource() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing move of a file");
String source = "/folder1/index.html";
String destination = "/folder1/index_move.html";
storeResources(cms, source);
cms.lockResource(source);
cms.moveResource(source, destination);
try {
// source resource must be gone
cms.readResource(source, CmsResourceFilter.ALL);
fail("source resource still there");
} catch (CmsException e) {
// ok
}
// check lock
assertFalse(cms.getLockedResources("/folder1", CmsLockFilter.FILTER_ALL).contains(source));
// project must be current project
assertProject(cms, destination, cms.getRequestContext().currentProject());
// state must be "changed"
assertState(cms, destination, CmsResource.STATE_CHANGED);
// assert lock state
assertLock(cms, destination, CmsLockType.EXCLUSIVE);
// set filter mapping
setMapping(destination, source);
// now assert the filter for the rest of the attributes
assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
OpenCms.getPublishManager().publishProject(cms);
OpenCms.getPublishManager().waitWhileRunning();
}
/**
* Tests to move a file into an as deleted marked folder.<p>
*
* @throws Exception if the test fails
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -