HMSPaths implements AuthzPaths { @Override public String toString() { return String.format("%s:%s", getClass().getSimpleName(), Arrays.toString(prefixes)); } HMSPaths();  HMSPaths(String[] pathPrefixes); @Override Set<String> findAuthzObject(String[] pathElements); @Override Set<String> findAuthzObjectExactMatches(String[] pathElements); Set<String> findAuthzObject(String[] pathElements, boolean isPartialOk); @Override boolean isUnderPrefix(String[] pathElements); Collection<Entry> getAllEntries(); @Override HMSPathsDumper getPathsDump(); @Override String toString(); String dumpContent();  }
@Test public void testRootEntry() { HMSPaths.Entry root = HMSPaths.Entry.createRoot(false); root.toString(); Assert.assertNull(root.getParent()); Assert.assertEquals(HMSPaths.EntryType.DIR, root.getType()); Assert.assertTrue(root.getAuthzObjsSize() == 0); Assert.assertTrue(root.isAuthzObjsEmpty()); Assert.assertTrue(root.getAuthzObjs().size() == 0); Assert.assertEquals(Path.SEPARATOR, root.getFullPath()); Assert.assertFalse(root.hasChildren()); root.delete(); try { root.find(null, true); Assert.fail(); } catch (IllegalArgumentException ex) { } try { root.find(new String[0], true); Assert.fail(); } catch (IllegalArgumentException ex) { } try { root.find(null, false); Assert.fail(); } catch (IllegalArgumentException ex) { } try { root.find(new String[0], false); Assert.fail(); } catch (IllegalArgumentException ex) { } Assert.assertNull(root.find(new String[]{"a"}, true)); Assert.assertNull(root.find(new String[]{"a"}, false)); Assert.assertNull(root.findPrefixEntry(Lists.newArrayList("a"))); root.delete(); }
@Test public void testRootPrefixEntry() { HMSPaths.Entry root = HMSPaths.Entry.createRoot(true); root.toString(); Assert.assertNull(root.find(new String[]{"a"}, true)); Assert.assertNull(root.find(new String[]{"a"}, false)); Assert.assertEquals(root, root.findPrefixEntry(Lists.newArrayList("a"))); Assert.assertEquals(root, root.findPrefixEntry(Lists.newArrayList("a", "b"))); try { root.createPrefix(Lists.newArrayList("a")); Assert.fail(); } catch (IllegalArgumentException ex) { } }
@Test public void testImmediatePrefixEntry() { HMSPaths.Entry root = HMSPaths.Entry.createRoot(false); HMSPaths.Entry entry = root.createPrefix(Lists.newArrayList("a")); entry.toString(); Assert.assertEquals(1, root.childrenValues().size()); Assert.assertEquals(root, entry.getParent()); Assert.assertEquals(HMSPaths.EntryType.PREFIX, entry.getType()); Assert.assertEquals("a", entry.getPathElement()); Assert.assertEquals(0, entry.getAuthzObjsSize()); Assert.assertTrue(entry.isAuthzObjsEmpty()); Assert.assertEquals(0, entry.getAuthzObjs().size()); Assert.assertEquals(Path.SEPARATOR + "a", entry.getFullPath()); Assert.assertFalse(entry.hasChildren()); Assert.assertEquals(entry, root.findPrefixEntry(Lists.newArrayList("a"))); Assert.assertEquals(entry, root.findPrefixEntry(Lists.newArrayList("a", "b"))); Assert.assertNull(root.find(new String[]{"a", "b"}, false)); Assert.assertNull(root.find(new String[]{"b"}, false)); Assert.assertNull(root.findPrefixEntry(Lists.newArrayList("b"))); try { root.createPrefix(Lists.newArrayList("a", "b")); Assert.fail(); } catch (IllegalArgumentException ex) { } try { root.createPrefix(Lists.newArrayList("a", "b", "c")); Assert.fail(); } catch (IllegalArgumentException ex) { } entry.delete(); Assert.assertFalse(root.hasChildren()); }
@Test public void testFurtherPrefixEntry() { HMSPaths.Entry root = HMSPaths.Entry.createRoot(false); HMSPaths.Entry entry = root.createPrefix(Lists.newArrayList("a", "b")); entry.toString(); Assert.assertEquals(1, root.childrenValues().size()); Assert.assertEquals(root, entry.getParent().getParent()); Assert.assertEquals(HMSPaths.EntryType.PREFIX, entry.getType()); Assert.assertEquals(HMSPaths.EntryType.DIR, entry.getParent().getType()); Assert.assertEquals("b", entry.getPathElement()); Assert.assertEquals("a", entry.getParent().getPathElement()); Assert.assertTrue(entry.getAuthzObjsSize() == 0); Assert.assertTrue(entry.isAuthzObjsEmpty()); Assert.assertTrue(entry.getParent().getAuthzObjsSize() == 0); Assert.assertTrue(entry.getAuthzObjs().size() == 0); Assert.assertTrue(entry.getParent().getAuthzObjs().size() == 0); Assert.assertEquals(Path.SEPARATOR + "a" + Path.SEPARATOR + "b", entry.getFullPath()); Assert.assertEquals(Path.SEPARATOR + "a", entry.getParent().getFullPath()); Assert.assertFalse(entry.hasChildren()); Assert.assertEquals(1, entry.getParent().childrenValues().size()); Assert.assertEquals(entry, root.findPrefixEntry(Lists.newArrayList("a", "b"))); Assert.assertNull(root.findPrefixEntry(Lists.newArrayList("a"))); Assert.assertNull(root.find(new String[]{"a", "b", "c"}, false)); try { root.createPrefix(Lists.newArrayList("a", "b")); Assert.fail(); } catch (IllegalArgumentException ex) { } try { root.createPrefix(Lists.newArrayList("a", "b", "c")); Assert.fail(); } catch (IllegalArgumentException ex) { } entry.delete(); Assert.assertFalse(root.hasChildren()); }