In Memory JCR

A in memory JCR repository for testing Purposes

Лицензия

Лицензия

Группа

Группа

nl.openweb.jcr
Идентификатор

Идентификатор

in-memory-jcr
Последняя версия

Последняя версия

1.3.3
Дата

Дата

Тип

Тип

jar
Описание

Описание

In Memory JCR
A in memory JCR repository for testing Purposes
Ссылка на сайт

Ссылка на сайт

https://github.com/openweb-nl/in-memory-jcr
Система контроля версий

Система контроля версий

https://github.com/openweb-nl/in-memory-jcr

Скачать in-memory-jcr

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/nl.openweb.jcr/in-memory-jcr/ -->
<dependency>
    <groupId>nl.openweb.jcr</groupId>
    <artifactId>in-memory-jcr</artifactId>
    <version>1.3.3</version>
</dependency>
// https://jarcasting.com/artifacts/nl.openweb.jcr/in-memory-jcr/
implementation 'nl.openweb.jcr:in-memory-jcr:1.3.3'
// https://jarcasting.com/artifacts/nl.openweb.jcr/in-memory-jcr/
implementation ("nl.openweb.jcr:in-memory-jcr:1.3.3")
'nl.openweb.jcr:in-memory-jcr:jar:1.3.3'
<dependency org="nl.openweb.jcr" name="in-memory-jcr" rev="1.3.3">
  <artifact name="in-memory-jcr" type="jar" />
</dependency>
@Grapes(
@Grab(group='nl.openweb.jcr', module='in-memory-jcr', version='1.3.3')
)
libraryDependencies += "nl.openweb.jcr" % "in-memory-jcr" % "1.3.3"
[nl.openweb.jcr/in-memory-jcr "1.3.3"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
javax.jcr : jcr jar 2.0
org.apache.jackrabbit : jackrabbit-core jar 2.21.4
org.slf4j : jcl-over-slf4j jar 1.7.30

test (3)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-nop jar 1.7.30
org.junit.jupiter : junit-jupiter-engine jar 5.7.0
org.hamcrest : hamcrest-junit jar 2.0.0.0

Модули Проекта

Данный проект не имеет модулей.

In Memory JCR

The goal of this project is to make it easier for developers to set up a full feature JCR repository (In this case Jackrabbit) for testing purposes.

Usage

The first is to add this library to your project as a test dependency. If you are using Maven you can do so by adding the following snippet to your pom.xml file

<dependencies>
  ...
  <dependency>
    <groupId>nl.openweb.jcr</groupId>
    <artifactId>in-memory-jcr</artifactId>
    <version>1.3.2</version>
    <scope>test</scope>
  </dependency>
  ...
</dependencies>

then in your test you can instantiate a new repository simple by instantiating a new instance of InMemoryJcrRepository class.

InMemoryJcrRepository repository = new InMemoryJcrRepository();

to obtain an instance of java session via

Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

Please notice that you need to shutdown the repository at the end of your test. Because unlike what the name of this library might suggest the repository is not 100% in the memory. The database and the indexes are indeed kept in memory, but it still places a couple of XML files in a temporary folder. So shutting down the repository insures that these xml files are deleted. To shutdown the repository you can use the following snippet

repository.shutdown();

Please notice that InMemoryJcrRepository implements AutoCloseable. Therefore it can be in a try with resources statement as well.

try (InMemoryJcrRepository repository = new InMemoryJcrRepository()) {
	Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
	// here is your test
}

Extra tools

Node definition constrains and namespace definitions can be a headache during testing. To make testing easier, there is a utility class that you can use to register your node types and mixin types free of constrains. Let say I want to have a node of type "mynamespace:mynode" then I can simple use

NodeTypeDefUtils.createNodeType(session, "mynamespace:mynode");

Please notice that you do not need to register "mynamespace". If "mynamespace" namespace is not register the NodeTypeDefUtils is going to register it automatically.

Here is a complete example

try (InMemoryJcrRepository repository = new InMemoryJcrRepository()) {
    Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    NodeTypeDefUtils.createNodeType(session, "mynamespace:mynode");

    Node node = session.getRootNode().addNode("nodeName", "mynamespace:mynode");
    session.save();
    // your test
}
nl.openweb.jcr

Open Web

Software development and open source is in our DNA. Development, contracting, maintenance and management. Discover what Open Web professionals can do for you.

Версии библиотеки

Версия
1.3.3
1.3.2
hippo-1.3.3
hippo-1.3.2