/**
* Basically a test of a Graffito use case.
*/
public void testRegisterCyclicChildNodeTypesAndSupertypes() {
/**
* Constructs node types with the following structure:
* [Folder] > CmsObject
* + folders (Folder)
* + documents (Document)
*
* [CmsObject]
* + parentFolder (Folder)
*
* [Document] > CmsObject
* - size (long)
*
*/
final QNodeTypeDefinitionBuilder folder = new QNodeTypeDefinitionBuilder();
folder.setName(nameFactory.create("", "Folder"));
final QNodeTypeDefinitionBuilder cmsObject = new QNodeTypeDefinitionBuilder();
cmsObject.setName(nameFactory.create("", "CmsObject"));
cmsObject.setSupertypes(new Name[]{NameConstants.NT_BASE});
QNodeDefinitionBuilder parentFolder = new QNodeDefinitionBuilder();
parentFolder.setRequiredPrimaryTypes(new Name[]{folder.getName()});
parentFolder.setName(nameFactory.create("", "parentFolder"));
parentFolder.setDeclaringNodeType(cmsObject.getName());
cmsObject.setChildNodeDefs(new QNodeDefinition[]{parentFolder.build()});
final QNodeTypeDefinitionBuilder document = new QNodeTypeDefinitionBuilder();
document.setName(nameFactory.create("", "Document"));
document.setSupertypes(new Name[]{cmsObject.getName()});
QPropertyDefinitionBuilder sizeProp = new QPropertyDefinitionBuilder();
sizeProp.setName(nameFactory.create("", "size"));
sizeProp.setRequiredType(PropertyType.LONG);
sizeProp.setDeclaringNodeType(document.getName());
document.setPropertyDefs(new QPropertyDefinition[]{sizeProp.build()});
folder.setSupertypes(new Name[]{cmsObject.getName()});
QNodeDefinitionBuilder folders = new QNodeDefinitionBuilder();
folders.setRequiredPrimaryTypes(new Name[]{folder.getName()});
folders.setName(nameFactory.create("", "folders"));
folders.setDeclaringNodeType(folder.getName());
QNodeDefinitionBuilder documents = new QNodeDefinitionBuilder();
documents.setRequiredPrimaryTypes(new Name[]{document.getName()});
documents.setName(nameFactory.create("", "documents"));
documents.setDeclaringNodeType(folder.getName());
folder.setChildNodeDefs(new QNodeDefinition[]{
folders.build(), documents.build()});
ntDefCollection = new LinkedList<QNodeTypeDefinition>();
ntDefCollection.add(folder.build());
ntDefCollection.add(document.build());
ntDefCollection.add(cmsObject.build());
try {
ntreg.registerNodeTypes(ntDefCollection);
} catch (InvalidNodeTypeDefException e) {
assertFalse(e.getMessage(), true);
e.printStackTrace();
} catch (RepositoryException e) {
assertFalse(e.getMessage(), true);
e.printStackTrace();
}
boolean allNTsAreRegistered = ntreg.isRegistered(folder.getName()) && ntreg.isRegistered(document.getName()) && ntreg.isRegistered(cmsObject.getName());
assertTrue(allNTsAreRegistered);
}