CompositeRestrictionProvider implements RestrictionProvider { @NotNull @Override public Restriction createRestriction(@Nullable String oakPath, @NotNull String oakName, @NotNull Value value) throws RepositoryException { return getProvider(oakPath, oakName).createRestriction(oakPath, oakName, value); } private  CompositeRestrictionProvider(@NotNull Collection<? extends RestrictionProvider> providers); static RestrictionProvider newInstance(@NotNull RestrictionProvider... providers); static RestrictionProvider newInstance(@NotNull Collection<? extends RestrictionProvider> providers); @NotNull @Override Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath); @NotNull @Override Restriction createRestriction(@Nullable String oakPath, @NotNull String oakName, @NotNull Value value); @NotNull @Override Restriction createRestriction(@Nullable String oakPath, @NotNull String oakName, @NotNull Value... values); @NotNull @Override Set<Restriction> readRestrictions(@Nullable String oakPath, @NotNull Tree aceTree); @Override void writeRestrictions(String oakPath, Tree aceTree, Set<Restriction> restrictions); @Override void validateRestrictions(@Nullable String oakPath, @NotNull Tree aceTree); @NotNull @Override RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree); @NotNull @Override RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions);  }
@Test public void testCreateRestriction() throws Exception { Map<String, Value> valid = ImmutableMap.of( NAME_BOOLEAN, vf.createValue(true), NAME_LONGS, vf.createValue(10), REP_GLOB, vf.createValue("*") ); for (String name : valid.keySet()) { provider.createRestriction("/testPath", name, valid.get(name)); } }
@Test(expected = AccessControlException.class) public void testCreateRestrictionWithInvalidPath() throws Exception { provider.createRestriction(null, REP_GLOB, vf.createValue("*")); }
@Test public void testCreateInvalidRestriction() throws Exception { Map<String, Value> invalid = ImmutableMap.of( NAME_BOOLEAN, vf.createValue("wrong_type"), REP_GLOB, vf.createValue(true) ); for (String name : invalid.keySet()) { try { provider.createRestriction("/testPath", name, invalid.get(name)); fail("invalid restriction " + name); } catch (AccessControlException e) { } } }
@Test public void testMvCreateRestriction() throws RepositoryException { Map<String, Value[]> valid = ImmutableMap.of( NAME_LONGS, new Value[] {vf.createValue(100)}, REP_PREFIXES, new Value[] {vf.createValue("prefix"), vf.createValue("prefix2")} ); for (String name : valid.keySet()) { provider.createRestriction("/testPath", name, valid.get(name)); } }
@Test(expected = AccessControlException.class) public void testCreateMvRestrictionWithInvalidPath() throws Exception { provider.createRestriction(null, REP_PREFIXES, new Value[] {vf.createValue("jcr")}); }
@Test public void testCreateInvalidMvRestriction() throws Exception { Map<String, Value[]> invalid = ImmutableMap.of( NAME_BOOLEAN, new Value[] {vf.createValue(true), vf.createValue(false)}, NAME_LONGS, new Value[] {vf.createValue("wrong_type")}, REP_PREFIXES, new Value[] {vf.createValue(true)} ); for (String name : invalid.keySet()) { try { provider.createRestriction("/testPath", name, invalid.get(name)); fail("invalid restriction " + name); } catch (AccessControlException e) { } } }