📄 testproperty.java
字号:
* @throws Throwable if something goes wrong
*/
public static void createProperties(OpenCmsTestCase tc, CmsObject cms, String resource1, List propertyList1)
throws Throwable {
tc.storeResources(cms, resource1);
long timestamp = System.currentTimeMillis();
cms.lockResource(resource1);
cms.writePropertyObjects(resource1, propertyList1);
cms.unlockResource(resource1);
// now evaluate the result
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
// the properties must be new
tc.assertPropertyNew(cms, resource1, propertyList1);
}
/**
* Test the writeProperty method to create one property.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to add a propery
* @param property1 the property to create
* @throws Throwable if something goes wrong
*/
public static void createProperty(OpenCmsTestCase tc, CmsObject cms, String resource1, CmsProperty property1)
throws Throwable {
tc.storeResources(cms, resource1);
long timestamp = System.currentTimeMillis();
cms.lockResource(resource1);
cms.writePropertyObject(resource1, property1);
cms.unlockResource(resource1);
// now evaluate the result
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
// the property must be new
tc.assertPropertyNew(cms, resource1, property1);
}
/**
* Test the writeProperty method to remove a list of properties.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to remove the properies
* @param propertyList1 the properties to remove
* @throws Throwable if something goes wrong
*/
public static void removeProperties(OpenCmsTestCase tc, CmsObject cms, String resource1, List propertyList1)
throws Throwable {
tc.storeResources(cms, resource1);
long timestamp = System.currentTimeMillis();
cms.lockResource(resource1);
cms.writePropertyObjects(resource1, propertyList1);
cms.unlockResource(resource1);
// now evaluate the result
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
// the properties must have been removed
tc.assertPropertyRemoved(cms, resource1, propertyList1);
}
/**
* Test the writeProperty method to remove one property.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to remove a propery
* @param property1 the property to remove
* @throws Throwable if something goes wrong
*/
public static void removeProperty(OpenCmsTestCase tc, CmsObject cms, String resource1, CmsProperty property1)
throws Throwable {
tc.storeResources(cms, resource1);
long timestamp = System.currentTimeMillis();
cms.lockResource(resource1);
cms.writePropertyObject(resource1, property1);
cms.unlockResource(resource1);
// now evaluate the result
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
// the property must be removed
tc.assertPropertyRemoved(cms, resource1, property1);
}
/**
* Test the writeProperty method with a list of properties.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to write the properies
* @param propertyList1 the properties to write
* @throws Throwable if something goes wrong
*/
public static void writeProperties(OpenCmsTestCase tc, CmsObject cms, String resource1, List propertyList1)
throws Throwable {
tc.storeResources(cms, resource1);
long timestamp = System.currentTimeMillis();
cms.lockResource(resource1);
cms.writePropertyObjects(resource1, propertyList1);
cms.unlockResource(resource1);
// now evaluate the result
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resource1, CmsResource.STATE_CHANGED);
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
// the property must have the new value
tc.assertPropertyChanged(cms, resource1, propertyList1);
}
/**
* Test the writeProperty method with one property.<p>
* @param tc the OpenCmsTestCase
* @param cms the CmsObject
* @param resource1 the resource to write a propery
* @param property1 the property to write
* @throws Throwable if something goes wrong
*/
public static void writeProperty(OpenCmsTestCase tc, CmsObject cms, String resource1, CmsProperty property1)
throws Throwable {
tc.storeResources(cms, resource1);
long timestamp = System.currentTimeMillis();
cms.lockResource(resource1);
cms.writePropertyObject(resource1, property1);
cms.unlockResource(resource1);
// now evaluate the result
tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_WRITEPROPERTY);
// project must be current project
tc.assertProject(cms, resource1, cms.getRequestContext().currentProject());
// state must be "changed"
tc.assertState(cms, resource1, tc.getPreCalculatedState(resource1));
// date last modified must be after the test timestamp
tc.assertDateLastModifiedAfter(cms, resource1, timestamp);
// the user last modified must be the current user
tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser());
// the property must have the new value
tc.assertPropertyChanged(cms, resource1, property1);
}
/**
* Tests the writePropertyObjects method for removing of properties.<p>
*
* @throws Throwable if something goes wrong
*/
public void testCreateProperties() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing creating multiple properties on a resource");
CmsProperty property8 = new CmsProperty("Newproperty", "testvalue1", "testvalue2");
CmsProperty property9 = new CmsProperty("AnotherNewproperty", "anothervalue", null);
List propertyList3 = new ArrayList();
propertyList3.add(property8);
propertyList3.add(property9);
createProperties(this, cms, "/index.html", propertyList3);
}
/**
* Tests the proper behaviour for case sensitiveness in property definition names.<p>
*
* @throws Throwable if something goes wrong
*/
public void testCaseSensitiveProperties() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing proper behaviour for case sensitiveness in property definition names");
CmsProperty myProperty = new CmsProperty("myProperty", "myValue", "myValue");
CmsProperty myproperty = new CmsProperty("myproperty", "myvalue", "myvalue");
cms.lockResource("/index.html");
cms.writePropertyObject("/index.html", myProperty);
cms.writePropertyObject("/index.html", myproperty);
cms.unlockResource("/index.html");
assertEquals("myValue", cms.readPropertyObject("/index.html", "myProperty", false).getResourceValue());
assertEquals("myvalue", cms.readPropertyObject("/index.html", "myproperty", false).getResourceValue());
}
/**
* Tests the writePropertyObject method for removing of properties.<p>
*
* @throws Throwable if something goes wrong
*/
public void testCreateProperty() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing creating one property on a resource");
CmsProperty property7 = new CmsProperty("Newproperty", "testvalue1", "testvalue2");
createProperty(this, cms, "/folder1/index.html", property7);
}
/**
* Tests the writePropertyObjects method for removing of multiple properties.<p>
*
* @throws Throwable if something goes wrong
*/
public void testRemoveProperties() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing removing multiple properties on a resource");
CmsProperty property5 = new CmsProperty("Title", CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE);
CmsProperty property6 = new CmsProperty("NavPos", CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE);
List propertyList2 = new ArrayList();
propertyList2.add(property5);
propertyList2.add(property6);
removeProperties(this, cms, "/folder1/page1.html", propertyList2);
}
/**
* Tests the writePropertyObject method for removing of a single property.<p>
*
* @throws Throwable if something goes wrong
*/
public void testRemoveProperty() throws Throwable {
CmsObject cms = getCmsObject();
echo("Testing removing one property on a resource");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -