?? testundochanges.java
字號:
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
}
/**
* Test undoChanges method to a single folder.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to touch
* @throws Throwable if something goes wrong
*/
public static void undoChangesFolder(OpenCmsTestCase tc, CmsObject cms, String resource1) throws Throwable {
// create a global storage and store the resource
tc.createStorage("undoChanges");
tc.switchStorage("undoChanges");
tc.storeResources(cms, resource1);
tc.switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE);
long timestamp = System.currentTimeMillis();
// change a property
CmsProperty property1 = new CmsProperty("Title", "undoChanges", null);
TestProperty.writeProperty(tc, cms, resource1, property1);
// change the property on all subresources
List subresources = tc.getSubtree(cms, resource1);
Iterator i = subresources.iterator();
while (i.hasNext()) {
CmsResource res = (CmsResource)i.next();
String resName = cms.getSitePath(res);
TestProperty.writeProperty(tc, cms, resName, property1);
}
// now undo everything
cms.lockResource(resource1);
cms.undoChanges(resource1, false);
cms.unlockResource(resource1);
tc.switchStorage("undoChanges");
// now evaluate the result, the folder must be unchanged now
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// all resources within the folder must keep their changes
Iterator j = subresources.iterator();
while (j.hasNext()) {
CmsResource res = (CmsResource)j.next();
String resName = cms.getSitePath(res);
tc.assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resName, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resName, tc.getPreCalculatedState(resource1));
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resName, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resName, cms.getRequestContext().currentUser());
// the property must have the new value
tc.assertPropertyChanged(cms, resName, property1);
}
}
/**
* Test undoChanges method to a single folder and all resources within the folder.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to touch
* @throws Throwable if something goes wrong
*/
public static void undoChangesFolderRecursive(OpenCmsTestCase tc, CmsObject cms, String resource1) throws Throwable {
// create a global storage and store the resource
tc.createStorage("undoChanges");
tc.switchStorage("undoChanges");
tc.storeResources(cms, resource1);
tc.switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE);
// change a property
CmsProperty property1 = new CmsProperty("Title", "undoChanges", null);
TestProperty.writeProperty(tc, cms, resource1, property1);
// change the property on all subresources
List subresources = tc.getSubtree(cms, resource1);
Iterator i = subresources.iterator();
while (i.hasNext()) {
CmsResource res = (CmsResource)i.next();
String resName = cms.getSitePath(res);
TestProperty.writeProperty(tc, cms, resName, property1);
}
// now undo everything
cms.lockResource(resource1);
cms.undoChanges(resource1, true);
cms.unlockResource(resource1);
tc.switchStorage(OpenCmsTestResourceStorage.GLOBAL_STORAGE);
// now evaluate the result, the folder must be unchanged now
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// all resources within the folder must be unchanged now
Iterator j = subresources.iterator();
while (j.hasNext()) {
CmsResource res = (CmsResource)j.next();
String resName = cms.getSitePath(res);
// now evaluate the result
tc.assertFilter(cms, resName, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES);
// project must be current project
tc.assertProject(cms, resName, cms.getRequestContext().currentProject());
}
}
/**
* Test undoChanges method to a single file.<p>
*
* @throws Throwable if something goes wrong
*/
public void testUndoChangesResource() throws Throwable {
CmsObject cms = getCmsObject();
// this is the first test, so set up the global storage used for all other
// tests
createStorage(OpenCmsTestResourceStorage.GLOBAL_STORAGE);
switchStorage(OpenCmsTestResourceStorage.GLOBAL_STORAGE);
storeResources(cms, "/");
switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE);
echo("Testing undoChanges on a file");
undoChanges(this, cms, "/index.html");
}
/**
* Test undoChanges method to a single folder.<p>
*
* @throws Throwable if something goes wrong
*/
public void testUndoChangesFolder() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing undoChanges on a folder without recursion");
undoChangesFolder(this, cms, "/folder2/");
}
/**
* Test undoChanges method to a single folder.<p>
*
* @throws Throwable if something goes wrong
*/
public void testUndoChangesFolderRecursive() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing undoChanges on a folder _with_ recursion");
undoChangesFolderRecursive(this, cms, "/folder1/");
}
/**
* Test undoChanges method to a resource with an ace.<p>
*
* @throws Throwable if something goes wrong
*/
public void testUndoChangesWithAce() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing undoChanges on a resource with an ACE");
undoChanges(this, cms, "/folder2/index.html");
}
/**
* Test undoChanges method to a resource with an ace.<p>
*
* @throws Throwable if something goes wrong
*/
public void testUndoChangesSharedProperty() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing undoChanges on shared property");
// create the files
String file = "/a";
cms.createResource(file, CmsResourceTypePlain.getStaticTypeId());
// publish the project
cms.unlockProject(cms.getRequestContext().currentProject().getId());
cms.publishProject();
String sibling = "/b";
TestSiblings.createSibling(this, cms, file, sibling);
// write a persistent no-shared property to test with
CmsProperty property = new CmsProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, "undoChanges navText", null);
cms.writePropertyObject(sibling, property);
// write a persistent shared property to test with
CmsProperty property1 = new CmsProperty(CmsPropertyDefinition.PROPERTY_DESCRIPTION, null, "undoChanges description");
cms.writePropertyObject(sibling, property1);
// publish the project
cms.unlockProject(cms.getRequestContext().currentProject().getId());
cms.publishProject();
// create a global storage and store the resource
createStorage("undoChanges");
switchStorage("undoChanges");
storeResources(cms, file);
storeResources(cms, sibling);
switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE);
// change a shared property
CmsProperty property2 = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, null, "undoChanges title");
cms.lockResource(file);
cms.writePropertyObject(file, property2);
cms.unlockResource(file);
//TestProperty.writeProperty(this, cms, file1, property);
// now undo everything
cms.lockResource(file);
cms.undoChanges(file, false);
cms.unlockResource(file);
switchStorage("undoChanges");
// now evaluate the result
assertFilter(cms, file, OpenCmsTestResourceFilter.FILTER_UNDOCHANGES);
// project must be current project
assertProject(cms, file, cms.getRequestContext().currentProject());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -