use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.
the class RestoreTest method testRestoreWithUUIDConflictJcr2_2.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
public void testRestoreWithUUIDConflictJcr2_2() throws RepositoryException, NotExecutableException {
try {
Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
// Verify that nodes used for the test have proper opv behaviour
NodeDefinition nd = naa.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
}
Version v = versionManager.checkin(versionableNode.getPath());
versionManager.checkout(versionableNode.getPath());
superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
superuser.save();
versionManager.restore(v, false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.nodetype.NodeDefinition 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.NodeDefinition 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.NodeDefinition 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.NodeDefinition in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testResidualAndLegalType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns true if <code>childNodeName</code> does not match the <code>NodeDef</code>
* but <code>nodeTypeName</code> matches the node type of a residual <code>NodeDef</code>.
*/
public void testResidualAndLegalType() throws NotExecutableException, RepositoryException {
String type = null;
NodeType nodeType = null;
for (NodeDefinition nodeDef : NodeTypeUtil.locateAllChildNodeDef(session, false, false, true)) {
for (NodeType nt : nodeDef.getRequiredPrimaryTypes()) {
if (!nt.isAbstract()) {
nodeType = nodeDef.getDeclaringNodeType();
type = nt.getName();
}
}
}
if (nodeType == null || type == null) {
throw new NotExecutableException("No testable residual child node def.");
}
String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true for a not defined childNodeName if nodeTypeName " + "matches the type of a residual child node def", nodeType.canAddChildNode(undefinedName, type));
}
Aggregations