📄 testpublishissues.java
字号:
OpenCms.getDefaultUsers().getGroupUsers(),
OpenCms.getDefaultUsers().getGroupUsers());
CmsProject projectB = cms.readProject("projectB");
cms.getRequestContext().setCurrentProject(projectB);
cms.copyResourceToProject("/");
// check if the project was created as planned
List resources = cms.readProjectResources(projectB);
assertEquals(1, resources.size());
assertEquals("/sites/default/", (String)resources.get(0));
// TODO: The wanted behaviour in this case must be defined!
}
/**
* Tests multiple creation of a project with the same name.<p>
*
* @throws Throwable if something goes wrong
*/
public void testMultipleProjectCreation() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing multiple creation of a project with the same name");
String projectName = "projectX";
boolean gotException;
// try to read a non-existant project
gotException = false;
try {
cms.readProject(projectName);
} catch (CmsException e) {
gotException = true;
}
if (! gotException) {
fail("Required exception was not thrown!");
}
// create the project
cms.createProject(
projectName,
"Test project",
OpenCms.getDefaultUsers().getGroupUsers(),
OpenCms.getDefaultUsers().getGroupUsers());
CmsProject project = cms.readProject(projectName);
cms.getRequestContext().setCurrentProject(project);
cms.copyResourceToProject("/folder1/");
// check if the project was created as planned
List resources = cms.readProjectResources(project);
assertEquals(1, resources.size());
assertEquals("/sites/default/folder1/", (String)resources.get(0));
// copy the root folder of the sito to the project - this must remove the "/folder1/" folder
cms.copyResourceToProject("/");
resources = cms.readProjectResources(project);
assertEquals(1, resources.size());
assertEquals("/sites/default/", (String)resources.get(0));
// now create the project again - this must throw an exception
gotException = false;
CmsProject newProject = cms.createProject(
projectName,
"Test project 2nd time",
OpenCms.getDefaultUsers().getGroupUsers(),
OpenCms.getDefaultUsers().getGroupUsers());
// TODO: above create statement fails "sometimes" - check table contraints (?)
// check if the projects have different ids
int id1 = project.getId();
int id2 = newProject.getId();
if (id1 == id2) {
fail("Two different projects created with same name have the same id!");
}
// read the projects again and asserts same name but differnet description
project = cms.readProject(id1);
newProject = cms.readProject(id2);
assertEquals(project.getName(), newProject.getName());
if (project.getDescription().equals(newProject.getDescription())) {
fail("Projects should have differnet descriptions!");
}
}
/**
* Tests publish scenario "C".<p>
*
* This scenario is described as follows:
* Direct publishing of folders containing subfolders skips all changed subfolders e.g. direct publish of /folder1/
* publishes /folder1/ and /folder1/index.html/, but not /folder1/subfolder11/.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishScenarioC() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publish scenario C");
long touchTime = System.currentTimeMillis();
cms.lockResource("/folder1/");
cms.setDateLastModified("/folder1/", touchTime, false);
cms.setDateLastModified("/folder1/index.html", touchTime, false);
cms.setDateLastModified("/folder1/subfolder11/", touchTime, false);
cms.setDateLastModified("/folder1/subfolder11/index.html", touchTime, false);
cms.unlockResource("/folder1/");
cms.publishResource("/folder1/");
assertState(cms, "/folder1/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder1/index.html", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder1/subfolder11/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder1/subfolder11/index.html", CmsResource.STATE_UNCHANGED);
cms.createResource("/folder_a/", CmsResourceTypeFolder.getStaticTypeId());
cms.createResource("/folder_a/file_a.txt", CmsResourceTypePlain.getStaticTypeId());
cms.createResource("/folder_a/folder_b/", CmsResourceTypeFolder.getStaticTypeId());
cms.createResource("/folder_a/folder_b/file_b.txt", CmsResourceTypePlain.getStaticTypeId());
cms.unlockResource("/folder_a/");
cms.publishResource("/folder_a/");
assertState(cms, "/folder_a/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder_a/file_a.txt", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder_a/folder_b/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder_a/folder_b/file_b.txt", CmsResource.STATE_UNCHANGED);
}
/**
* Tests publish scenario "D".<p>
*
* This scenario is described as follows:
* Direct publishing of folders containing subfolders skips all (sibling)
* resources in subfolders.
* e.g. direct publish of /folder2/folder1/
* publishes /folder2/folder1/ and /folder2/folder1/index.html/,
* but not /folder2/folder1/subfolder11/index.html.<p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishScenarioD() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publish scenario D");
// change to the offline project
CmsProject project = cms.readProject("Offline");
cms.getRequestContext().setCurrentProject(project);
cms.lockResource("/folder1/");
// copy the whole folder creating siblings of all resources
cms.copyResource("/folder1/", "/folder2/folder1", CmsResource.COPY_AS_SIBLING);
cms.unlockResource("/folder1/");
// direct publish the new folder
cms.unlockResource("/folder2/folder1/");
cms.publishResource("/folder2/folder1/");
assertState(cms, "/folder2/folder1/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/index.html", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder11/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder11/index.html", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder11/subsubfolder111/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder11/subsubfolder111/jsp.jsp", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder12/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder12/index.html", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder12/subsubfolder121/", CmsResource.STATE_UNCHANGED);
assertState(cms, "/folder2/folder1/subfolder12/subsubfolder121/index.html", CmsResource.STATE_UNCHANGED);
}
/**
* Tests publish scenario "E".<p>
*
* This scenario is described as follows:
* Deletion of folders containing shared locked siblings after copying
* a folder creating siblings into a new folder and publication. <p>
*
* @throws Throwable if something goes wrong
*/
public void testPublishScenarioE() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publish scenario E");
// change to the offline project
CmsProject project = cms.readProject("Offline");
cms.getRequestContext().setCurrentProject(project);
// create folder
cms.createResource("/test", CmsResourceTypeFolder.getStaticTypeId());
// create siblings
cms.copyResource("/folder1/subfolder12/subsubfolder121", "/test/subtest", CmsResource.COPY_AS_SIBLING);
cms.unlockResource("/test");
// publish
cms.publishResource("/test");
// lock sibling
cms.lockResource("/folder1/subfolder12/subsubfolder121/image1.gif");
// login as user test2
cms.addUserToGroup("test2", "Projectmanagers");
cms.loginUser("test2", "test2");
cms.getRequestContext().setCurrentProject(project);
// check lock
assertEquals(cms.getLock("/test/subtest/image1.gif").getType(), CmsLock.TYPE_SHARED_EXCLUSIVE);
// delete the folder
cms.lockResource("/test/subtest");
cms.deleteResource("/test/subtest", CmsResource.DELETE_PRESERVE_SIBLINGS);
cms.unlockResource("/test/subtest");
// publish
cms.publishResource("/test");
}
/**
* Tests publish scenario "publish all Siblings".<p>
*
* This scenario is described as follows:
* If a direct publish is made, and the option "publish all siblings" is selected,
* a file that contains siblings will be added multiple times to the publish list,
* causing a primary key collision in the publish history table.<p>
*
* @throws Throwable if something goes wrong
*/
public void testDirectPublishWithSiblings() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing publish scenario using 'publish all Siblings'");
cms.lockResource("/folder1/");
cms.setDateLastModified("/folder1/", System.currentTimeMillis(), true);
cms.unlockResource("/folder1/");
// publish the project (this did cause an exception because of primary key violation!)
CmsUUID publishId = cms.publishResource("/folder1/", true, new CmsShellReport(cms.getRequestContext().getLocale()));
// read the published resources from the history
List publishedResources = cms.readPublishedResources(publishId);
// make sure the publish history contains the required amount of resources
assertEquals(35, publishedResources.size());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -