ACE implements JackrabbitAccessControlEntry { @NotNull public Set<Restriction> getRestrictions() { return restrictions; } ACE(Principal principal, PrivilegeBits privilegeBits,
               boolean isAllow, Set<Restriction> restrictions, NamePathMapper namePathMapper); @NotNull PrivilegeBits getPrivilegeBits(); @NotNull Set<Restriction> getRestrictions(); @NotNull @Override Principal getPrincipal(); @Override boolean isAllow(); @NotNull @Override String[] getRestrictionNames(); @Nullable @Override Value getRestriction(@NotNull String restrictionName); @Nullable @Override Value[] getRestrictions(@NotNull String restrictionName); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testNullRestrictions() throws Exception { ACE ace = new ACE(testPrincipal, PrivilegeBits.BUILT_IN.get(PrivilegeConstants.JCR_READ), true, null, getNamePathMapper()) { @Override public Privilege[] getPrivileges() { return new Privilege[0]; } }; assertTrue(ace.getRestrictions().isEmpty()); }
@Test public void testRestrictions() throws Exception { Restriction r = new RestrictionImpl(PropertyStates.createProperty("r", "v"), false); Restriction r2 = new RestrictionImpl(PropertyStates.createProperty("r2", ImmutableList.of("v"), Type.STRINGS), false); Set<Restriction> restrictions = Sets.newHashSet(r, r2); ACE ace = new ACE(testPrincipal, PrivilegeBits.BUILT_IN.get(PrivilegeConstants.JCR_READ), true, restrictions, getNamePathMapper()) { @Override public Privilege[] getPrivileges() { return new Privilege[0]; } }; assertFalse(ace.getRestrictions().isEmpty()); assertNotSame(restrictions, ace.getRestrictions()); assertTrue(Iterables.elementsEqual(restrictions, ace.getRestrictions())); }
@Test public void testGetEmptyRestrictions() throws Exception { Value[] vs = createEntry().getRestrictions(AccessControlConstants.REP_GLOB); assertNull(vs); }
@Test public void testGetNonExistingRestrictions() throws Exception { Restriction nameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, nameValues); ACE ace = createEntry(nameRestr); assertNull(ace.getRestrictions(AccessControlConstants.REP_GLOB)); }
@Test public void testGetRestrictionsForSingleValue() throws Exception { Restriction globRestr = createRestriction(AccessControlConstants.REP_GLOB, globValue); ACE ace = createEntry(globRestr); Value[] vs = ace.getRestrictions(AccessControlConstants.REP_GLOB); assertNotNull(vs); assertArrayEquals(new Value[] {globValue}, vs); }
@Test public void testGetRestrictionsForMultiValued() throws Exception { Restriction nameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, nameValues); ACE ace = createEntry(nameRestr); Value[] vs = ace.getRestrictions(AccessControlConstants.REP_NT_NAMES); assertEquals(2, vs.length); assertArrayEquals(nameValues, vs); }
@Test public void testGetRestrictionsForMultiValued2() throws Exception { Restriction singleNameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, new Value[]{nameValue}); ACE ace = createEntry(singleNameRestr); Value[] vs = ace.getRestrictions(AccessControlConstants.REP_NT_NAMES); assertEquals(1, vs.length); assertEquals(nameValue, vs[0]); }
@Test public void testGetRestrictions() throws Exception { Restriction nameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, nameValues); Restriction globRestr = createRestriction(AccessControlConstants.REP_GLOB, globValue); Set<Restriction> expected = ImmutableSet.of(nameRestr, globRestr); ACE ace = createEntry(nameRestr, globRestr); assertEquals(expected, ace.getRestrictions()); }
@Test public void testGetRestrictionsNone() throws Exception { ACE ace = createEntry(testPrincipal, PrivilegeBits.BUILT_IN.get(PrivilegeConstants.JCR_READ), true); assertTrue(ace.getRestrictions().isEmpty()); }