Provide support when accessing XML databases like eXist with Java and XQuery
The following Spring integration tests demonstrates the simple use-case of an empty XQuery sequence:
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = ExistConfiguration.class)
class SimpleExistXQJRepositoryTests {
@Inject
private SimpleXQJRepository<Integer> existRepository;
@Test
void emptySequence() {
Stream<Integer> result = existRepository.execute("()");
assertEquals(0, result.count());
}
}
Prerequisites
- Install and start an eXist-db locally.
Tip: Please refer to eXist - Kick-start Development with Docker for a non-invasive setup with Docker.
- Create the test collection
/data/book
with eXide. - Download
exist-xqj-api-1.0.1.jar
from eXist XQJ API and put the Java library into thelib
folder.
Action
The standard Gradle task test
will run the integration tests.
$ ./gradlew test
Hint: This repository is a companion of the blog post Building a Simple eXist Repository on Top of Spring Data which describes the internals of this library in more detail.