开发者

JCR Repository available for Junit tests

开发者 https://www.devze.com 2023-03-31 15:34 出处:网络
I have a code accessing to content repositories through JCR API. My code is being developed in OSGI environment. What I want is to have a JCR content repository which should be available while running

I have a code accessing to content repositories through JCR API. My code is being developed in OSGI environment. What I want is to have a JCR content repository which should be available while running the unit tests regardless from the environment. I mean it should be available for any user who builds the project. I don't want to depend on some external content repository running in a 开发者_StackOverflowdifferent virtual machine.

Is it possible to do such a thing? Thanks in advance.


You may also look at the transient repository provided by the Jackrabbit implementation. (assuming you are using Jackrabbit implementation) A Transient Repository is

a repository proxy that automatically initializes and shuts down the underlying repository instance when the first session is opened or the last one closed. - API doc

Please look at the examples here - it is really easy to create an instance of it. Since it is a local repository, you will never need to go over the network.

I normally create a transient repository and a session once per JUnit test class in setUpClass/BeforeClass hook and reuse it across all the test cases, cleaning up the session ( e.g, removing the nodes I added during a test case, etc.) after each test case.

One drawback, however, using transient repository, is that it will create several repository specific files/directory in your base directory. If you are using maven, then you can use maven-clean-plugin to clean up the unwanted files as a solution.


Apache Sling's RepositoryTestBase class provides a repository that can be used in "unit" testing. It does have some Sling dependencies, so you might not be able to use it as is but it's probably a good starting point.


ModeShape can easily be used within unit tests, and for unit tests our In-Memory connector and Disk connector work great and are very fast (and the in-memory doesn't require cleanup after each test). Our JcrEngineTest shows how easy this is, with each method configuring and starting an engine instance within a few lines. Many of these test complete in under 100ms.


Use a TransientRepository with a MemoryFileSystem and an In-Memory PM or a database persistence manager which can hanlde in-memory databases like H2.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号