AbstractRestrictionProvider implements RestrictionProvider, AccessControlConstants { @NotNull @Override public Restriction createRestriction(String oakPath, @NotNull String oakName, @NotNull Value value) throws RepositoryException { RestrictionDefinition definition = getDefinition(oakPath, oakName); Type<?> requiredType = definition.getRequiredType(); int tag = requiredType.tag(); if (tag != PropertyType.UNDEFINED && tag != value.getType()) { throw new AccessControlException("Unsupported restriction: Expected value of type " + requiredType + " for " + oakName); } PropertyState propertyState; if (requiredType.isArray()) { propertyState = PropertyStates.createProperty(oakName, ImmutableList.of(value), tag); } else { propertyState = PropertyStates.createProperty(oakName, value); } return createRestriction(propertyState, definition); } AbstractRestrictionProvider(@NotNull Map<String, ? extends RestrictionDefinition> definitions); @NotNull @Override Set<RestrictionDefinition> getSupportedRestrictions(String oakPath); @NotNull @Override Restriction createRestriction(String oakPath, @NotNull String oakName, @NotNull Value value); @NotNull @Override Restriction createRestriction(String oakPath, @NotNull String oakName, @NotNull Value... values); @NotNull @Override Set<Restriction> readRestrictions(String oakPath, @NotNull Tree aceTree); @Override void writeRestrictions(String oakPath, Tree aceTree, Set<Restriction> restrictions); @Override void validateRestrictions(String oakPath, @NotNull Tree aceTree);  }
@Test(expected = AccessControlException.class) public void testCreateForUnsupportedPath() throws Exception { restrictionProvider.createRestriction(unsupportedPath, REP_GLOB, globValue); }
@Test(expected = AccessControlException.class) public void testCreateForUnsupportedName() throws Exception { restrictionProvider.createRestriction(testPath, "unsupported", nameValue); }
@Test(expected = AccessControlException.class) public void testCreateForUnsupportedType() throws Exception { restrictionProvider.createRestriction(testPath, REP_NT_NAMES, valueFactory.createValue("nt:file", PropertyType.NAME), valueFactory.createValue(true)); }
@Test(expected = AccessControlException.class) public void testCreateForUnsupportedMultiValues() throws Exception { restrictionProvider.createRestriction(testPath, REP_GLOB, valueFactory.createValue("*"), valueFactory.createValue("/a/*")); }
@Test public void testCreateRestriction() throws Exception { Restriction r = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue); assertNotNull(r); assertEquals(REP_GLOB, r.getDefinition().getName()); assertEquals(globValue.getString(), r.getProperty().getValue(Type.STRING)); }
@Test public void testCreatedUndefinedType() throws Exception { Restriction r = restrictionProvider.createRestriction(testPath, "undefined", valueFactory.createValue(23)); }
@Test(expected = AccessControlException.class) public void testCreateUndefinedTypeMV() throws Exception { Restriction r2 = restrictionProvider.createRestriction(testPath, "undefined", valueFactory.createValue(23), valueFactory.createValue(false)); }