Using OpenCmsTestCase
14 Apr 2010 These are basically some notes for me because I just had to relearn all of it.To use OpenCmsTestCase in a project the following steps have to be applied:
- Download the source distribution and unzip it
- set the file encoding: export ANT_OPTS=-Dfile.encoding=iso-8859-1
- run ant bindist
- run ant compile-tests
- Somehow some unittests are always not compiling for me: remove the java files and the entries from the TestSuites
- create a jar file from the folder org in ../BuildCms/build/test, e.g. jar -cf opencms-test-7.5.2.jar org
- add the jar to your project classpath/deploy to your maven repository
- add hsqldb.jar to your project
- copy the folders data and webapp to your project
- copy test/log4j.properties and test/test.properties to your test classpath and adjust the directory paths in test.properties (a good reason to use Maven so you can use the resource filtering mechanism)
- play with the files in data/imports and adjust them to your needs
A simple test case example:
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;
public class DummyOpenCmsTest extends OpenCmsTestCase {
static {
OpenCmsTestProperties.initialize(OpenCmsTestProperties.getResourcePathFromClassloader("test.properties"));
}
public DummyOpenCmsTest(String name) {
super(name);
}
@Override
public void setUp() throws Exception {
super.setUp();
setupOpenCms("simpletest", "/sites/default/");
}
public void testExistingResource() throws Exception {
CmsObject cms = getCmsObject();
CmsResource res = cms.readResource("/index.html");
assertEquals("/sites/default/index.html", res.getRootPath());
}
@Override
public void tearDown() throws Exception {
super.tearDown();
removeOpenCms();
}
}