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();
}
}
About Florian Hopf
I am working as a freelance software developer and consultant in Karlsruhe, Germany and have written a German book about Elasticsearch. If you liked this post you can follow me on Twitter or subscribe to my feed to get notified of new posts. If you think I could help you and your company and you'd like to work with me please contact me directly.
Keine Kommentare:
Kommentar veröffentlichen