📄 opencmstestcase.java
字号:
+ CmsDateUtil.getHeaderDate(dateCreated)
+ " > "
+ res.getDateCreated()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateCreated())
+ "]");
}
} catch (CmsException e) {
fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e));
}
}
/**
* Compares the current date last modified of a resource with a given date.<p>
*
* @param cms the CmsObject
* @param resourceName the name of the resource to compare
* @param dateLastModified the last modification date
*/
public void assertDateLastModified(CmsObject cms, String resourceName, long dateLastModified) {
try {
// get the actual resource from the vfs
CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL);
if (res.getDateLastModified() != dateLastModified) {
fail("[DateLastModified "
+ dateLastModified
+ " i.e. "
+ CmsDateUtil.getHeaderDate(dateLastModified)
+ " != "
+ res.getDateLastModified()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateLastModified())
+ "]");
}
} catch (CmsException e) {
fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e));
}
}
/**
* Tests if the the current date last modified of a resource is later then a given date.<p>
*
* @param cms the CmsObject
* @param resourceName the name of the resource to compare
* @param dateLastModified the last modification date
*/
public void assertDateLastModifiedAfter(CmsObject cms, String resourceName, long dateLastModified) {
try {
// get the actual resource from the vfs
CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL);
if (res.getDateLastModified() < dateLastModified) {
fail("[DateLastModified "
+ dateLastModified
+ " i.e. "
+ CmsDateUtil.getHeaderDate(dateLastModified)
+ " > "
+ res.getDateLastModified()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateLastModified())
+ "]");
}
} catch (CmsException e) {
fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e));
}
}
/**
* Tests if the given exceptions are equal (or both null).<p>
*
* @param e1 first exception to compare
* @param e2 second exception to compare
*/
public void assertEquals(CmsException e1, CmsException e2) {
if (e1 == null && e2 == null) {
return;
}
if ((e1 == null && e2 != null) || (e1 != null && e2 == null)) {
fail("Exceptions not equal (not both null)");
}
if (!(e1.getClass().equals(e2.getClass()))) {
fail("Exception " + e1.toString() + " does not equal " + e2.toString());
}
if (!(e1.getMessageContainer().getKey().equals(e2.getMessageContainer().getKey()))) {
fail("Exception " + e1.toString() + " does not equal " + e2.toString());
}
}
/**
* Tests if the given xml document objects are equals (or both null).<p>
*
* @param d1 first document to compare
* @param d2 second document to compare
*/
public void assertEquals(Document d1, Document d2) {
if (d1 == null && d2 == null) {
return;
}
if ((d1 == null && d2 != null) || (d1 != null && d2 == null)) {
fail("Documents not equal (not both null)");
}
InternalNodeComparator comparator = new InternalNodeComparator();
if (comparator.compare((Node)d1, (Node)d2) != 0) {
fail("Comparison of documents failed: "
+ "name = "
+ d1.getName()
+ ", "
+ "path = "
+ comparator.m_node1.getUniquePath());
}
}
/**
* Compares a given resource to its stored version containing the state before a CmsObject
* method was called.<p>
*
* @param cms the CmsObject
* @param resource the resource to compare
* @param filter the filter contianing the flags defining which attributes to compare
*/
public void assertFilter(CmsObject cms, CmsResource resource, OpenCmsTestResourceFilter filter) {
try {
// get the stored resource
OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resource.getRootPath());
// compare the current resource with the stored resource
assertFilter(cms, storedResource, resource, filter);
} catch (Exception e) {
fail("cannot read resource " + resource.getRootPath() + " " + e.getMessage());
}
}
/**
* Compares a stored Cms resource with another Cms resource instance using a specified filter.<p>
*
* @param cms the current user's Cms object
* @param storedResource a stored Cms resource representing the state before an operation
* @param res a Cms resource representing the state after an operation
* @param filter a filter to compare both resources
*/
public void assertFilter(
CmsObject cms,
OpenCmsTestResourceStorageEntry storedResource,
CmsResource res,
OpenCmsTestResourceFilter filter) {
String noMatches = null;
String resourceName = null;
try {
noMatches = "";
resourceName = cms.getRequestContext().removeSiteRoot(res.getRootPath());
// compare the contents if necessary
if (filter.testContents()) {
byte[] contents;
// we only have to do this when comparing files
if (res.isFile()) {
contents = cms.readFile(resourceName, CmsResourceFilter.ALL).getContents();
if (!new String(storedResource.getContents()).equals(new String(contents))) {
noMatches += "[Content does not match]\n";
}
contents = null;
}
}
// compare the date created if necessary
if (filter.testDateCreated()) {
if (storedResource.getDateCreated() != res.getDateCreated()) {
noMatches += "[DateCreated "
+ storedResource.getDateCreated()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(storedResource.getDateCreated())
+ " != "
+ res.getDateCreated()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateCreated())
+ "]\n";
}
}
// compare the date expired if necessary
if (filter.testDateExpired()) {
if (storedResource.getDateExpired() != res.getDateExpired()) {
noMatches += "[DateExpired "
+ storedResource.getDateExpired()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(storedResource.getDateExpired())
+ " != "
+ res.getDateExpired()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateExpired())
+ "]\n";
}
}
// compare the date last modified if necessary
if (filter.testDateLastModified()) {
if (storedResource.getDateLastModified() != res.getDateLastModified()) {
noMatches += "[DateLastModified "
+ storedResource.getDateLastModified()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(storedResource.getDateLastModified())
+ " != "
+ res.getDateLastModified()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateLastModified())
+ "]\n";
}
}
// compare the date last released if necessary
if (filter.testDateReleased()) {
if (storedResource.getDateReleased() != res.getDateReleased()) {
noMatches += "[DateReleased "
+ storedResource.getDateReleased()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(storedResource.getDateReleased())
+ " != "
+ res.getDateReleased()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateReleased())
+ "]\n";
}
}
// compare the flags if necessary
if (filter.testFlags()) {
if (storedResource.getFlags() != res.getFlags()) {
noMatches += "[Flags " + storedResource.getFlags() + " != " + res.getFlags() + "]\n";
}
}
// compare the length if necessary
if (filter.testLength()) {
if (storedResource.getLength() != res.getLength()) {
noMatches += "[Length " + storedResource.getLength() + " != " + res.getLength() + "]\n";
}
}
// compare the sibling count if necessary
if (filter.testSiblingCount()) {
if (storedResource.getSiblingCount() != res.getSiblingCount()) {
noMatches += "[SiblingCount "
+ storedResource.getSiblingCount()
+ " != "
+ res.getSiblingCount()
+ "]\n";
}
}
// compare the lockstate if necessary
if (filter.testLock()) {
CmsLock resLock = cms.getLock(res);
if (!storedResource.getLock().equals(resLock)) {
noMatches += "[Lockstate " + storedResource.getLock() + " != " + resLock + "]\n";
}
}
// compare the name if necessary
if (filter.testName()) {
if (!storedResource.getName().equals(res.getName())) {
noMatches += "[Name " + storedResource.getName() + " != " + res.getName() + "]\n";
}
}
// compare the project last modified if necessary
if (filter.testProjectLastModified()) {
if (storedResource.getProjectLastModified() != res.getProjectLastModified()) {
noMatches += "[ProjectLastModified "
+ storedResource.getProjectLastModified()
+ " != "
+ res.getProjectLastModified()
+ "]\n";
}
}
// compare the properties if necessary
if (filter.testProperties()) {
noMatches += compareProperties(cms, resourceName, storedResource, null);
}
// compare the acl if necessary
if (filter.testAcl()) {
// compare the ACLs
noMatches += compareAccessLists(cms, resourceName, storedResource, null);
}
// compare the ace if necessary
if (filter.testAce()) {
// compate the ACEs
noMatches += compareAccessEntries(cms, resourceName, storedResource, null);
}
// compare the resource id if necessary
if (filter.testResourceId()) {
if (!storedResource.getResourceId().equals(res.getResourceId())) {
noMatches += "[ResourceId " + storedResource.getResourceId() + " != " + res.getResourceId() + "]\n";
}
}
// compare the state if necessary
if (filter.testState()) {
if (storedResource.getState() != res.getState()) {
noMatches += "[State " + storedResource.getState() + " != " + res.getState() + "]\n";
}
}
// compare the structure id if necessary
if (filter.testStructureId()) {
if (!storedResource.getStructureId().equals(res.getStructureId())) {
noMatches += "[StructureId "
+ storedResource.getStructureId()
+ " != "
+ res.getStructureId()
+ "]\n";
}
}
// compare the touched flag if necessary
if (filter.testTouched()) {
if (storedResource.isTouched() != res.isTouched()) {
noMatches += "[Touched " + storedResource.isTouched() + " != " + res.isTouched() + "]\n";
}
}
// compare the type if necessary
if (filter.testType()) {
if (storedResource.getType() != res.getTypeId()) {
noMatches += "[Type " + storedResource.getType() + " != " + res.getTypeId() + "]\n";
}
}
// compare the user created if necessary
if (filter.testUserCreated()) {
if (!storedResource.getUserCreated().equals(res.getUserCreated())) {
noMatches += createUserFailMessage(
cms,
"UserCreated",
storedResource.getUserLastModified(),
res.getUserLastModified());
noMatches += "\n";
}
}
// compare the user created if ne
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -