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.

When creating a mock hierarchy manager you can either initialize it from a properties file:

sample.properties
main@type = mgnl:content
main@uuid = 1

main/uuidLink@type = mgnl:contentNode
main/uuidLink@uuid = 2
main/uuidLink.MetaData.mgnl\:template = someParagraphName
main/uuidLink.MetaData.mgnl\:authorid = superuser
main/uuidLink.MetaData.mgnl\:activatorid = superuser
main/uuidLink.MetaData.mgnl\:title = myTitle
main/uuidLink.link1 = 3

main/linkTarget@type = mgnl:content
main/linkTarget@uuid = 3
main/linkTarget.prop1 = sub2value1
main/linkTarget.prop2 = sub2value2
main/linkTarget.prop3 = boolean:false

main/content@type = mgnl:contentNode
main/content@uuid = 4
main/content.value = Content Value
create MockHM from properties file
HierarchyManager hm = MockUtil.createHierarchyManager(RepositoryConstants.USERS, getClass().getResourceAsStream("sample.properties"));

or you can create a variable with the data or pass it to the method call directly:

create MockHM from properties String
final String content = StringUtils.join(Arrays.asList(
    "main/content@type=mgnl:contentNode",
    "main/content@uuid=4",
    "main/content.value=Content Value"
    ), "\n");

HierarchyManager hm = MockUtil.createHierarchyManager(RepositoryConstants.USERS, content);

You may also directly instantiate a MockContent and then add the child Contents and or NodeData's as required

create MockContent using API
MockContent page = new MockContent("page");
page.createContent("subpage", ItemType.CONTENT);
page.setNodeData("stringProperty", "HelloWorld");
  • No labels