📄 testsiblings.java
字号:
"s#^/sites/default/pics(.*)#/system/galleries/pics$1#",
"s#^/sites/default/download(.*)#/system/galleries/download$1#",
"s#^/sites/default/externallinks(.*)#/system/galleries/externallinks$1#",
"s#^/sites/default/htmlgalleries(.*)#/system/galleries/htmlgalleries$1#",
"s#^/sites/default/content(.*)#/system$1#"
},
false);
// set modified folder translator
OpenCms.getResourceManager().setTranslators(
folderTranslator,
OpenCms.getResourceManager().getFileTranslator());
try {
CmsObject cms = getCmsObject();
cms.getRequestContext().setSiteRoot("/");
// need to create the "galleries" folder manually
cms.createResource("/system/galleries", CmsResourceTypeFolder.RESOURCE_TYPE_ID);
cms.unlockResource("/system/galleries");
cms.getRequestContext().setSiteRoot("/sites/default");
// import the files
String importFile = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf("packages/testimport01.zip");
OpenCms.getImportExportManager().importData(cms, importFile, "/", new CmsShellReport(cms.getRequestContext().getLocale()));
// clean up for the next test
cms.getRequestContext().setSiteRoot("/");
cms.lockResource("/sites/default");
cms.lockResource("/system");
// using the option "DELETE_REMOVE_SIBLINGS" caused an error here!
cms.deleteResource("/sites/default/importtest", CmsResource.DELETE_REMOVE_SIBLINGS);
cms.deleteResource("/system/bodies", CmsResource.DELETE_REMOVE_SIBLINGS);
cms.deleteResource("/system/galleries/pics", CmsResource.DELETE_REMOVE_SIBLINGS);
cms.unlockResource("/sites/default");
cms.unlockResource("/system");
cms.publishProject();
} finally {
// reset the translation rules
OpenCms.getResourceManager().setTranslators(
oldFolderTranslator,
OpenCms.getResourceManager().getFileTranslator());
}
}
/**
* Does an "undo changes" from the online project on a resource with more than 1 sibling.<p>
*/
/*
public static void undoChangesWithSiblings(...) throws Throwable {
// this test should do the following:
// - create a sibling of a resource
// - e.g. touch the black/unchanged sibling so that it gets red/changed
// - make an "undo changes" -> the last-modified-in-project ID in the resource record
// of the resource must be the ID of the current project, and not 0
// - this is to ensure that the new/changed/deleted other sibling still have a valid
// state which consits of the last-modified-in-project ID plus the resource state
// - otherwise this may result in grey flags
Another issue:
What happens if a user A has an exclusive lock on a resource X,
and user B does a "copy as sibling Y" of X, or "create
new sibling Y" of X. The lock status of the resource X is exclusive
to A, but test implies that it would be switched to B after operation!
Maybe copy as / create new sibling must not be allowed if original is
currently locked by another user?
}
*/
/**
* Tests if setting the flags of a sibling will do any modifications to other siblings.<p>
*
* @throws Throwable if something goes wrong
*/
public void testSiblingStateIssue() throws Throwable {
echo("Tests issue with resource state and siblings");
CmsObject cms = getCmsObject();
// part 1: changes to the fields that are part of the resource table
String resource1 = "/folder1/page1.html";
String sibling1 = "/folder1/sibling1.html";
// create a sibling
cms.copyResource(resource1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, resource1, CmsResource.STATE_UNCHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// now set the flags for the sibling
cms.chflags(sibling1, 1024);
cms.chtype(sibling1, CmsResourceTypeBinary.getStaticTypeId());
// verify the state of the resources after the change
assertState(cms, resource1, CmsResource.STATE_CHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// part 2: now the same operation with a new copy
String copy1 = "/folder1/copy1.html";
sibling1 = "/folder1/siblingofcopy1.html";
// create a copy
cms.copyResource(resource1, copy1, CmsResource.COPY_AS_NEW);
cms.copyResource(copy1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// now set the flags for the sibling
cms.chflags(sibling1, 1024);
cms.chtype(sibling1, CmsResourceTypeBinary.getStaticTypeId());
// verify the state of the resources after the change
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// part 3: changes to the fields that are part of the structure table
resource1 = "/folder1/page2.html";
sibling1 = "/folder1/sibling2.html";
// create a sibling
cms.copyResource(resource1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, resource1, CmsResource.STATE_UNCHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// after changes of dates the resource states must be the same
cms.setDateExpired(sibling1, System.currentTimeMillis() + 1000, false);
cms.setDateReleased(sibling1, System.currentTimeMillis() - 1000, false);
// verify the state of the resources after the change
assertState(cms, resource1, CmsResource.STATE_UNCHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// step 4: changes to the fields that are part of the resource table
cms.setDateLastModified(sibling1, System.currentTimeMillis(), false);
// verify the state of the resources after the change
assertState(cms, resource1, CmsResource.STATE_CHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// part 5: now the same operation with a new copy
copy1 = "/folder1/copy2.html";
sibling1 = "/folder1/siblingofcopy2.html";
// create a copy
cms.copyResource(resource1, copy1, CmsResource.COPY_AS_NEW);
cms.copyResource(copy1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// change date of last modification
cms.setDateLastModified(sibling1, System.currentTimeMillis(), false);
// verify the state of the resources after the change
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// modifiy release info
cms.setDateExpired(sibling1, System.currentTimeMillis() + 1000, false);
cms.setDateReleased(sibling1, System.currentTimeMillis() - 1000, false);
// verify the state of the resources after the change
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
}
/**
* Tests deletion of a resource together with all siblings.<p>
*
* @throws Throwable if something goes wrong
*/
public void testDeleteAllSiblings() throws Throwable {
echo("Creating a new resource with 2 siblings, then deleting it with all siblings again");
CmsObject cms = getCmsObject();
String sib1Name = "/folder1/sib1.txt";
String sib2Name = "/folder1/sib2.txt";
String sib3Name = "/folder1/sib3.txt";
cms.createResource(sib1Name, CmsResourceTypePlain.getStaticTypeId());
cms.createSibling(sib1Name, sib2Name, Collections.EMPTY_LIST);
cms.createSibling(sib1Name, sib3Name, Collections.EMPTY_LIST);
cms.deleteResource(sib1Name, CmsResource.DELETE_REMOVE_SIBLINGS);
CmsResource sib2Resource = null;
try {
sib2Resource = cms.readResource(sib2Name);
} catch (CmsVfsResourceNotFoundException e) {
// intentionally left blank
}
if (sib2Resource != null) {
fail("Sibling " + sib2Name + " has not been deleted!");
}
CmsResource sib3Resource = null;
try {
sib3Resource = cms.readResource(sib3Name);
} catch (CmsVfsResourceNotFoundException e) {
// intentionally left blank
}
if (sib3Resource != null) {
fail("Sibling " + sib3Name + " has not been deleted!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -