@Test public void testGetOrAddTree() throws Exception { NodeUtil result = node.getOrAddTree(".", NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertSame(node, result); NodeUtil child = node.getOrAddTree("child", NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertEqualNodeUtil(new NodeUtil(root.getTree("/child")), child); NodeUtil parent = child.getOrAddTree("..", NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertEqualNodeUtil(node, parent); Map<String, String> map = ImmutableMap.of( "a/b/c", "/a/b/c", "a/../b/c", "/b/c", "a/b/c/../..", "/a", "a/././././b/c", "/a/b/c" ); for (String relPath : map.keySet()) { NodeUtil n = node.getOrAddTree(relPath, NodeTypeConstants.NT_OAK_UNSTRUCTURED); assertEqualNodeUtil(new NodeUtil(root.getTree(map.get(relPath))), n); } } }
@Test public void testGetPatternForAllSupported() throws Exception { Map<PropertyState, RestrictionPattern> map = newHashMap(); map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content")); List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE); map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames)); List<String> prefixes = ImmutableList.of("rep", "jcr"); map.put(PropertyStates.createProperty(REP_PREFIXES, prefixes, Type.STRINGS), new PrefixPattern(prefixes)); List<String> itemNames = ImmutableList.of("abc", "jcr:primaryType"); map.put(PropertyStates.createProperty(REP_ITEM_NAMES, prefixes, Type.NAMES), new ItemNamePattern(itemNames)); NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED); Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree(); for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) { restrictions.setProperty(entry.getKey()); } RestrictionPattern pattern = provider.getPattern("/testPath", restrictions); assertTrue(pattern instanceof CompositePattern); }
@Test public void testGetRestrictionPattern() throws Exception { Map<PropertyState, RestrictionPattern> map = newHashMap(); map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content")); List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE); map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames)); NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED); Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree(); // test restrictions individually for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) { restrictions.setProperty(entry.getKey()); RestrictionPattern pattern = provider.getPattern("/testPath", restrictions); assertEquals(entry.getValue(), pattern); restrictions.removeProperty(entry.getKey().getName()); } // test combination on multiple restrictions for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) { restrictions.setProperty(entry.getKey()); } RestrictionPattern pattern = provider.getPattern("/testPath", restrictions); assertTrue(pattern instanceof CompositePattern); }
@Test public void testGetPatternFromRestrictions() throws Exception { Map<PropertyState, RestrictionPattern> map = newHashMap(); map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content")); List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE); map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames)); List<String> prefixes = ImmutableList.of("rep", "jcr"); map.put(PropertyStates.createProperty(REP_PREFIXES, prefixes, Type.STRINGS), new PrefixPattern(prefixes)); List<String> itemNames = ImmutableList.of("abc", "jcr:primaryType"); map.put(PropertyStates.createProperty(REP_ITEM_NAMES, itemNames, Type.NAMES), new ItemNamePattern(itemNames)); NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED); Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree(); // test restrictions individually for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) { restrictions.setProperty(entry.getKey()); RestrictionPattern pattern = provider.getPattern("/testPath", provider.readRestrictions("/testPath", tree.getTree())); assertEquals(entry.getValue(), pattern); restrictions.removeProperty(entry.getKey().getName()); } // test combination on multiple restrictions for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) { restrictions.setProperty(entry.getKey()); } RestrictionPattern pattern = provider.getPattern("/testPath", provider.readRestrictions("/testPath", tree.getTree())); assertTrue(pattern instanceof CompositePattern); }
@Test public void testMatchesItem() throws Exception { NodeUtil rootTree = new NodeUtil(root.getTree("/")); List<String> matching = ImmutableList.of("a", "b", "c", "d/e/a", "a/b/c/d/b", "test/c"); for (String relPath : matching) { Tree testTree = rootTree.getOrAddTree(relPath, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree(); assertTrue(pattern.matches(testTree, null)); assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE))); assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval"))); testTree.remove(); } List<String> notMatching = ImmutableList.of("d", "b/d", "d/e/f", "c/b/abc"); for (String relPath : notMatching) { Tree testTree = rootTree.getOrAddTree(relPath, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree(); assertFalse(pattern.matches(testTree, null)); assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE))); assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval"))); testTree.remove(); } }
Tree createGroupTree() throws Exception { String groupPath = getUserConfiguration().getParameters().getConfigValue(PARAM_GROUP_PATH, DEFAULT_GROUP_PATH); NodeUtil node = new NodeUtil(root.getTree(PathUtils.ROOT_PATH)); NodeUtil groupRoot = node.getOrAddTree(PathUtils.relativize(PathUtils.ROOT_PATH, groupPath), NT_REP_AUTHORIZABLE_FOLDER); Tree groupTree = groupRoot.addChild("testGroup", NT_REP_GROUP).getTree(); groupTree.setProperty(JcrConstants.JCR_UUID, new UserProvider(root, ConfigurationParameters.EMPTY).getContentID(TEST_GROUP_ID)); return groupTree; }
@Override public void before() throws Exception { super.before(); Tree rootTree = root.getTree("/"); NodeUtil f = new NodeUtil(rootTree).getOrAddTree("a/d/b/e/c/f", NodeTypeConstants.NT_OAK_UNSTRUCTURED); NodeUtil c = f.getParent(); c.setString("prop", "value"); c.setString("a", "value"); testPrincipal = getTestUser().getPrincipal(); AccessControlManager acMgr = getAccessControlManager(root); JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/a"); vf = new ValueFactoryImpl(root, NamePathMapper.DEFAULT); acl.addEntry(testPrincipal, privilegesFromNames( PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_ADD_PROPERTIES, PrivilegeConstants.JCR_ADD_CHILD_NODES, PrivilegeConstants.JCR_REMOVE_NODE), true, Collections.<String, Value>emptyMap(), ImmutableMap.of(AccessControlConstants.REP_ITEM_NAMES, new Value[] { vf.createValue("a", PropertyType.NAME), vf.createValue("b", PropertyType.NAME), vf.createValue("c", PropertyType.NAME)})); acMgr.setPolicy(acl.getPath(), acl); UserManager uMgr = getUserManager(root); testGroup = uMgr.createGroup("testGroup" + UUID.randomUUID()); root.commit(); testSession = createTestSession(); }