use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class MandatoryItemTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType);
NodeDefinition[] ndefs = nt.getChildNodeDefinitions();
for (int i = 0; i < ndefs.length; i++) {
if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated()) {
childNodeDef = ndefs[i];
break;
}
}
PropertyDefinition[] pdefs = nt.getPropertyDefinitions();
for (int i = 0; i < pdefs.length; i++) {
if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated()) {
childPropDef = pdefs[i];
break;
}
}
if (childPropDef == null && childNodeDef == null) {
cleanUp();
throw new NotExecutableException();
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeAddMixinTest method testAddSuccessfully.
/**
* Tests if <code>Node.addMixin(String mixinName)</code> adds the requested
* mixin and stores it in property <code>jcr:mixinTypes</code>
*/
public void testAddSuccessfully() throws NotExecutableException, RepositoryException {
Session session = testRootNode.getSession();
Node node = testRootNode.addNode(nodeName1, testNodeType);
String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
if (mixinName == null) {
throw new NotExecutableException("No testable mixin node type found");
}
node.addMixin(mixinName);
// test if mixin is written to property jcr:mixinTypes immediately
Value[] mixinValues = node.getProperty(jcrMixinTypes).getValues();
boolean found = false;
for (int i = 0; i < mixinValues.length; i++) {
found |= mixinName.equals(mixinValues[i].getString());
}
if (!found) {
fail("Mixin type must be added to property " + jcrMixinTypes + " immediately.");
}
// it is implementation-specific if a added mixin is available
// before or after save therefore save before further tests
testRootNode.getSession().save();
// test if added mixin is available by node.getMixinNodeTypes()
NodeType[] mixins = node.getMixinNodeTypes();
found = false;
for (int i = 0; i < mixins.length; i++) {
found |= mixinName.equals(mixins[i].getName());
}
if (!found) {
fail("Mixin '" + mixinName + "' type not added.");
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanSetPropertyTest method testReturnFalseBecauseIsMultiple.
/**
* Tests if NodeType.canSetProperty(String propertyName, Value value)
* returns false if the property is multiple
*/
public void testReturnFalseBecauseIsMultiple() throws NotExecutableException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, true, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No multiple, not protected property def found.");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value value = NodeTypeUtil.getValueOfType(superuser, propDef.getRequiredType());
assertFalse("canSetProperty(String propertyName, Value value) must " + "return false if the property is multiple.", nodeType.canSetProperty(propDef.getName(), value));
}
use of javax.jcr.nodetype.NodeType 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.NodeType 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);
}
}
}
Aggregations