PrincipalRestrictionProvider implements RestrictionProvider, AccessControlConstants { @NotNull @Override public Restriction createRestriction(@Nullable String oakPath, @NotNull String oakName, @NotNull Value value) throws RepositoryException { if (REP_NODE_PATH.equals(oakName)) { PropertyState property; if (value.getString().isEmpty()) { property = PropertyStates.createProperty(oakName, "", Type.STRING); } else { property = PropertyStates.createProperty(oakName, value); } return new RestrictionImpl(property, true); } else { return base.createRestriction(oakPath, oakName, value); } } PrincipalRestrictionProvider(RestrictionProvider base); @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(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 { Restriction r = mock(Restriction.class); Value v = mock(Value.class); when(base.createRestriction("/testPath", "name", v)).thenReturn(r); assertSame(r, provider.createRestriction("/testPath", "name", v)); verify(base, times(1)).createRestriction("/testPath", "name", v); }
@Test public void testCreateNodePathRestriction() throws Exception { Value emptyV = when(mock(Value.class).getString()).thenReturn("").getMock(); Restriction r = provider.createRestriction("/testPath", REP_NODE_PATH, emptyV); assertTrue(r instanceof RestrictionImpl); assertTrue(r.getDefinition().isMandatory()); assertEquals("", r.getProperty().getValue(Type.STRING)); Value v = getValueFactory(root).createValue("/path"); r = provider.createRestriction("/testPath", REP_NODE_PATH, v); assertTrue(r instanceof RestrictionImpl); assertEquals("/path", r.getProperty().getValue(Type.STRING)); verify(base, never()).createRestriction(anyString(), anyString(), any(Value.class)); }