PrivilegeDefinitionWriter implements PrivilegeConstants { void writeDefinition(@NotNull PrivilegeDefinition definition) throws RepositoryException { writeDefinitions(Collections.singleton(definition)); } PrivilegeDefinitionWriter(@NotNull Root root);   }
@Test(expected = RepositoryException.class) public void testNameCollision() throws Exception { PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(root); writer.writeDefinition(new ImmutablePrivilegeDefinition(JCR_READ, true, null)); }
@Test(expected = RepositoryException.class) public void testMissingPrivilegeRoot() throws Exception { ContentRepository repo = new Oak().with(new OpenSecurityProvider()).createContentRepository(); try (ContentSession cs = repo.login(null, null)) { Root tmpRoot = cs.getLatestRoot(); PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(tmpRoot); writer.writeDefinition(new ImmutablePrivilegeDefinition("newName", true, null)); } }
@Test public void testWriteDefinition() throws Exception { PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(root); writer.writeDefinition(new ImmutablePrivilegeDefinition( "tmp", true, asList(JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL))); Tree privRoot = root.getTree(PRIVILEGES_PATH); assertTrue(privRoot.hasChild("tmp")); Tree tmpTree = privRoot.getChild("tmp"); assertTrue(TreeUtil.getBoolean(tmpTree, REP_IS_ABSTRACT)); assertArrayEquals( new String[] {JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL}, Iterables.toArray(TreeUtil.getStrings(tmpTree, REP_AGGREGATES), String.class)); }
@Test(expected = RepositoryException.class) public void testCommitFails() throws Exception { Root r = Mockito.spy(root); doThrow(new CommitFailedException(CommitFailedException.OAK, 1, "msg")).when(r).commit(); PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(r); writer.writeDefinition(new ImmutablePrivilegeDefinition( "tmp", true, asList(JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL))); }