📄 testsiblings.java
字号:
assertState(cms, source, CmsResourceState.STATE_UNCHANGED);
assertState(cms, target, CmsResourceState.STATE_UNCHANGED);
// now check deleting the sibling
cms.lockResource(source);
cms.deleteResource(source, CmsResource.DELETE_REMOVE_SIBLINGS);
assertState(cms, source, CmsResourceState.STATE_DELETED);
// the sibling has not been deleted, since the current user has no write permissions on the sibling!
assertState(cms, target, CmsResourceState.STATE_UNCHANGED);
// check the publish list
pl = OpenCms.getPublishManager().getPublishList(cms, cms.readResource(source, CmsResourceFilter.ALL), true);
assertEquals(2, pl.size());
assertTrue(pl.getFileList().contains(cms.readResource(source, CmsResourceFilter.ALL)));
assertTrue(pl.getFileList().contains(cms.readResource("/folder1/image1_sibling.gif", CmsResourceFilter.ALL)));
// publish
OpenCms.getPublishManager().publishResource(cms, source, true, new CmsShellReport(Locale.ENGLISH));
OpenCms.getPublishManager().waitWhileRunning();
assertFalse(cms.existsResource(source));
// the sibling has not been published!
assertTrue(cms.existsResource(target));
assertState(cms, target, CmsResourceState.STATE_UNCHANGED);
assertSiblingCount(cms, target, 1);
}
/**
* Tests the "copy as new sibling" function.<p>
*
* @throws Throwable if something goes wrong
*/
public void testSiblingsCreate() throws Throwable {
CmsObject cms = getCmsObject();
String source = "/folder1/image1.gif";
String target = "/folder1/image1_sibling.gif";
echo("Creating a new sibling " + target + " from " + source);
createSibling(this, cms, source, target);
}
/**
* Tests creating 2 new siblings and publishing just one of them.<p>
*
* @throws Throwable if something goes wrong
*/
public void testSiblingsCreateIssue() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing creating 2 new siblings and publishing just one of them");
String source = "/folder1/newsource.txt";
cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
String target = "/folder1/newsibling.txt";
cms.createSibling(source, target, null);
assertState(cms, source, CmsResourceState.STATE_NEW);
assertState(cms, target, CmsResourceState.STATE_NEW);
OpenCms.getPublishManager().publishResource(cms, source);
OpenCms.getPublishManager().waitWhileRunning();
assertState(cms, source, CmsResourceState.STATE_UNCHANGED);
assertState(cms, target, CmsResourceState.STATE_NEW);
}
/**
* Tests if setting the flags of a sibling will do any modifications to other siblings.<p>
*
* @throws Throwable if something goes wrong
*/
public void testSiblingStateIssue() throws Throwable {
echo("Tests issue with resource state and siblings");
CmsObject cms = getCmsObject();
// part 1: changes to the fields that are part of the resource table
String resource1 = "/folder1/page1.html";
String sibling1 = "/folder1/sibling1.html";
// create a sibling
cms.copyResource(resource1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, resource1, CmsResource.STATE_UNCHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// now set the flags for the sibling
cms.chflags(sibling1, 1024);
cms.chtype(sibling1, CmsResourceTypeBinary.getStaticTypeId());
// verify the state of the resources after the change
assertState(cms, resource1, CmsResource.STATE_CHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// part 2: now the same operation with a new copy
String copy1 = "/folder1/copy1.html";
sibling1 = "/folder1/siblingofcopy1.html";
// create a copy
cms.copyResource(resource1, copy1, CmsResource.COPY_AS_NEW);
cms.copyResource(copy1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// now set the flags for the sibling
cms.chflags(sibling1, 1024);
cms.chtype(sibling1, CmsResourceTypeBinary.getStaticTypeId());
// verify the state of the resources after the change
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// part 3: changes to the fields that are part of the structure table
resource1 = "/folder1/page2.html";
sibling1 = "/folder1/sibling2.html";
// create a sibling
cms.copyResource(resource1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, resource1, CmsResource.STATE_UNCHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// after changes of dates the resource states must be the same
cms.setDateExpired(sibling1, System.currentTimeMillis() + 1000, false);
cms.setDateReleased(sibling1, System.currentTimeMillis() - 1000, false);
// verify the state of the resources after the change
assertState(cms, resource1, CmsResource.STATE_UNCHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// step 4: changes to the fields that are part of the resource table
cms.setDateLastModified(sibling1, System.currentTimeMillis(), false);
// verify the state of the resources after the change
assertState(cms, resource1, CmsResource.STATE_CHANGED);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// part 5: now the same operation with a new copy
copy1 = "/folder1/copy2.html";
sibling1 = "/folder1/siblingofcopy2.html";
// create a copy
cms.copyResource(resource1, copy1, CmsResource.COPY_AS_NEW);
cms.copyResource(copy1, sibling1, CmsResource.COPY_AS_SIBLING);
// verify the state of the resources
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// change date of last modification
cms.setDateLastModified(sibling1, System.currentTimeMillis(), false);
// verify the state of the resources after the change
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
// modify release info
cms.setDateExpired(sibling1, System.currentTimeMillis() + 1000, false);
cms.setDateReleased(sibling1, System.currentTimeMillis() - 1000, false);
// verify the state of the resources after the change
assertState(cms, copy1, CmsResource.STATE_NEW);
assertState(cms, sibling1, CmsResource.STATE_NEW);
}
/**
* Tests an issue present in OpenCms 7 where online content was not replaced after publish.<p>
*
* @throws Exception if the test fails
*/
public void testSiblingsV7PublishIssue() throws Exception {
echo("Tests OpenCms v7 publish issue with siblings");
CmsObject cms = getCmsObject();
CmsProject offlineProject = cms.getRequestContext().currentProject();
CmsProject onlineProject = cms.readProject(CmsProject.ONLINE_PROJECT_ID);
// first we create a complete new folder as base for the test
String folder = "/publish_v7issue/";
cms.createResource(folder, CmsResourceTypeFolder.getStaticTypeId());
String firstContent = "This is the first content";
byte[] firstContentBytes = firstContent.getBytes();
CmsProperty firstTitleProperty = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "The first title", null);
List firstProperties = new ArrayList();
firstProperties.add(firstTitleProperty);
String source = folder + "test_en.txt";
cms.createResource(source, CmsResourceTypePlain.getStaticTypeId(), firstContentBytes, firstProperties);
assertState(cms, folder, CmsResourceState.STATE_NEW);
assertState(cms, source, CmsResourceState.STATE_NEW);
// publish the folder
OpenCms.getPublishManager().publishResource(cms, folder);
OpenCms.getPublishManager().waitWhileRunning();
// check both online and offline project
cms.getRequestContext().setCurrentProject(onlineProject);
assertState(cms, folder, CmsResourceState.STATE_UNCHANGED);
assertState(cms, source, CmsResourceState.STATE_UNCHANGED);
assertContent(cms, source, firstContentBytes);
cms.getRequestContext().setCurrentProject(offlineProject);
assertState(cms, folder, CmsResourceState.STATE_UNCHANGED);
assertState(cms, source, CmsResourceState.STATE_UNCHANGED);
assertContent(cms, source, firstContentBytes);
// create a new sibling using the "copy as" option
String sibling = folder + "test_de.txt";
copyResourceAsSibling(this, cms, source, sibling);
assertState(cms, sibling, CmsResourceState.STATE_NEW);
assertContent(cms, sibling, firstContentBytes);
// change the content (this should affect both siblings)
String secondContent = "++++++++ This is the SECOND content ++++++++++";
byte[] secondContentBytes = secondContent.getBytes();
CmsFile sourceFile = cms.readFile(source);
sourceFile.setContents(secondContentBytes);
cms.writeFile(sourceFile);
assertState(cms, sibling, CmsResourceState.STATE_NEW);
assertState(cms, source, CmsResourceState.STATE_CHANGED);
assertContent(cms, sibling, secondContentBytes);
assertContent(cms, source, secondContentBytes);
// now change a property on the first sibling
CmsProperty secondTitleProperty = new CmsProperty(
CmsPropertyDefinition.PROPERTY_TITLE,
"The SECOND title",
null);
cms.writePropertyObject(source, secondTitleProperty);
// publish the folder again
OpenCms.getPublishManager().publishResource(cms, folder);
OpenCms.getPublishManager().waitWhileRunning();
// get the content first for printing it to the console
cms.getRequestContext().setCurrentProject(onlineProject);
String contentOnline = new String(cms.readFile(source).getContents());
cms.getRequestContext().setCurrentProject(offlineProject);
String contentOffline = new String(cms.readFile(source).getContents());
echo("Online Content:\n" + contentOnline);
echo("Offline Content:\n" + contentOffline);
// check both online and offline project
cms.getRequestContext().setCurrentProject(offlineProject);
assertState(cms, folder, CmsResourceState.STATE_UNCHANGED);
assertState(cms, source, CmsResourceState.STATE_UNCHANGED);
assertContent(cms, sibling, secondContentBytes);
assertContent(cms, source, secondContentBytes);
cms.getRequestContext().setCurrentProject(onlineProject);
assertState(cms, folder, CmsResourceState.STATE_UNCHANGED);
assertState(cms, source, CmsResourceState.STATE_UNCHANGED);
assertContent(cms, sibling, secondContentBytes);
assertContent(cms, source, secondContentBytes);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -