final CachedNode cachedNode( Path absolutePath, boolean checkReadPermission ) throws PathNotFoundException, RepositoryException { return checkReadPermission ? cachedNode(cache, getRootNode().node(), absolutePath, ModeShapePermissions.READ) : cachedNode(cache, getRootNode().node(), absolutePath); }
final AbstractJcrNode node( Path absolutePath ) throws PathNotFoundException, AccessDeniedException, RepositoryException { assert absolutePath.isAbsolute(); if (absolutePath.isRoot()) return getRootNode(); if (absolutePath.isIdentifier()) { // Look up the node by identifier ... String identifierString = stringFactory().create(absolutePath).replaceAll("\\[", "").replaceAll("\\]", ""); return getNodeByIdentifier(identifierString); } CachedNode node = getRootNode().node(); return node(node, absolutePath); }
@Override public void createWorkspace( String name, String srcWorkspace ) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException { validateCrossWorkspaceAction(srcWorkspace); createWorkspace(name); JcrSession newWorkspaceSession = session.spawnSession(name, false); JcrSession srcWorkspaceSession = session.spawnSession(srcWorkspace, true); deepClone(srcWorkspaceSession, srcWorkspaceSession.getRootNode().key(), newWorkspaceSession, newWorkspaceSession.getRootNode().key()); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNullMixinTypeName() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); nodeA.canAddMixin(null); }
@Test( expected = NoSuchNodeTypeException.class ) public void shouldNotAllowInvalidMixinTypeName() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); nodeA.canAddMixin("foo"); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowEmptyMixinTypeName() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); nodeA.canAddMixin(""); }
@Test public void shouldAllowCreatingNodeUnderUnsavedNode() throws Exception { Node node = session.getRootNode().addNode("testNode"); node.addNode("childNode"); session.save(); }
@Test public void shouldNotHaveCapabilityToPerformInvalidAddNode() throws Exception { assertTrue(!session.hasCapability("addNode", session.getRootNode(), new String[] {"someNewNode[2]"})); assertTrue(!session.hasCapability("addNode", session.getRootNode(), new String[] {"someNewNode", "nt:invalidType"})); }
@Test( expected = ConstraintViolationException.class ) public void shouldNotAllowAdditionIfResidualChildNodeConflicts() throws Exception { session.getRootNode().addNode("a", "nt:unstructured").addNode(CHILD_NODE_B, "nt:base"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_WITH_AUTO_CHILD), is(false)); nodeA.addMixin(MIXIN_TYPE_WITH_AUTO_CHILD); }
@Test public void shouldHaveLoadedContent() throws RepositoryException { Node node = session.getRootNode().getNode("Cars"); assertThat(node, is(notNullValue())); assertThat(node.hasNode("Sports"), is(true)); assertThat(node.hasNode("Utility"), is(true)); assertThat(node.hasNode("Hybrid"), is(true)); // System.out.println(node.getNode("Hybrid").getNodes().nextNode().getPath()); assertThat(node.hasNode("Hybrid/Toyota Prius"), is(true)); assertThat(node.getPrimaryNodeType().getName(), is("nt:unstructured")); }
@Test public void shouldAllowCreatingNodesTwoLevelsBelowRoot() throws Exception { Node node = session.getRootNode().addNode("testNode"); session.save(); node.addNode("childNode"); session.save(); }
protected void addMixinRecursively( String path, String... nodeTypes ) throws RepositoryException { Node node = session().getRootNode().getNode(relativePath(path)); addMixin(node, true, nodeTypes); }
@Test public void shouldAllowDeletingTransientNodeWithNoChildren() throws Exception { Node node = session.getRootNode().addNode("testNode"); node.remove(); session.save(); }
/** * ModeShape JCR implementation is supposed to have root type named {@link ModeShapeLexicon#ROOT}. * * @throws Exception if an error occurs during the test */ @Test public void rootNodeShouldHaveProperType() throws Exception { Node rootNode = session.getRootNode(); NodeType rootNodePrimaryType = rootNode.getPrimaryNodeType(); NodeType dnaRootType = session.nodeTypeManager().getNodeType(ModeShapeLexicon.ROOT); assertThat(rootNodePrimaryType.getName(), is(dnaRootType.getName())); }
@Test public void shouldAllowValidReferenceValues() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode()); assertThat(satisfiesConstraints(prop, new Value[] {}), is(true)); assertThat(satisfiesConstraints(prop, new Value[] {value}), is(true)); }
@SuppressWarnings( "deprecation" ) @Test public void shouldProvideRootNode() throws Exception { Node root = session.getRootNode(); assertThat(root, notNullValue()); String uuid = root.getIdentifier(); assertThat(root.isNodeType("mix:referenceable"), is(true)); assertThat(root.getUUID(), is(uuid)); assertThat(uuid, notNullValue()); }
@Test @FixFor( "MODE-2012" ) public void clonedUUIDsShouldBeTheSame() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node nodeA = session.getRootNode().addNode("A", "test:node"); Node nodeB = session.getRootNode().addNode("B", "test:node"); session.save(); otherWorkspace.clone("default", "/", "/", true); assertEquals(nodeA.getIdentifier(), otherSession.getNode("/A").getIdentifier()); assertEquals(nodeB.getIdentifier(), otherSession.getNode("/B").getIdentifier()); }
private void addNodeAndAssertIndexUsed(JcrRepository repository) throws RepositoryException, InterruptedException { JcrSession session = repository.login(); session.getRootNode().addNode("testRoot"); session.save(); Thread.sleep(100); String sql = "select [jcr:path] from [nt:unstructured] where [jcr:name] = 'testRoot'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); ValidateQuery.validateQuery().rowCount(1).useIndex("nodesByName").validate(query, query.execute()); session.logout(); }
private void validateNodesWithCustomTypes() throws RepositoryException { JcrRootNode rootNode = session.getRootNode(); rootNode.addNode("car", "car:Car"); rootNode.addNode("aircraft", "air:Aircraft"); session.save(); assertEquals("car:Car", session.getNode("/car").getPrimaryNodeType().getName()); assertEquals("air:Aircraft", session.getNode("/aircraft").getPrimaryNodeType().getName()); }
@Test @FixFor( "MODE-2424" ) public void shouldAllowAddingMixinOnLockedNodeForLockOwner() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); session.getWorkspace().getLockManager().lock(path, false, true, Long.MAX_VALUE, session.getUserID()); testNode.addMixin("mix:created"); session.save(); }