ScopeTreeUtil { public static Tree.Node<String> getScopeAliasTreeNode( List<String> scopeAliasesList, ScopeMatcherFactory scopeMatcherFactory) { return getScopeAliasTreeNode( new HashSet<>(scopeAliasesList), scopeMatcherFactory); }  static Tree.Node<String> getScopeAliasTreeNode(
		List<String> scopeAliasesList,
		ScopeMatcherFactory scopeMatcherFactory); static Tree.Node<String> getScopeAliasTreeNode(
		Set<String> scopeAliases, ScopeMatcherFactory scopeMatcherFactory);  }
@Test public void testMultipleLevelsScopeTree() { List<String> scopeAliasesList = Arrays.asList( "everything.read", "everything.write", "everything", "everything.read.user", "everything.read.user.documents"); Tree.Node<String> node = ScopeTreeUtil.getScopeAliasTreeNode( scopeAliasesList, _scopeMatcherFactory); Assert.assertEquals(StringPool.BLANK, node.getValue()); Tree<String> tree = _getTree(node, 0); Assert.assertEquals("everything", tree.getValue()); Assert.assertFalse(tree instanceof Tree.Leaf); Tree<String> firstChildTree = _getTree((Tree.Node<String>)tree, 0); Assert.assertEquals("everything.read", firstChildTree.getValue()); Assert.assertFalse(firstChildTree instanceof Tree.Leaf); Tree<String> firstGrandChildTree = _getTree( (Tree.Node<String>)firstChildTree, 0); Assert.assertEquals( "everything.read.user", firstGrandChildTree.getValue()); Assert.assertFalse(firstGrandChildTree instanceof Tree.Leaf); Tree<String> greatGrandChildTree = _getTree( (Tree.Node<String>)firstGrandChildTree, 0); Assert.assertEquals( "everything.read.user.documents", greatGrandChildTree.getValue()); Tree<String> lastChildTree = _getLastTree((Tree.Node<String>)tree); Assert.assertEquals("everything.write", lastChildTree.getValue()); Assert.assertTrue(lastChildTree instanceof Tree.Leaf); }
@Test public void testMultipleParentsScopeTree() { List<String> scopeAliasesList = Arrays.asList( "everything.read", "everything.write", "everything", "everything.read.user", "analytics.read", "analytics"); Tree.Node<String> node = ScopeTreeUtil.getScopeAliasTreeNode( scopeAliasesList, _scopeMatcherFactory); Assert.assertEquals(StringPool.BLANK, node.getValue()); Tree<String> tree = _getTree(node, 0); Assert.assertEquals("analytics", tree.getValue()); Assert.assertFalse(tree instanceof Tree.Leaf); Tree<String> firstChildTree = _getTree((Tree.Node<String>)tree, 0); Assert.assertEquals("analytics.read", firstChildTree.getValue()); Assert.assertTrue(firstChildTree instanceof Tree.Leaf); Tree<String> lastTree = _getLastTree(node); Assert.assertEquals("everything", lastTree.getValue()); Assert.assertFalse(lastTree instanceof Tree.Leaf); Tree<String> lastChildTree = _getTree((Tree.Node<String>)lastTree, 0); Assert.assertEquals("everything.read", lastChildTree.getValue()); Assert.assertFalse(lastChildTree instanceof Tree.Leaf); }
@Test public void testOneLevelScopeTree() { List<String> scopeAliasesList = Arrays.asList( "everything.read", "everything.write", "everything"); Tree.Node<String> node = ScopeTreeUtil.getScopeAliasTreeNode( scopeAliasesList, _scopeMatcherFactory); Assert.assertEquals(StringPool.BLANK, node.getValue()); Tree<String> tree = _getTree(node, 0); Assert.assertEquals("everything", tree.getValue()); Assert.assertFalse(tree instanceof Tree.Leaf); Tree<String> firstChildTree = _getTree((Tree.Node<String>)tree, 0); Assert.assertEquals("everything.read", firstChildTree.getValue()); Assert.assertTrue(firstChildTree instanceof Tree.Leaf); Tree<String> lastChildTree = _getLastTree((Tree.Node<String>)tree); Assert.assertEquals("everything.write", lastChildTree.getValue()); Assert.assertTrue(lastChildTree instanceof Tree.Leaf); }