📄 testpublishing.java
字号:
assertDateContentAfter(cms, resName, offlineResource.getDateContent());
cms.getRequestContext().setCurrentProject(offlineProject);
// now publish and check again
OpenCms.getPublishManager().publishResource(cms, resName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContentAfter(cms, resName, offlineResource.getDateContent());
// test modifying just a property/attribute
cms.getRequestContext().setCurrentProject(offlineProject);
cms.lockResource(resName);
time = cms.readResource(resName).getDateContent();
synchronized (this) {
wait(50);
}
cms.writePropertyObject(resName, new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "abc", "def"));
cms.setDateExpired(resName, System.currentTimeMillis() + 100000, false);
assertDateContent(cms, resName, time);
// check the online project before publishing
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContentAfter(cms, resName, time);
// now publish and check again
cms.getRequestContext().setCurrentProject(offlineProject);
time = cms.readResource(resName).getDateContent();
synchronized (this) {
wait(50);
}
OpenCms.getPublishManager().publishResource(cms, resName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContentAfter(cms, resName, time);
// test creating a sibling
String sibName = "/newtext_sib.txt";
cms.getRequestContext().setCurrentProject(offlineProject);
time = cms.readResource(resName).getDateContent();
synchronized (this) {
wait(50);
}
CmsResource siblingOffline = cms.createSibling(resName, sibName, null);
assertDateContent(cms, sibName, time);
assertDateContent(cms, resName, time);
synchronized (this) {
wait(50);
}
// now publish and check
OpenCms.getPublishManager().publishResource(cms, sibName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContentAfter(cms, sibName, time);
assertDateContentAfter(cms, resName, time);
// test modifying the content of a sibling
cms.getRequestContext().setCurrentProject(offlineProject);
cms.lockResource(resName);
offlineFile = cms.readFile(resName);
time = System.currentTimeMillis();
synchronized (this) {
wait(50);
}
offlineFile.setContents("test".getBytes());
offlineFile = cms.writeFile(offlineFile);
offlineFile = cms.readFile(resName);
synchronized (this) {
wait(50);
}
assertTrue(offlineFile.getDateContent() < System.currentTimeMillis());
assertDateContentAfter(cms, resName, time);
assertDateContentAfter(cms, sibName, time);
// check the online project before publishing
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContentAfter(cms, resName, offlineResource.getDateContent());
siblingOffline = cms.readResource(sibName);
assertDateContentAfter(cms, sibName, siblingOffline.getDateContent());
// now publish and check again
cms.getRequestContext().setCurrentProject(offlineProject);
synchronized (this) {
wait(50);
}
OpenCms.getPublishManager().publishResource(cms, resName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContentAfter(cms, resName, offlineResource.getDateContent());
assertDateContentAfter(cms, sibName, offlineResource.getDateContent());
assertDateContent(cms, sibName, cms.readResource(resName).getDateContent());
long onlineTime = cms.readResource(resName).getDateContent();
// test moving
String movedName = "/newtext_mov.txt";
cms.getRequestContext().setCurrentProject(offlineProject);
cms.lockResource(resName);
time = cms.readResource(resName).getDateContent();
synchronized (this) {
wait(50);
}
// this will NOT write the content
cms.moveResource(resName, movedName);
offlineFile = cms.readFile(movedName);
assertDateContent(cms, movedName, time);
assertDateContent(cms, sibName, time);
// check the online project before publishing
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContent(cms, resName, onlineTime);
assertDateContent(cms, sibName, onlineTime);
// now publish and check again
cms.getRequestContext().setCurrentProject(offlineProject);
synchronized (this) {
wait(50);
}
OpenCms.getPublishManager().publishResource(cms, movedName);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(onlineProject);
assertDateContent(cms, movedName, time);
assertDateContent(cms, sibName, time);
}
/**
* Tests the publishing of a fresh created sibling.<p>
*
* take a modified resource:
* - create a sibling of it
* - publish only the sibling
* - compare online/offline versions of the sibling
*
* @throws Throwable if something goes wrong
*/
public void testPublishCopySibling() throws Throwable {
CmsObject cms = getCmsObject();
String source = "/folder1/page1.html";
echo("testing the publishing of a fresh created sibling");
long time = System.currentTimeMillis();
cms.lockResource(source);
cms.setDateLastModified(source, time, false);
synchronized (this) {
wait(100);
}
String destination = "/folder1/sibling2.html";
cms.copyResource(source, destination, CmsResource.COPY_AS_SIBLING);
OpenCms.getPublishManager().publishResource(cms, destination);
OpenCms.getPublishManager().waitWhileRunning();
long newTime = cms.readResource(destination).getDateLastModified();
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
assertEquals(
"File is unchanged and online date last modified is not the same as offline",
newTime,
cms.readResource(destination).getDateLastModified());
assertState(cms, destination, CmsResource.STATE_UNCHANGED);
}
/**
* Test publishing deleted files.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishDeletedFiles() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publish deleted files");
String resource1 = "/folder2/image1_new.gif";
String resource2 = "/folder2/image1_sibling1.gif";
String resource3 = "/folder2/image1_sibling2.gif";
String resource4 = "/folder2/image1_sibling3.gif";
CmsProject onlineProject = cms.readProject("Online");
CmsProject offlineProject = cms.readProject("Offline");
// publish a deleted resource without siblings
//
// delete the resources
cms.lockResource(resource1);
cms.deleteResource(resource1, CmsResource.DELETE_PRESERVE_SIBLINGS);
cms.unlockResource(resource1);
OpenCms.getPublishManager().publishResource(cms, resource1);
OpenCms.getPublishManager().waitWhileRunning();
// the online file must be deleted
cms.getRequestContext().setCurrentProject(onlineProject);
try {
cms.readResource(resource1);
fail("Resource " + resource1 + " was not deleted online");
} catch (CmsVfsResourceNotFoundException e) {
// ok
}
cms.getRequestContext().setCurrentProject(offlineProject);
// publish a deleted resource with siblings,
// delete the siblings also, but publish only the resource itself
// delete the resources
cms.lockResource(resource2);
cms.deleteResource(resource2, CmsResource.DELETE_REMOVE_SIBLINGS);
cms.unlockResource(resource2);
// this test makes only sense when siblings are published
OpenCms.getPublishManager().publishResource(
cms,
resource2,
false,
new CmsShellReport(cms.getRequestContext().getLocale()));
OpenCms.getPublishManager().waitWhileRunning();
// the files must be unlocked
List lockedResources = cms.getLockedResources("/folder2", CmsLockFilter.FILTER_ALL);
assertTrue(lockedResources.isEmpty());
// the online file must be deleted
cms.getRequestContext().setCurrentProject(onlineProject);
try {
cms.readResource(resource2);
fail("Resource " + resource2 + " was not deleted online");
} catch (CmsVfsResourceNotFoundException e) {
// ok
}
// the other siblings must still be there
try {
cms.readResource(resource3);
} catch (CmsException e) {
fail("Resource " + resource3 + " error:" + e);
}
try {
cms.readResource(resource4);
} catch (CmsException e) {
fail("Resource " + resource4 + " error:" + e);
}
cms.getRequestContext().setCurrentProject(offlineProject);
// in the offline project, the siblings must be still marked as deleted
assertState(cms, resource3, CmsResource.STATE_DELETED);
assertState(cms, resource4, CmsResource.STATE_DELETED);
// publish a deleted resource with siblings, delete the siblings
//
OpenCms.getPublishManager().publishResource(
cms,
resource3,
true,
new CmsShellReport(cms.getRequestContext().getLocale()));
OpenCms.getPublishManager().waitWhileRunning();
// the online files must be deleted
cms.getRequestContext().setCurrentProject(onlineProject);
try {
cms.readResource(resource3);
fail("Resource " + resource3 + " was not deleted online");
} catch (CmsVfsResourceNotFoundException e) {
// ok
}
try {
cms.readResource(resource4);
fail("Resource " + resource4 + " was not deleted online");
} catch (CmsVfsResourceNotFoundException e) {
// ok
}
cms.getRequestContext().setCurrentProject(offlineProject);
}
/**
* Tests the publishing of deleted siblings.<p>
*
* take 2 siblings (s1 and s2):
* - delete one
* - publish the deleted one
* - the remaining sibling should be readable in online project
* - the deleted sibling should be eligible for restoration
*
* @throws Throwable if something goes wrong
*/
public void testPublishDeletedSiblings() throws Throwable {
CmsObject cms = getCmsObject();
String source = "/testdeletesib1.html";
String sibling = "/testdeletesib2.html";
echo("testing publishing of deleted siblings");
// create the siblings
CmsResource src = cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
CmsFile file = cms.readFile(src);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -