@Override public MgnlRole doExec(Session session) throws RepositoryException { String parentPath = StringUtils.defaultString(path, "/"); Node roleNode = session.getNode(parentPath).addNode(name, NodeTypes.Role.NAME); final Node acls = roleNode.addNode(NODE_ACLROLES, NodeTypes.ContentNode.NAME); // read only access to the role itself Node acl = acls.addNode(nodeNameHelper.getUniqueName(session, acls.getPath(), "0"), NodeTypes.ContentNode.NAME); acl.setProperty("path", roleNode.getPath()); acl.setProperty("permissions", Permission.READ); session.save(); return newRoleInstance(roleNode); }
@Test public void logModifiesNode() throws RepositoryException { session.getNode("/articles").setProperty("title", "newtitle"); session.save(); assertEquals(1, audit.records.size()); assertEquals(AuditLoggingUtil.ACTION_MODIFY, audit.records.get(0).getLeft()); assertEquals("/articles", audit.records.get(0).getRight()[4]); }
@Test public void createNewUserUnderPath() throws Exception { Session userSession = MgnlContext.getJCRSession(RepositoryConstants.USERS); userSession.getNode("/public").addNode("developers", NodeTypes.Folder.NAME); // WHEN hm.createUser("/public/developers", "vito", "password"); // THEN assertThat(userSession.getNode("/public/developers"), hasNode("v/vi/vito", NodeTypes.User.NAME)); }
/** * Tests that in infinity and NaN values can be persisted and round-tripped. */ public void testEdgeCases() throws Exception { double tests[] = { Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }; String path = testNode.getPath(); for (double v : tests) { testNode.setProperty(propertyName1, v); testRootNode.getSession().save(); assertEquals("Round-trip of " + v, v, superuser.getNode(path).getProperty(propertyName1).getDouble()); } } }
@Override protected void beforeSuite() throws Exception { Session session = loginWriter(); testRoot = session.getRootNode().addNode( getClass().getSimpleName() + TEST_ID, "nt:unstructured"); testRoot.addNode("node1").addNode("node2"); addAccessControlEntry(session, testRoot.getPath(), EveryonePrincipal.getInstance(), new String[] {JCR_READ}, true); session.save(); testRoot = login().getNode(testRoot.getPath()); session.logout(); }
/** * @see <a href="https://issues.apache.org/jira/browse/OAK-2024">OAK-2024</a> */ @Test public void testTraverseIndex() throws Exception { Session session = getAdminSession(); AccessControlUtils.denyAllToEveryone(session, "/oak:index"); session.save(); Node index = session.getNode("/oak:index"); traverse(index); }
@Test public void copyToVersionWhenChangingPrimaryNodeType() throws RepositoryException { // GIVEN Node node = websiteSession.getRootNode().addNode("test", NodeTypes.Content.NAME); copyUtil.copyToVersion(node, new RuleBasedNodePredicate(new Rule())); assertEquals(NodeTypes.Content.NAME, versionSession.getNode("/" + CopyUtil.getSavePath(node) + "/" + node.getIdentifier()).getPrimaryNodeType().getName()); node.setPrimaryType(NodeTypes.Page.NAME); // WHEN copyUtil.copyToVersion(node, new RuleBasedNodePredicate(new Rule())); // THEN assertThat(versionSession.getRootNode(), hasNode(CopyUtil.getSavePath(node) + "/" + node.getIdentifier(), NodeTypes.Page.NAME)); }
public void testRestoreRemovedJcr2() throws RepositoryException { String path = versionableNode.getPath(); Version v1 = versionManager.checkin(path); versionableNode.remove(); versionableNode = null; superuser.save(); versionManager.restore(path, v1, true); versionableNode = superuser.getNode(path); String value = versionableNode.getProperty(propertyName1).getString(); assertEquals("Restoring a node must set the correct property.", propertyValue2, value); }
@Override protected void beforeSuite() throws Exception { session = loginWriter(); testRoot = session.getRootNode().addNode( getClass().getSimpleName() + TEST_ID, "nt:unstructured"); Node n = testRoot.addNode("node1"); path = n.getPath(); addAccessControlEntry(session, n.getPath(), EveryonePrincipal.getInstance(), new String[] { JCR_READ }, true); session.save(); testRoot = loginWriter().getNode(testRoot.getPath()); acm = testRoot.getSession().getAccessControlManager(); }
@Test public void testMoveAndAddPropertyAtSource2() throws Exception { setupMovePermissions(); allow(childNPath, privilegesFromName(PrivilegeConstants.REP_ADD_PROPERTIES)); testSession.move(nodePath3, siblingDestPath); Node n = testSession.getNode(childNPath); Property p = n.setProperty("newProp", "val"); testSession.save(); }
/** * @since oak */ @Test public void testVersionablePath() throws Exception { Node n = createVersionableNode(superuser.getNode(path)); VersionHistory vh = n.getVersionHistory(); Property versionablePath = vh.getProperty(superuser.getWorkspace().getName()); assertEquals(n.getPath(), versionablePath.getString()); }
protected void tearDown() throws Exception { // remove copied node try { String dstPath = getProperty("destination"); superuser.getNode(dstPath).remove(); testRootNode.getSession().save(); } catch (Exception e) { log.println("Exception in tearDown: " + e.toString()); } finally { super.tearDown(); } }
@Override protected void runTest(TestContext ctx) throws Exception { //Create tree in breadth first fashion with each node having 50 child Node parent = ctx.session.getNode(ctx.paths.remove()); Status status = Status.NONE; for (int i = 0; i < nodesPerIteration; i++) { Node child = parent.addNode(nextNodeName()); child.setProperty(indexedPropName, status.name()); ctx.session.save(); ctx.paths.add(child.getPath()); indexedNodeCount.incrementAndGet(); status.inc(); status = status.next(); } }
@Test public void testMoveAndAddProperty2() throws Exception { setupMovePermissions(); allow(childNPath, privilegesFromName(PrivilegeConstants.REP_ADD_PROPERTIES)); testSession.move(nodePath3, siblingDestPath); Node destNode = testSession.getNode(siblingDestPath); Property p = destNode.setProperty("newProp", "val"); // now save must succeed testSession.save(); }
protected void tearDown() throws Exception { // remove copied node try { String dstPath = getProperty("destination"); superuser.getNode(dstPath).remove(); testRootNode.getSession().save(); } catch (Exception e) { log.println("Exception in tearDown: " + e.toString()); } finally { super.tearDown(); } }