Hi,
Quite a few of the bug reports we receive could quite easily be
expressed as unit tests. It would be great if we could provide a
simple unit test template class that users could fill in and attach to
the bug report. This would make verifying the bug reports easier and
also provide a ready-made regression test case to be included in the
Jackrabbit test suite.
The requirements for such a template class would be:
1) It should depend only on JUnit, JCR, and perhaps some helper class
available in the Jackrabbit jar so that you could compile and run it
by just adding JUnit to the Jackrabbit classpath without having to
checkout and compile the Jackrabbit sources
2) It should require minimal configuration. Something like the
TransientRepository default constructor could be used to automatically
set up a test repository.
3) It should be short and simple, preferably less than 50 lines
including documentation.
4) It should compile with "javac ExampleTest.java" and run with "java
junit.textui.TestRunner ExampleTest" with the classpath from
requirement 1
The RepositoryHelper and AbstractJCRTest classes in the TCK could be a
good starting point, but they are somewhat complex and don't meet
requirement 1 at least at the moment. Another alternative based on
TransientFactory and some default configuration (TODO) is shown below.
Comments?
import javax.jcr.*; // Import all main JCR interfaces to simplify
test writing
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Template test case for Jackrabbit. Use this template to write test cases
* to accompany Jackrabbit bug reports.
*/
public class ExampleTest extends TestCase {
public void testSomething() throws Exception {
// TODO: Your test case here. (Hint: use the session variable.)
}
/**
* Read-write session for accessing the test repository.
*/
private Session session;
/**
* Starts a test fixture by acquiring a new read-write session
* on the test repository.
*
* @throws Exception if an error occurs
*/
protected void setUp() throws Exception {
RepositoryConfig config = ...; // TODO: Test config with
defaultUserId
session = new TransientRepository(config).login();
}
/**
* Ends a test fixture by closing the test session.
*
* @throws Exception if an error occurs
*/
protected void tearDown() throws Exception {
session.logout();
}
/**
* Returns a test suite that contains all the tests in this class.
*
* @return test suite
*/
public static Test suite() {
return new TestSuite(ExampleTest.class);
}
}
BR,
Jukka Zitting
--
Yukatan - http://yukatan.fi/ - [EMAIL PROTECTED]
Software craftsmanship, JCR consulting, and Java development