PermissionStoreImpl implements PermissionStore, PermissionConstants { @NotNull @Override public NumEntries getNumEntries(@NotNull String principalName, long max) { Tree tree = getPrincipalRoot(principalName); if (tree == null) { return NumEntries.ZERO; } else { long l = TreeUtil.getLong(tree, REP_NUM_PERMISSIONS, -1); return (l >= 0) ? NumEntries.valueOf(l, true) : NumEntries.valueOf(tree.getChildrenCount(max), false); } } PermissionStoreImpl(@NotNull Root root, @NotNull String permissionRootName, @NotNull RestrictionProvider restrictionProvider); @Override void flush(@NotNull Root root); @Nullable @Override Collection<PermissionEntry> load(@NotNull String principalName, @NotNull String path); @NotNull @Override NumEntries getNumEntries(@NotNull String principalName, long max); @Override @NotNull PrincipalPermissionEntries load(@NotNull String principalName);  }
@Test public void testGetNumEntries() { assertEquals(NumEntries.valueOf(2, true), permissionStore.getNumEntries(EveryonePrincipal.NAME, Long.MAX_VALUE)); }
@Test public void testGetNumEntriesMissingPrincipalRoot() { assertEquals(NumEntries.valueOf(0, true), permissionStore.getNumEntries(testPrincipal.getName(), Long.MAX_VALUE)); }
@Test public void testGetNumEntriesMissingProperty() throws Exception { try { Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME); everyoneTree.removeProperty(REP_NUM_PERMISSIONS); assertEquals(NumEntries.valueOf(2, false), permissionStore.getNumEntries(EveryonePrincipal.NAME, Long.MAX_VALUE)); } finally { root.refresh(); } }
@Test public void testGetNumEntriesMissingPropertyThreshold() throws Exception { try { Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME); everyoneTree.removeProperty(REP_NUM_PERMISSIONS); long max = 1; assertEquals(NumEntries.valueOf(everyoneTree.getChildrenCount(max), false), permissionStore.getNumEntries(EveryonePrincipal.NAME, max)); } finally { root.refresh(); } }