AuthorizablePropertiesImpl implements AuthorizableProperties { @Override public boolean removeProperty(@NotNull String relPath) throws RepositoryException { String oakPath = getOakPath(relPath); Tree node = getTree(); TreeLocation propertyLocation = getLocation(node, oakPath); if (propertyLocation.getProperty() != null) { if (isAuthorizableProperty(node, propertyLocation, true)) { return propertyLocation.remove(); } else { throw new ConstraintViolationException("Property " + relPath + " isn't a modifiable authorizable property"); } } else { checkScope(node.getPath(), propertyLocation.getPath(), relPath); } return false; } AuthorizablePropertiesImpl(@NotNull AuthorizableImpl authorizable,
                               @NotNull PartialValueFactory valueFactory); @NotNull @Override Iterator<String> getNames(@NotNull String relPath); @Override boolean hasProperty(@NotNull String relPath); @Override Value[] getProperty(@NotNull String relPath); @Override void setProperty(@NotNull String relPath, @Nullable Value value); @Override void setProperty(@NotNull String relPath, @Nullable Value[] values); @Override boolean removeProperty(@NotNull String relPath);  }
@Test(expected = ConstraintViolationException.class) public void testRemoveAuthorizableId() throws Exception { properties.removeProperty(UserConstants.REP_AUTHORIZABLE_ID); }
@Test(expected = ConstraintViolationException.class) public void testRemovePrimaryType() throws Exception { properties.removeProperty("relPath/" + JcrConstants.JCR_PRIMARYTYPE); }
@Test public void testRemoveNonExisting() throws Exception { assertFalse(properties.removeProperty("nonExisting")); assertFalse(properties.removeProperty("relPath/nonExisting")); assertFalse(emptyProperties.removeProperty("prop")); }
@Test public void testRemove() throws Exception { assertTrue(properties.removeProperty("mvProp")); assertTrue(properties.removeProperty("relPath/prop")); }
@Test(expected = RepositoryException.class) public void testRemoveMissingResolutionToOakPath() throws Exception { AuthorizableProperties props = new AuthorizablePropertiesImpl((AuthorizableImpl) user2, new PartialValueFactory(new NamePathMapper.Default() { @Override public String getOakNameOrNull(@NotNull String jcrName) { return null; } @Override public String getOakPath(String jcrPath) { return null; } })); props.removeProperty("relPath/prop"); }
@Test(expected = RepositoryException.class) public void testRemovePropertyOutSideScope() throws Exception { properties.removeProperty("../../" + JcrConstants.JCR_PRIMARYTYPE); }
@Test(expected = RepositoryException.class) public void testRemoveNonExistingPropertyOutSideScope() throws Exception { properties.removeProperty("../../nonExistingTree/nonExistingProp"); }
@Test(expected = RepositoryException.class) public void testRemovePropertyOtherUser() throws Exception { emptyProperties.removeProperty("../" + PathUtils.getName(user2.getPath()) + "/prop"); }