📄 testmoverename.java
字号:
// create a new, plain resource
cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
assertLock(cms, source, CmsLock.TYPE_EXCLUSIVE);
storeResources(cms, source);
cms.moveResource(source, destination);
// source resource must be gone
CmsResource res = null;
try {
res = cms.readResource(source);
} catch (CmsVfsResourceNotFoundException e) {
// this is expected
}
if (res != null) {
fail("New resource still available after move operation!");
}
// destination resource
// project must be current project
assertProject(cms, destination, cms.getRequestContext().currentProject());
// state must be "new"
assertState(cms, destination, CmsResource.STATE_NEW);
// assert lock state
assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE);
// set filter mapping
setMapping(destination, source);
// no siblings on the new resource
assertSiblingCount(cms, destination, 1);
// now assert the filter for the rest of the attributes
assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
}
/**
* Tests a "multiple move" on a resource.<p>
*
* @throws Throwable if something goes wrong
*/
public void testRenameNewFolder() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing rename a new folder with content");
// switch to the root context
cms.getRequestContext().setSiteRoot("/");
String source = "/sites/default/folder1";
String newFolder = "/sites/default/newfolder";
String destination = newFolder + "/folder1";
String newFolder2 = "/sites/default/testfolder";
cms.createResource(newFolder, CmsResourceTypeFolder.getStaticTypeId());
cms.lockResource(source);
cms.moveResource(source, destination);
cms.moveResource(newFolder, newFolder2);
try {
cms.readResource(newFolder2, CmsResourceFilter.ALL);
} catch (CmsVfsResourceNotFoundException e) {
echo("ERROR: folder not found, try to create it.");
cms.createResource(newFolder2, CmsResourceTypeFolder.getStaticTypeId());
}
assertState(cms, newFolder2, CmsResource.STATE_NEW);
cms.undoChanges(source, false);
}
/**
* 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);
CmsVfsException error = null;
try {
// moving a folder to it's own subfolder must cause an exception
cms.moveResource(source, destination);
} catch (CmsVfsException e) {
error = e;
}
// an exception must have been thrown
assertNotNull(error);
// check for the right error message
assertSame(error.getMessageContainer().getKey(), Messages.ERR_MOVE_SAME_FOLDER_2);
}
/**
* Tests renaming a file to the same name with a different case.<p>
*
* @throws Exception if the test fails
*/
public void testRenameFileUpperLowerCase() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing to rename a file to the same name with a different case");
// Creating paths
String source = "/folder2/image1.gif";
String destination = "/folder2/Image1.GIF";
storeResources(cms, source);
// now move from the old to the new name
cms.lockResource(source);
cms.moveResource(source, destination);
// source resource must be gone for default read
CmsResource res = null;
try {
res = cms.readResource(source);
} catch (CmsVfsResourceNotFoundException e) {
// this is expected
}
if (res != null) {
fail("New resource still available after move operation!");
}
// source resource must still be available if reading with "include deleted" filter
cms.readResource(source, CmsResourceFilter.ALL);
// source resource
// project must be current project
assertProject(cms, source, cms.getRequestContext().currentProject());
// state must be "deelted"
assertState(cms, source, CmsResource.STATE_DELETED);
// assert lock state
assertLock(cms, source, CmsLock.TYPE_SHARED_EXCLUSIVE);
// "internal" property must have been added
assertPropertyNew(cms, source, new CmsProperty(CmsPropertyDefinition.PROPERTY_INTERNAL,
String.valueOf(cms.getRequestContext().currentProject().getId()), null));
// one sibling must have been added
assertSiblingCountIncremented(cms, source, 1);
// now assert the filter for the rest of the attributes
assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_MOVE_SOURCE);
// destination resource
// project must be current project
assertProject(cms, destination, cms.getRequestContext().currentProject());
// state must be "new"
assertState(cms, destination, CmsResource.STATE_NEW);
// assert lock state
assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE);
// set filter mapping
setMapping(destination, source);
// one sibling must have been added
assertSiblingCountIncremented(cms, destination, 1);
// now assert the filter for the rest of the attributes
assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION);
}
/**
* Tests renaming a folder to the same name with a different case.<p>
*
* @throws Exception if the test fails
*/
public void testRenameFolderUpperLowerCase() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing to rename a folder to the same name with a different case");
// Creating paths
String source = "/xmlcontent";
String destination = "/XMLcontent";
storeResources(cms, source);
// now move from the old to the new name
cms.lockResource(source);
cms.moveResource(source, destination);
// source resource must be gone for default read
CmsResource res = null;
try {
res = cms.readResource(source);
} catch (CmsVfsResourceNotFoundException e) {
// this is expected
}
if (res != null) {
fail("New resource still available after move operation!");
}
// source resource must still be available if reading with "include deleted" filter
cms.readResource(source, CmsResourceFilter.ALL);
// try to read the destination folder
cms.readResource(destination);
// source resource
// project must be current project
assertProject(cms, source, cms.getRequestContext().currentProject());
// state must be "deelted"
assertState(cms, source, CmsResource.STATE_DELETED);
// assert lock state
assertLock(cms, source, CmsLock.TYPE_EXCLUSIVE);
// folders don't have siblings
assertSiblingCount(cms, source, 1);
// destination resource
// project must be current project
assertProject(cms, destination, cms.getRequestContext().currentProject());
// state must be "new"
assertState(cms, destination, CmsResource.STATE_NEW);
// assert lock state
assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE);
// folders don't have siblings
assertSiblingCount(cms, source, 1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -