use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class AddNodeTest method testMixinNodeType.
/**
* Tests if addNode() throws a ConstraintViolationException in case
* of an mixin node type.
*/
public void testMixinNodeType() throws RepositoryException, NotExecutableException {
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator nts = ntMgr.getMixinNodeTypes();
if (nts.hasNext()) {
try {
testRootNode.addNode(nodeName1, nts.nextNodeType().getName());
superuser.save();
fail("Expected ConstraintViolationException.");
} catch (ConstraintViolationException e) {
// correct.
}
} else {
throw new NotExecutableException("no mixins.");
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeDefTest method testGetDefaultPrimaryTypes.
/**
* Tests if the default primary type is of the same or a sub node type as the
* the required primary types. Test runs for all existing node types. Also
* tests the string based access ({@link NodeDefinition#getDefaultPrimaryTypeName()}.
*
* @since JCR 2.0
*/
public void testGetDefaultPrimaryTypes() throws RepositoryException {
// loop all node types
for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
NodeType type = types.nextNodeType();
NodeDefinition[] defs = type.getChildNodeDefinitions();
for (int i = 0; i < defs.length; i++) {
NodeDefinition def = defs[i];
NodeType defaultType = def.getDefaultPrimaryType();
String defaultTypeName = def.getDefaultPrimaryTypeName();
if (defaultType != null) {
NodeType[] requiredTypes = def.getRequiredPrimaryTypes();
for (int j = 0; j < requiredTypes.length; j++) {
NodeType requiredType = requiredTypes[j];
boolean isSubType = compareWithRequiredType(requiredType, defaultType);
assertTrue("The NodeType returned by " + "getDefaultPrimaryType or one of its " + "supertypes must match all NodeTypes " + "returned by getRequiredPrimaryTypes()", isSubType);
}
assertEquals("type names obtained from getDefaultPrimaryType and getDefaultPrimaryTypeName should match", defaultType.getName(), defaultTypeName);
NodeType tmpType = manager.getNodeType(defaultTypeName);
assertEquals(tmpType.getName(), defaultTypeName);
} else {
assertNull("getDefaultPrimaryTypeName should return null when getDefaultPrimaryType does", defaultTypeName);
}
}
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeDefTest method testGetRequiredPrimaryTypeNames.
/**
* Tests that the information from getRequiredPrimaryTypeNames()
* matches getRequiredPrimaryTypes().
*
* @since JCR 2.0
*/
public void testGetRequiredPrimaryTypeNames() throws RepositoryException {
// loop all node types
for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
NodeType type = types.nextNodeType();
NodeDefinition[] defs = type.getChildNodeDefinitions();
for (int i = 0; i < defs.length; i++) {
NodeType[] requiredPrimaryTypes = defs[i].getRequiredPrimaryTypes();
Set<String> rptnames = new HashSet<String>();
for (int j = 0; j < requiredPrimaryTypes.length; j++) {
rptnames.add(requiredPrimaryTypes[j].getName());
}
Set<String> rptnames2 = new HashSet<String>(Arrays.asList(defs[i].getRequiredPrimaryTypeNames()));
assertEquals("names returned from getRequiredPrimaryTypeNames should match types returned from getRequiredPrimaryTypes", rptnames, rptnames2);
}
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeManagerTest method testGetNodeType.
/**
* Test if getNodeType(String nodeTypeName) returns the expected NodeType and
* if a NoSuchTypeException is thrown if no according node type is existing
*/
public void testGetNodeType() throws RepositoryException {
NodeType type = manager.getAllNodeTypes().nextNodeType();
assertEquals("getNodeType(String nodeTypeName) does not return correct " + "NodeType", manager.getNodeType(type.getName()).getName(), type.getName());
StringBuffer notExistingName = new StringBuffer("X");
NodeTypeIterator types = manager.getAllNodeTypes();
while (types.hasNext()) {
// build a name which is for sure not existing
// (":" of namespace prefix will be replaced later on)
notExistingName.append(types.nextNodeType().getName());
}
try {
manager.getNodeType(notExistingName.toString().replaceAll(":", ""));
fail("getNodeType(String nodeTypeName) must throw a " + "NoSuchNodeTypeException if no according NodeType " + "does exist");
} catch (NoSuchNodeTypeException e) {
// success
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeTest method testGetDeclaredPropertyDefs.
/**
* Test if all property defs returned by getDeclatedPropertyDefs() are also
* returned by getPropertyDefs(). All existing node types are tested.
*/
public void testGetDeclaredPropertyDefs() throws RepositoryException {
NodeTypeIterator types = manager.getAllNodeTypes();
while (types.hasNext()) {
NodeType type = types.nextNodeType();
PropertyDefinition[] declaredDefs = type.getDeclaredPropertyDefinitions();
PropertyDefinition[] defs = type.getPropertyDefinitions();
try {
for (int i = 0; i < declaredDefs.length; i++) {
boolean exists = false;
for (int j = 0; j < defs.length; j++) {
if (defs[j].getName().equals(declaredDefs[i].getName())) {
exists = true;
break;
}
}
assertTrue("All property defs returned by " + "getDeclaredPropertyDefs() must also be " + "returned by getPropertyDefs()", exists);
}
} catch (ArrayIndexOutOfBoundsException e) {
fail("The array returned by " + "getDeclaredPropertyDefs() must not exceed " + "the one returned by getPropertyDefs()");
}
}
}
Aggregations