Since Magnolia 4.5 we provide the package info.magnolia.test.mock.jcr containing proper mock's for javax.jcr.Node, javax.jcr.Session etc. They're extending abstract types provided in jackrabbit-commons. The types of the Content API are now basically just wrapping these new mocks. If required you can always create a MockContent from a MockNode or a MockHierarchyManager from a MockSession.
With the help of info.magnolia.test.mock.jcr.SessionTestUtil MockNodes can be created from properties files
Code Block |
---|
|
page1.@type = mgnl:content
page1/page11.@type = mgnl:content
page1/page12.@type = mgnl:content
page1/page13.@type = mgnl:content
page1/collection.@type = mgnl:contentNode
page1/collection/para11.@type = mgnl:contentNode
page1/collection/para12.@type = mgnl:contentNode
page1/page12/collection/para121.@type = mgnl:contentNode
page1/page12/collection/para122.@type = mgnl:contentNode |
Code Block |
---|
title | create MockSession from properties file |
---|
|
MockSession session = SessionTestUtil.createSession("test", getClass().getResourceAsStream("sample.properties"));
|
as well as from String:
Code Block |
---|
title | create MockSession from properties String |
---|
|
MockSession session = SessionTestUtil.createSession("testWorkspace",
"/foo/bar.@type=mgnl:content",
"/foo/bar/sub1.@uuid=1",
"/foo/bar/subpath.property=testName");
|
Of course there's also an proper API for it:
Code Block |
---|
title | create MockNode using API |
---|
|
MockNode root = new MockNode();
root.addNode(MetaData.DEFAULT_META_NODE);
root.setProperty("stringProperty", "HelloWorld");
|