ACE implements JackrabbitAccessControlEntry { @Nullable @Override public Value getRestriction(@NotNull String restrictionName) throws RepositoryException { for (Restriction restriction : restrictions) { String jcrName = getJcrName(restriction); if (jcrName.equals(restrictionName)) { if (restriction.getDefinition().getRequiredType().isArray()) { List<Value> values = valueFactory.createValues(restriction.getProperty()); switch (values.size()) { case 1: return values.get(0); default : throw new ValueFormatException("Attempt to retrieve single value from multivalued property"); } } else { return valueFactory.createValue(restriction.getProperty()); } } } return null; } 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 testGetRestrictionForEmpty() throws Exception { Value val = createEntry().getRestriction(AccessControlConstants.REP_GLOB); assertNull(val); }
@Test public void testGetNonExistingRestriction() throws Exception { Restriction globRestr = createRestriction(AccessControlConstants.REP_GLOB, globValue); ACE ace = createEntry(globRestr); assertNull(ace.getRestriction(AccessControlConstants.REP_NT_NAMES)); }
@Test public void testGetRestrictionForSingleValued() throws Exception { Restriction globRestr = createRestriction(AccessControlConstants.REP_GLOB, globValue); ACE ace = createEntry(globRestr); Value val = ace.getRestriction(AccessControlConstants.REP_GLOB); assertNotNull(val); assertEquals(globValue, val); }
@Test(expected = ValueFormatException.class) public void testGetRestrictionForMultiValued() throws Exception { Restriction nameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, nameValues); ACE ace = createEntry(nameRestr); ace.getRestriction(AccessControlConstants.REP_NT_NAMES); }
@Test public void testGetRestrictionForMultiValued2() throws Exception { Restriction singleNameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, new Value[] {nameValue}); ACE ace = createEntry(singleNameRestr); Value val = ace.getRestriction(AccessControlConstants.REP_NT_NAMES); assertEquals(nameValue, val); }