Page History
...
What this example does is to use the EasyMock method createStrictMock that creates an instance of the SystemContext inteface meaning that it creates a mock object that implements this interface checking the order of method calls. It sets the property Locale to this new context and then uses the FactoryUtil class to register the new instance which will be returned by getSingleton()
Magnolia Mock Objects
...
Content API Mocks
The customized mock objects that we provide to be able to setup an environment for Magnolia tests can be found in package info.magnolia.test.mock.
...
Code Block | ||
---|---|---|
| ||
MockContent page = new MockContent("page"); page.createContent("subpage", ItemType.CONTENT); page.setNodeData("stringProperty", "HelloWorld"); |
JCR Mocks
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 | ||
---|---|---|
| ||
MockSession session = SessionTestUtil.createSession("test", getClass().getResourceAsStream("sample.properties"));
|
as well as from String:
Code Block | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
MockNode root = new MockNode();
root.addNode(MetaData.DEFAULT_META_NODE);
root.setProperty("stringProperty", "HelloWorld");
|