📄 opencmstestcase.java
字号:
+ "]");
}
} catch (CmsException e) {
fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e));
}
}
/**
* Compares the current date created of a resource with a given date.<p>
*
* @param cms the CmsObject
* @param resourceName the name of the resource to compare
* @param dateCreated the creation date
*/
public void assertDateCreated(CmsObject cms, String resourceName, long dateCreated) {
try {
// get the actual resource from the vfs
CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL);
if (res.getDateCreated() != dateCreated) {
fail("[DateCreated "
+ dateCreated
+ " i.e. "
+ CmsDateUtil.getHeaderDate(dateCreated)
+ " != "
+ res.getDateCreated()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateCreated())
+ "]");
}
} catch (CmsException e) {
fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e));
}
}
/**
* Tests if the the creation date of a resource is later then a given date.<p>
*
* @param cms the CmsObject
* @param resourceName the name of the resource to compare
* @param dateCreated the creation date
*/
public void assertDateCreatedAfter(CmsObject cms, String resourceName, long dateCreated) {
try {
// get the actual resource from the vfs
CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL);
if (res.getDateCreated() < dateCreated) {
fail("[DateCreated "
+ dateCreated
+ " i.e. "
+ 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 than the 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 != null) && (e2 != 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 jobs are internally equal.<p>
* (May have different wrapper classes)
*
* @param j1 first job to compare
* @param j2 second job to compare
* @param comparePublishLists if the publish lists should be compared, too
* @param compareTime if the timestamps should be compared, too
*/
public void assertEquals(
CmsPublishJobBase j1,
CmsPublishJobBase j2,
boolean comparePublishLists,
boolean compareTime) {
CmsPublishJobInfoBean job1 = new OpenCmsTestPublishJobBase(j1).getInfoBean();
CmsPublishJobInfoBean job2 = new OpenCmsTestPublishJobBase(j2).getInfoBean();
if (!(job1.getPublishHistoryId().equals(job2.getPublishHistoryId())
&& job1.getProjectName().equals(job2.getProjectName())
&& job1.getUserId().equals(job2.getUserId())
&& job1.getLocale().equals(job2.getLocale())
&& (job1.getFlags() == job2.getFlags()) && (job1.getSize() == job2.getSize()))) {
fail("Publish jobs are not equal");
}
if (compareTime) {
if (!((job1.getEnqueueTime() == job2.getEnqueueTime()) && (job1.getStartTime() == job2.getStartTime()) && (job1.getFinishTime() == job2.getFinishTime()))) {
fail("Publish jobs do not have the same timestamps");
}
}
if (comparePublishLists) {
if (!job1.getPublishList().toString().equals(job2.getPublishList().toString())) {
fail("Publish jobs do not have the same publish list");
}
}
}
/**
* 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)");
}
if ((d1 != null) && (d2 != 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(cms.getSitePath(resource));
// compare the current resource with the stored resource
assertFilter(cms, storedResource, resource, filter);
} catch (Exception e) {
fail("cannot read resource " + cms.getSitePath(resource) + " " + 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 content if necessary
if (filter.testDateContent()) {
if (storedResource.getDateContent() != res.getDateContent()) {
noMatches += "[DateContent "
+ storedResource.getDateContent()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(storedResource.getDateContent())
+ " != "
+ res.getDateContent()
+ " i.e. "
+ CmsDateUtil.getHeaderDate(res.getDateContent())
+ "]\n";
}
}
// 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";
}
}
if (filter.testDateCreatedSec()) {
if ((storedResource.getDateCreated() / 1000) != (res.getDateCreated() / 1000)) {
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.getDa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -