@Override public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException { return delegate.getPrimaryNodeTypes(); }
/** {@inheritDoc} */ public RemoteIterator getPrimaryNodeTypes() throws RepositoryException, RemoteException { try { return getFactory().getRemoteNodeTypeIterator( manager.getPrimaryNodeTypes()); } catch (RepositoryException ex) { throw getRepositoryException(ex); } }
private static String getPrimaryTypeName(Session session, Node node) throws RepositoryException { NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getPrimaryNodeTypes(); while (nts.hasNext()) { String name = nts.nextNodeType().getName(); if (!name.equals(node.getPrimaryNodeType().getName())) { return name; } } return null; } }
private List<ExtensibleType> getTypesList(final String typeName) { final Session session = getSession(); try { final List<ExtensibleType> list = new ArrayList<>(); final NodeTypeManager typeMgr = session.getWorkspace().getNodeTypeManager(); final NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes(); final NodeType extensibleType = typeMgr.getNodeType(typeName); while (typeItr.hasNext()) { final NodeType nodeType = (NodeType) typeItr.next(); if (nodeType.isNodeType(extensibleType.getName()) && !nodeType.equals(extensibleType)) { String nodeTypePath = ExtensionsConstants.TYPES + "/" + nodeType.getName(); if (session.getRootNode().hasNode(nodeTypePath)) { final Node typeNode = session.getRootNode().getNode(nodeTypePath); list.add(new JcrExtensibleType(typeNode, nodeType)); } } } return list; } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to lookup all extensible types", e); } }
/** * Test if getPrimaryNodeTypes does not return any mixin node types */ public void testGetPrimaryNodeTypes() throws RepositoryException { NodeTypeIterator types = manager.getPrimaryNodeTypes(); while (types.hasNext()) { assertFalse("getPrimaryNodeTypes() must not return mixin " + "node types", types.nextNodeType().isMixin()); } }
/** * Tests if addNode() throws a ConstraintViolationException in case * of an abstract node type. */ public void testAbstractNodeType() throws RepositoryException { NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = ntMgr.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); if (nt.isAbstract()) { try { testRootNode.addNode(nodeName1, nt.getName()); superuser.save(); fail("Expected ConstraintViolationException."); } catch (ConstraintViolationException e) { // correct. } finally { superuser.refresh(false); } } } }
Node typesNode = session.getRootNode().getNode(ExtensionsConstants.TYPES); NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager(); NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes(); NodeType extensionsType = typeMgr.getNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE);
/** * Tests if all primary node types are subtypes of node type <code>nt:base</code> */ public void testIfPrimaryNodeTypesAreSubtypesOfNTBase() throws RepositoryException { NodeTypeIterator types = manager.getPrimaryNodeTypes(); while (types.hasNext()) { NodeType type = types.nextNodeType(); assertTrue("Primary node type " + type.getName() + " must inherit nt:base", type.isNodeType("nt:base")); } }
/** * Test if getPropertyDefs() of a primary node returns also "jcr:primaryType" * which is inherited from "nt:base". */ public void testGetPropertyDefs() throws NotExecutableException, RepositoryException { // find a primary node type but not "nt:base" NodeTypeIterator types = manager.getPrimaryNodeTypes(); while (types.hasNext()) { NodeType type = types.nextNodeType(); PropertyDefinition defs[] = type.getPropertyDefinitions(); boolean hasJCRPrimaryType = false; for (int i = 0; i < defs.length; i++) { if (defs[i].getName().equals(jcrPrimaryType)) { hasJCRPrimaryType = true; break; } } assertTrue("getPropertyDefs() of a primary node type " + "must return also \"jcr:primaryType\".", hasJCRPrimaryType); } }
/** * Tests if <code>Node.setPrimaryType(String)</code> throws a * <code>ConstraintViolationException</code> if the * name of a mixin type is passed */ public void testSetAbstractAsPrimaryType() throws RepositoryException { Session session = testRootNode.getSession(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); if (nt.isAbstract()) { try { Node node = testRootNode.addNode(nodeName1, testNodeType); node.setPrimaryType(nt.getName()); fail("Node.setPrimaryType(String) must throw ConstraintViolationException if the specified node type name refers to an abstract node type."); } catch (ConstraintViolationException e) { // success } finally { // reset the changes. session.refresh(false); } } } }
/** * Test if getAllNodeTypes() returns all primary and mixin node types */ public void testGetAllNodeTypes() throws RepositoryException { long sizeAll = getSize(manager.getAllNodeTypes()); long sizePrimary = getSize(manager.getPrimaryNodeTypes()); long sizeMixin = getSize(manager.getMixinNodeTypes()); assertEquals("sizeAll() must return all primary and mixin node types:", sizePrimary + sizeMixin, sizeAll); }
NodeTypeIterator types = manager.getPrimaryNodeTypes(); NodeType type = null; while (types.hasNext()) {
public void testDescendantNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException { testRootNode.addNode(nodeName1, testNodeType); superuser.save(); NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator it = ntMgr.getPrimaryNodeTypes(); NodeType testNt = ntMgr.getNodeType(testNodeType); while (it.hasNext()) { NodeType nt = it.nextNodeType(); if (!testNt.isNodeType(nt.getName())) { // perform test QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.descendantNode("s", testRoot), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
public void testChildNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException { testRootNode.addNode(nodeName1, testNodeType); superuser.save(); NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator it = ntMgr.getPrimaryNodeTypes(); NodeType testNt = ntMgr.getNodeType(testNodeType); while (it.hasNext()) { NodeType nt = it.nextNodeType(); if (!testNt.isNodeType(nt.getName())) { // perform test QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.sameNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
public void testChildNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException { testRootNode.addNode(nodeName1, testNodeType); superuser.save(); NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator it = ntMgr.getPrimaryNodeTypes(); NodeType testNt = ntMgr.getNodeType(testNodeType); while (it.hasNext()) { NodeType nt = it.nextNodeType(); if (!testNt.isNodeType(nt.getName())) { // perform test QueryObjectModel qom = qf.createQuery( qf.selector(nt.getName(), "s"), qf.childNode("s", testRoot), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
/** * Like {@link #testIsNodeType()}, but using qualified names */ public void testIsNodeTypeQName() throws RepositoryException { // find a primary node type but not "nt:base" NodeTypeIterator types = manager.getPrimaryNodeTypes(); while (types.hasNext()) { NodeType type = types.nextNodeType(); String typename = type.getName(); String ns = session.getNamespaceURI(AbstractJCRTest.getPrefix(typename)); if (ns.length() != 0 && !ns.contains(":")) { log.warn("Node type '" + typename + "' has invalid namespace '" + ns + "', thus skipping testIsNodeTypeQName() for this type"); } else { String qn = AbstractJCRTest.getQualifiedName(session, typename); assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is nodeTypeName", type.isNodeType(qn)); } if (type.isMixin()) { assertFalse("isNodeType(String nodeTypeName) must return " + "false if NodeType is not a subtype of " + "nodeTypeName", type.isNodeType(NodeType.NT_BASE)); } else { assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is a subtype of nodeTypeName", type.isNodeType(NodeType.NT_BASE)); } } }
/** * Test if isMixin() returns false if applied on a primary node type and true * on a mixin node type. */ public void testIsMixin() throws RepositoryException { NodeTypeIterator primaryTypes = manager.getPrimaryNodeTypes(); assertFalse("testIsMixin() must return false if applied on a " + "primary node type", primaryTypes.nextNodeType().isMixin()); // if a mixin node type exist, test if isMixin() returns true NodeTypeIterator mixinTypes = manager.getMixinNodeTypes(); if (getSize(mixinTypes) > 0) { // need to re-aquire iterator {@link #getSize} may consume iterator mixinTypes = manager.getMixinNodeTypes(); assertTrue("testIsMixin() must return true if applied on a " + "mixin node type", mixinTypes.nextNodeType().isMixin()); } // else skip the test for mixin node types }
/** * Test if isNodeType(String nodeTypeName) returns true if nodeTypeName is * the name of the node itself. Also, primary node types must return true if * nodeTypeName is "nt:base", and mixin node types must return false in that * case. */ public void testIsNodeType() throws RepositoryException { // find a primary node type but not "nt:base" NodeTypeIterator types = manager.getPrimaryNodeTypes(); while (types.hasNext()) { NodeType type = types.nextNodeType(); assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is nodeTypeName", type.isNodeType(type.getName())); if (type.isMixin()) { assertFalse("isNodeType(String nodeTypeName) must return " + "false if NodeType is not a subtype of " + "nodeTypeName", type.isNodeType(ntBase)); } else { assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is a subtype of nodeTypeName", type.isNodeType(ntBase)); } } }
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>nodeTypeName</code> represents an abstract node type. */ public void testCanAddAbstractType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String childNodeName = nodeDef.getName(); String abstractName = null; NodeTypeIterator it = manager.getPrimaryNodeTypes(); while (it.hasNext() && abstractName == null) { NodeType nt = it.nextNodeType(); if (nt.isAbstract()) { abstractName = nt.getName(); } } if (abstractName == null) { throw new NotExecutableException("No abstract type found."); } assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents an abstract node type.", nodeType.canAddChildNode(childNodeName, abstractName)); } /**