📄 testpublishing.java
字号:
assertState(cms, target1, CmsResource.STATE_UNCHANGED);
}
/**
* Test publishing new files.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishNewFiles() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publish new files");
String source = "/folder2/subfolder21/image1.gif";
String destination1 = "/folder2/image1_new.gif";
String destination2 = "/folder2/image1_sibling1.gif";
String destination3 = "/folder2/image1_sibling2.gif";
String destination4 = "/folder2/image1_sibling3.gif";
CmsProject onlineProject = cms.readProject("Online");
CmsProject offlineProject = cms.readProject("Offline");
// make four copies of a file to be published later
cms.copyResource(source, destination1, CmsResource.COPY_AS_NEW);
cms.copyResource(source, destination2, CmsResource.COPY_AS_SIBLING);
cms.copyResource(source, destination3, CmsResource.COPY_AS_SIBLING);
cms.copyResource(source, destination4, CmsResource.COPY_AS_SIBLING);
storeResources(cms, destination1);
storeResources(cms, destination2);
storeResources(cms, destination3);
storeResources(cms, destination4);
// unlock all new resources
// do not neet do unlock destination3 as it is a sibling of destination2
cms.unlockResource(destination1);
cms.unlockResource(destination2);
// publish a new resource
//
OpenCms.getPublishManager().publishResource(cms, destination1);
OpenCms.getPublishManager().waitWhileRunning();
// the file must be now available in the online project
cms.getRequestContext().setCurrentProject(onlineProject);
try {
cms.readResource(destination1);
} catch (CmsException e) {
fail("Resource " + destination1 + " not found in online project:" + e);
}
assertFilter(cms, destination1, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
// check if the file in the offline project is unchanged now
cms.getRequestContext().setCurrentProject(offlineProject);
assertState(cms, destination1, CmsResource.STATE_UNCHANGED);
// publish a sibling without publishing other siblings
//
OpenCms.getPublishManager().publishResource(cms, destination2);
OpenCms.getPublishManager().waitWhileRunning();
// the file must be now available in the online project
cms.getRequestContext().setCurrentProject(onlineProject);
try {
cms.readResource(destination2);
} catch (CmsException e) {
fail("Resource " + destination2 + " not found in online project:" + e);
}
// the other siblings must not be available in the online project yet
try {
cms.readResource(destination3);
fail("Resource " + destination3 + " should not available online yet");
} catch (CmsVfsResourceNotFoundException e) {
// ok
} catch (CmsException e) {
fail("Resource " + destination3 + " error:" + e);
}
try {
cms.readResource(destination4);
fail("Resource " + destination4 + " should not available online yet");
} catch (CmsVfsResourceNotFoundException e) {
// ok
} catch (CmsException e) {
fail("Resource " + destination4 + " error:" + e);
}
assertFilter(cms, destination2, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
// check if the file in the offline project is unchanged now
cms.getRequestContext().setCurrentProject(offlineProject);
assertState(cms, destination2, CmsResource.STATE_UNCHANGED);
// the other siblings in the offline project must still be shown as new
assertState(cms, destination3, CmsResource.STATE_NEW);
assertState(cms, destination4, CmsResource.STATE_NEW);
// publish a sibling and all other siblings of it
//
OpenCms.getPublishManager().publishResource(
cms,
destination3,
true,
new CmsShellReport(cms.getRequestContext().getLocale()));
OpenCms.getPublishManager().waitWhileRunning();
// the file and its siblings must be now available in the online project
cms.getRequestContext().setCurrentProject(onlineProject);
try {
cms.readResource(destination3);
} catch (CmsException e) {
fail("Resource " + destination3 + " not found in online project:" + e);
}
try {
cms.readResource(destination4);
} catch (CmsException e) {
fail("Resource " + destination4 + " not found in online project:" + e);
}
assertFilter(cms, destination3, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
assertFilter(cms, destination4, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
// check if the file in the offline project is unchanged now
cms.getRequestContext().setCurrentProject(offlineProject);
assertState(cms, destination3, CmsResource.STATE_UNCHANGED);
assertState(cms, destination4, CmsResource.STATE_UNCHANGED);
}
/**
* Test publishing files within a new unpublished folder.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishNewFilesInNewFolder() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publishing new files in new folder");
String source = "/folder1/image1.gif";
String newFolder = "/new_folder/";
String newFile = newFolder + "new_file";
String newSibling = newFolder + "new_sibling";
cms.createResource(newFolder, CmsResourceTypeFolder.getStaticTypeId());
cms.unlockResource(newFolder);
storeResources(cms, newFolder);
// change to test project
CmsProject project = getTestProject(cms);
cms.getRequestContext().setCurrentProject(project);
cms.copyResource(source, newFile, CmsResource.COPY_AS_NEW);
cms.unlockResource(newFile);
cms.copyResource(source, newSibling, CmsResource.COPY_AS_SIBLING);
cms.unlockResource(newSibling);
// direct publish of the new file will not publish the new file
echo("Publishing the resource directly");
storeResources(cms, newFile);
boolean error = true;
try {
// this will generate an error in the log, ensure the test still continues
OpenCmsTestLogAppender.setBreakOnError(false);
OpenCms.getPublishManager().publishResource(cms, newFile);
OpenCms.getPublishManager().waitWhileRunning();
} catch (CmsMultiException e) {
CmsVfsException ex = (CmsVfsException)e.getExceptions().get(0);
if (ex.getMessageContainer().getKey() == org.opencms.db.Messages.ERR_DIRECT_PUBLISH_PARENT_NEW_2) {
error = false;
}
}
// reset log to stop test on error
OpenCmsTestLogAppender.setBreakOnError(true);
if (error) {
fail("A resource in a new folder could be published without generating an error!");
}
assertFilter(cms, newFile, OpenCmsTestResourceFilter.FILTER_EQUAL);
// direct publish of another sibling will not publish the new sibling
echo("Publishing another sibling");
cms.lockResource(source);
cms.setDateLastModified(source, System.currentTimeMillis(), false);
cms.unlockResource(source);
storeResources(cms, newSibling);
OpenCms.getPublishManager().publishResource(
cms,
source,
true,
new CmsShellReport(cms.getRequestContext().getLocale()));
OpenCms.getPublishManager().waitWhileRunning();
assertFilter(cms, newSibling, OpenCmsTestResourceFilter.FILTER_EQUAL);
// publishing the test project will not publish the new file or the new sibling
echo("Publishing the test project");
OpenCms.getPublishManager().publishProject(cms);
OpenCms.getPublishManager().waitWhileRunning();
assertFilter(cms, newFile, OpenCmsTestResourceFilter.FILTER_EQUAL);
assertFilter(cms, newSibling, OpenCmsTestResourceFilter.FILTER_EQUAL);
// publishing the offline project will publish the folder but not the resources
echo("Publishing the offline project");
cms.getRequestContext().setCurrentProject(cms.readProject("Offline"));
OpenCms.getPublishManager().publishProject(cms);
OpenCms.getPublishManager().waitWhileRunning();
assertFilter(cms, newFolder, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
assertState(cms, newFolder, CmsResource.STATE_UNCHANGED);
assertFilter(cms, newFile, OpenCmsTestResourceFilter.FILTER_EQUAL);
assertFilter(cms, newSibling, OpenCmsTestResourceFilter.FILTER_EQUAL);
// publishing the test proejct again will now publish the resources
echo("Publishing the test project again");
cms.getRequestContext().setCurrentProject(project);
OpenCms.getPublishManager().publishProject(cms);
OpenCms.getPublishManager().waitWhileRunning();
assertFilter(cms, newFile, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
assertState(cms, newFile, CmsResource.STATE_UNCHANGED);
assertFilter(cms, newSibling, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
assertState(cms, newSibling, CmsResource.STATE_UNCHANGED);
}
/**
* Test publishing a project with an iteration.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishProjectGalore() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publishing a project with an iteration");
// publish project with several resources
String resourcename = "/";
cms.lockResource(resourcename);
cms.setDateLastModified(resourcename, System.currentTimeMillis(), true);
for (int i = 0; i < 10; i++) { // size of publish queue
OpenCms.getPublishManager().publishProject(cms);
}
OpenCms.getPublishManager().waitWhileRunning();
List pubHistory = OpenCms.getPublishManager().getPublishHistory();
assertEquals(10, pubHistory.size());
CmsPublishJobFinished pubJob = (CmsPublishJobFinished)pubHistory.get(0);
assertEquals(13 + 51, pubJob.getSize()); // folders + files
for (int i = 1; i < 10; i++) {
pubJob = (CmsPublishJobFinished)pubHistory.get(i);
assertEquals("pubJob: " + i, 0, pubJob.getSize());
}
}
/**
* Tests publishing resources within a distinct project.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishProjectLastmodified() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publishing a distinct project");
String path = "/folder1";
String res1 = path + "/page1.html";
String res2 = path + "/page2.html";
long timestamp = System.currentTimeMillis();
cms.getRequestContext().setCurrentProject(cms.readProject("Online"));
storeResources(cms, res1);
// change first resource in the offline project
cms.getRequestContext().setCurrentProject(cms.readProject("Offline"));
cms.lockResource(res1);
cms.setDateLastModified(res1, timestamp, false);
cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
// create a new project
CmsProject project = getTestProject(cms);
cms.getRequestContext().setCurrentProject(project);
cms.copyResourceToProject(path);
// and change another resource in this project
cms.lockResource(res2);
cms.setDateLastModified(res2, timestamp, false);
cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
storeResources(cms, res2);
// when the project is published, only the second resource will be published
OpenCms.getPublishManager().publishProject(cms);
OpenCms.getPublishManager().waitWhileRunning();
cms.getRequestContext().setCurrentProject(cms.readProject("Online"));
assertFilter(cms, res1, OpenCmsTestResourceFilter.FILTER_EQUAL);
assertFilter(cms, res2, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);
assertDateLastModified(cms, res2, timestamp);
echo("Testing publishing in different projects");
// change back to the test project, create a new resource
String res3 = path + "/testPublishProjectLastmodified.txt";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -