use of javax.jcr.nodetype.NodeType 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.NodeType 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()");
}
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeTypeTest method testGetPrimaryItemName.
/**
* Test if node.getPrimaryItemName() returns the same name as
* node.getPrimaryItem().getName()
*/
public void testGetPrimaryItemName() throws NotExecutableException, RepositoryException {
Node node = locateNodeWithPrimaryItem(rootNode);
if (node == null) {
throw new NotExecutableException("Workspace does not contain a node with primary item defined");
}
String name = node.getPrimaryItem().getName();
NodeType type = node.getPrimaryNodeType();
assertEquals("node.getPrimaryNodeType().getPrimaryItemName() " + "must return the same name as " + "node.getPrimaryItem().getName()", name, type.getPrimaryItemName());
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanSetPropertyDateTest method testValueConstraintNotSatisfiedMultiple.
/**
* Tests if canSetProperty(String propertyName, Value[] values) returns
* false if values do not satisfy the value constraints of the property def
*/
public void testValueConstraintNotSatisfiedMultiple() throws NotExecutableException, ParseException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.DATE, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple date property def with " + "testable value constraints has been found");
}
Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
if (value == null) {
throw new NotExecutableException("No multiple date property def with " + "testable value constraints has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value[] values = new Value[] { value };
assertFalse("canSetProperty(String propertyName, Value[] values) must " + "return false if values do not match the value constraints.", nodeType.canSetProperty(propDef.getName(), values));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanSetPropertyDateTest method testValueConstraintNotSatisfied.
/**
* Tests if canSetProperty(String propertyName, Value value) returns false
* if value does not match the value constraints of the property def
*/
public void testValueConstraintNotSatisfied() throws NotExecutableException, ParseException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.DATE, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No date property def with " + "testable value constraints has been found");
}
Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
if (value == null) {
throw new NotExecutableException("No date property def with " + "testable value constraints has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
assertFalse("canSetProperty(String propertyName, Value value) must " + "return false if value does not match the value constraints.", nodeType.canSetProperty(propDef.getName(), value));
}
Aggregations