Author: angela
Date: Thu Apr  4 16:39:33 2019
New Revision: 1856959

URL: http://svn.apache.org/viewvc?rev=1856959&view=rev
Log:
OAK-8195 : AutoSaveEnabledManager.createSystemUser calls createUser on delegatee

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableImplTest.java
   (with props)
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapperTest.java
   (with props)
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/GroupImplTest.java
   (with props)
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/UserImplTest.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AbstractAutoSaveTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableByTypeTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java?rev=1856959&r1=1856958&r2=1856959&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManager.java
 Thu Apr  4 16:39:33 2019
@@ -120,7 +120,7 @@ public class AutoSaveEnabledManager impl
     @Override
     public User createSystemUser(String userID, String intermediatePath) 
throws RepositoryException {
         try {
-            return wrap(dlg.createUser(userID, intermediatePath));
+            return wrap(dlg.createSystemUser(userID, intermediatePath));
         } finally {
             autosave();
         }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AbstractAutoSaveTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AbstractAutoSaveTest.java?rev=1856959&r1=1856958&r2=1856959&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AbstractAutoSaveTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AbstractAutoSaveTest.java
 Thu Apr  4 16:39:33 2019
@@ -16,29 +16,22 @@
  */
 package org.apache.jackrabbit.oak.security.user.autosave;
 
-import java.util.Collections;
-
-import com.google.common.collect.ImmutableMap;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.AbstractSecurityTest;
-import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
-import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
-import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.spy;
 
 public abstract class AbstractAutoSaveTest extends AbstractSecurityTest {
 
-    UserManager mgr;
+    UserManager mgrDlg;
+    AutoSaveEnabledManager autosaveMgr;
 
     @Override
     public void before() throws Exception {
         super.before();
-        mgr = getUserManager(root);
-    }
-
-    @Override
-    protected ConfigurationParameters getSecurityConfigParameters() {
-        ConfigurationParameters userConfig = ConfigurationParameters.of(
-                Collections.singletonMap(UserConstants.PARAM_SUPPORT_AUTOSAVE, 
Boolean.TRUE));
-        return 
ConfigurationParameters.of(ImmutableMap.of(UserConfiguration.NAME, userConfig));
+        mgrDlg = spy(getUserManager(root));
+        assertFalse(mgrDlg instanceof AutoSaveEnabledManager);
+        autosaveMgr = spy(new AutoSaveEnabledManager(mgrDlg, root));
     }
 }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableByTypeTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableByTypeTest.java?rev=1856959&r1=1856958&r2=1856959&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableByTypeTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableByTypeTest.java
 Thu Apr  4 16:39:33 2019
@@ -36,8 +36,8 @@ public class AuthorizableByTypeTest exte
     public void before() throws Exception {
         super.before();
 
-        user = getTestUser();
-        group = mgr.createGroup("testGroup" + UUID.randomUUID());
+        user = autosaveMgr.getAuthorizable(getTestUser().getID(), User.class);
+        group = autosaveMgr.createGroup("testGroup" + UUID.randomUUID());
         root.commit();
     }
 
@@ -56,37 +56,37 @@ public class AuthorizableByTypeTest exte
 
     @Test
     public void testUserByIdAndType() throws Exception {
-        User u = mgr.getAuthorizable(user.getID(), User.class);
+        User u = autosaveMgr.getAuthorizable(user.getID(), User.class);
         assertTrue(u instanceof UserImpl);
 
-        Authorizable auth = mgr.getAuthorizable(user.getID(), user.getClass());
+        Authorizable auth = autosaveMgr.getAuthorizable(user.getID(), 
user.getClass());
         assertTrue(auth instanceof UserImpl);
 
-        auth = mgr.getAuthorizable(user.getID(), Authorizable.class);
+        auth = autosaveMgr.getAuthorizable(user.getID(), Authorizable.class);
         assertTrue(auth instanceof AuthorizableImpl);
     }
 
     @Test
     public void testGroupByIdAndType() throws Exception {
-        Group g = mgr.getAuthorizable(group.getID(), Group.class);
+        Group g = autosaveMgr.getAuthorizable(group.getID(), Group.class);
         assertTrue(g instanceof GroupImpl);
 
-        Authorizable auth = mgr.getAuthorizable(group.getID(), 
group.getClass());
+        Authorizable auth = autosaveMgr.getAuthorizable(group.getID(), 
group.getClass());
         assertTrue(auth instanceof GroupImpl);
 
-        auth = mgr.getAuthorizable(group.getID(), Authorizable.class);
+        auth = autosaveMgr.getAuthorizable(group.getID(), Authorizable.class);
         assertTrue(auth instanceof AuthorizableImpl);
     }
 
     @Test(expected = AuthorizableTypeException.class)
     public void testUserByIdAndWrongType() throws Exception {
-        mgr.getAuthorizable(user.getID(), Group.class);
+        autosaveMgr.getAuthorizable(user.getID(), Group.class);
         fail("Wrong Authorizable type is not detected.");
     }
 
     @Test(expected = AuthorizableTypeException.class)
     public void testGroupByIdAndWrongType() throws Exception {
-        mgr.getAuthorizable(group.getID(), User.class);
+        autosaveMgr.getAuthorizable(group.getID(), User.class);
         fail("Wrong Authorizable type is not detected.");
     }
 }

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableImplTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableImplTest.java?rev=1856959&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableImplTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableImplTest.java
 Thu Apr  4 16:39:33 2019
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.user.autosave;
+
+import com.google.common.collect.Iterators;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class AuthorizableImplTest extends AbstractAutoSaveTest {
+
+    private Authorizable dlg;
+    private AuthorizableImpl a;
+
+    @Before
+    @Override
+    public void before() throws Exception {
+        super.before();
+        Authorizable u = mgrDlg.createUser("u", "u");
+        root.commit();
+
+        dlg = spy(u);
+        assertFalse(dlg instanceof AuthorizableImpl);
+        a = new AuthorizableImpl(dlg, autosaveMgr);
+    }
+
+    @After
+    @Override
+    public void after() throws Exception {
+        try {
+            root.refresh();
+            Authorizable a = mgrDlg.getAuthorizable("u");
+            if (a != null) {
+                a.remove();
+                root.commit();
+            }
+        } finally {
+            super.after();
+        }
+    }
+
+    @Test
+    public void testGetDlg() throws RepositoryException {
+        assertSame(dlg, a.getDlg());
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetMgr() throws RepositoryException {
+        assertSame(autosaveMgr, a.getMgr());
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetId() throws Exception {
+        assertEquals(dlg.getID(), a.getID());
+        verify(dlg, times(2)).getID();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testIsGroup() throws RepositoryException {
+        assertEquals(dlg.isGroup(), a.isGroup());
+        verify(dlg, times(2)).isGroup();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetPrincipal() throws Exception {
+        assertEquals(dlg.getPrincipal(), a.getPrincipal());
+        verify(dlg, times(2)).getPrincipal();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testDeclaredMemberOf() throws Exception {
+        assertTrue(Iterators.elementsEqual(dlg.declaredMemberOf(), 
a.declaredMemberOf()));
+        verify(dlg, times(2)).declaredMemberOf();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testMemberOf() throws Exception {
+        assertTrue(Iterators.elementsEqual(dlg.memberOf(), a.memberOf()));
+        verify(dlg, times(2)).memberOf();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testRemove() throws Exception {
+        a.remove();
+        verify(dlg, times(1)).remove();
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testGetPropertyNames() throws Exception {
+        assertTrue(Iterators.elementsEqual(dlg.getPropertyNames(), 
a.getPropertyNames()));
+        verify(dlg, times(2)).getPropertyNames();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetPropertyNamesRelPath() throws Exception {
+        assertTrue(Iterators.elementsEqual(dlg.getPropertyNames("."), 
a.getPropertyNames(".")));
+        verify(dlg, times(2)).getPropertyNames(".");
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testHasProperty() throws Exception {
+        assertEquals(dlg.hasProperty("propName"), a.hasProperty("propName"));
+        verify(dlg, times(2)).hasProperty("propName");
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testSetProperty() throws Exception {
+        Value v = getValueFactory(root).createValue(23);
+        a.setProperty("propName", v);
+        verify(dlg, times(1)).setProperty("propName", v);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testSetPropertyMv() throws Exception {
+        Value[] v = new Value[] {};
+        a.setProperty("propName", v);
+        verify(dlg, times(1)).setProperty("propName", v);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testGetProperty() throws Exception {
+        assertNull(a.getProperty("propName"));
+        verify(dlg, times(1)).getProperty("propName");
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testRemoveProperty() throws Exception {
+        assertFalse(a.removeProperty("propName"));
+        verify(dlg, times(1)).removeProperty("propName");
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testGetPath() throws Exception {
+        assertEquals(dlg.getPath(), a.getPath());
+        verify(dlg, times(2)).getPath();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testToString() throws Exception {
+        Authorizable dlg = getTestUser();
+        assertEquals(dlg.toString(), new AuthorizableImpl(dlg, 
autosaveMgr).toString());
+    }
+
+    @Test
+    public void testHashCode() throws Exception {
+        Authorizable dlg = getTestUser();
+        assertEquals(dlg.hashCode(), new AuthorizableImpl(dlg, 
autosaveMgr).hashCode());
+    }
+
+    @Test
+    public void testEquals() throws Exception {
+        Authorizable dlg = getTestUser();
+        AuthorizableImpl wrapped = new AuthorizableImpl(dlg, autosaveMgr);
+        assertEquals(wrapped,  wrapped);
+        assertEquals(wrapped, new AuthorizableImpl(dlg, autosaveMgr));
+        assertEquals(wrapped, new UserImpl(getTestUser(), new 
AutoSaveEnabledManager(getUserManager(root), root)));
+    }
+
+    @Test
+    public void testNotEquals() throws Exception {
+        Authorizable dlg = getTestUser();
+        AuthorizableImpl wrapped = new AuthorizableImpl(dlg, autosaveMgr);
+        assertNotEquals(wrapped, dlg);
+        assertNotEquals(wrapped, null);
+
+        Authorizable mock = mock(Authorizable.class);
+        assertNotEquals(wrapped, mock);
+
+        mock = mock(AuthorizableImpl.class);
+        assertNotEquals(wrapped, mock);
+    }
+}
\ No newline at end of file

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapperTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapperTest.java?rev=1856959&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapperTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapperTest.java
 Thu Apr  4 16:39:33 2019
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.user.autosave;
+
+import com.google.common.collect.Lists;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.junit.Test;
+
+import java.util.Iterator;
+
+import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class AuthorizableWrapperTest extends AbstractAutoSaveTest {
+
+    @Test
+    public void testApplyNull() {
+        Iterator<Authorizable> it = 
AuthorizableWrapper.createIterator(Lists.newArrayList(null, (Authorizable) 
null).iterator(), autosaveMgr);
+        while(it.hasNext()) {
+            assertNull(it.next());
+        }
+        verify(autosaveMgr, never()).wrap(any(Authorizable.class));
+    }
+
+    @Test
+    public void testApply() throws Exception {
+        Iterator<Authorizable> it = 
AuthorizableWrapper.createIterator(Lists.newArrayList(getTestUser(), 
(Authorizable) null).iterator(), autosaveMgr);
+        while(it.hasNext()) {
+            it.next();
+        }
+        verify(autosaveMgr, times(1)).wrap(any(Authorizable.class));
+    }
+}
\ No newline at end of file

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AuthorizableWrapperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java?rev=1856959&r1=1856958&r2=1856959&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/AutoSaveEnabledManagerTest.java
 Thu Apr  4 16:39:33 2019
@@ -16,84 +16,108 @@
  */
 package org.apache.jackrabbit.oak.security.user.autosave;
 
-import java.security.Principal;
-import java.util.Iterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.Impersonation;
+import org.apache.jackrabbit.api.security.user.Query;
 import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
-import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.query.QueryEngineSettings;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.junit.After;
 import org.junit.Test;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import java.security.Principal;
+import java.util.Iterator;
+
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 public class AutoSaveEnabledManagerTest extends AbstractAutoSaveTest {
 
+    @After
     @Override
     public void after() throws Exception {
-        Authorizable a = mgr.getAuthorizable("u");
-        if (a != null) {
-            a.remove();
-        }
-        a = mgr.getAuthorizable("g");
-        if (a != null) {
-            a.remove();
-        }
-        if (root.hasPendingChanges()) {
-            root.commit();
+        try {
+            Authorizable a = mgrDlg.getAuthorizable("u");
+            if (a != null) {
+                a.remove();
+            }
+            a = mgrDlg.getAuthorizable("g");
+            if (a != null) {
+                a.remove();
+            }
+            if (root.hasPendingChanges()) {
+                root.commit();
+            }
+        } finally {
+            super.after();
         }
-        super.after();
     }
 
     @Override
-    protected ConfigurationParameters getSecurityConfigParameters() {
-        ConfigurationParameters userConfig = ConfigurationParameters.of(
-                UserConstants.PARAM_SUPPORT_AUTOSAVE, Boolean.TRUE);
-        return ConfigurationParameters.of(UserConfiguration.NAME, userConfig);
+    protected QueryEngineSettings getQueryEngineSettings() {
+        if (querySettings == null) {
+            querySettings = new QueryEngineSettings();
+            querySettings.setFailTraversal(false);
+        }
+        return querySettings;
+    }
+
+    @Test
+    public void testIsAutoSave() {
+        assertTrue(autosaveMgr.isAutoSave());
+        verify(mgrDlg, never()).isAutoSave();
     }
 
     @Test
-    public void testAutoSaveEnabled() throws RepositoryException {
-        assertTrue(mgr instanceof AutoSaveEnabledManager);
-        assertTrue(mgr.isAutoSave());
+    public void testSetAutoSave() throws Exception {
+        assertTrue(autosaveMgr.isAutoSave());
+
+        autosaveMgr.autoSave(false);
+        assertFalse(autosaveMgr.isAutoSave());
+        autosaveMgr.autoSave(true);
 
-        mgr.autoSave(false);
-        assertFalse(mgr.isAutoSave());
-        mgr.autoSave(true);
+        assertTrue(autosaveMgr.isAutoSave());
+
+        verify(mgrDlg, never()).isAutoSave();
+        verify(mgrDlg, never()).autoSave(true);
+        verify(mgrDlg, never()).autoSave(false);
     }
 
     @Test
     public void testGetAuthorizable() throws RepositoryException {
-        Authorizable a = 
mgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
+        Authorizable a = 
autosaveMgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
         assertNotNull(a);
         assertTrue(a instanceof AuthorizableImpl);
         assertTrue(a instanceof UserImpl);
 
-        a = mgr.getAuthorizableByPath(a.getPath());
+        a = autosaveMgr.getAuthorizableByPath(a.getPath());
         assertNotNull(a);
         assertTrue(a instanceof AuthorizableImpl);
         assertTrue(a instanceof UserImpl);
 
-        a = mgr.getAuthorizable(a.getPrincipal());
+        a = autosaveMgr.getAuthorizable(a.getPrincipal());
         assertNotNull(a);
         assertTrue(a instanceof AuthorizableImpl);
         assertTrue(a instanceof UserImpl);
 
-        assertNull(mgr.getAuthorizable("unknown"));
+        assertNull(autosaveMgr.getAuthorizable("unknown"));
     }
 
     @Test
     public void testFindAuthorizable() throws RepositoryException {
-        Iterator<Authorizable> res = 
mgr.findAuthorizables(UserConstants.REP_AUTHORIZABLE_ID, 
UserConstants.DEFAULT_ANONYMOUS_ID);
+        Iterator<Authorizable> res = 
autosaveMgr.findAuthorizables(UserConstants.REP_AUTHORIZABLE_ID, 
UserConstants.DEFAULT_ANONYMOUS_ID);
         assertTrue(res.hasNext());
 
         Authorizable a = res.next();
@@ -102,47 +126,106 @@ public class AutoSaveEnabledManagerTest
     }
 
     @Test
-    public void testIsAutoSave() {
-        assertTrue(mgr.isAutoSave());
+    public void testFindAuthorizableWithSearchType() throws 
RepositoryException {
+        Iterator<Authorizable> res = 
autosaveMgr.findAuthorizables(UserConstants.REP_AUTHORIZABLE_ID, 
UserConstants.DEFAULT_ANONYMOUS_ID, UserManager.SEARCH_TYPE_GROUP);
+        assertFalse(res.hasNext());
+
+        verify(mgrDlg, 
times(1)).findAuthorizables(UserConstants.REP_AUTHORIZABLE_ID, 
UserConstants.DEFAULT_ANONYMOUS_ID, UserManager.SEARCH_TYPE_GROUP);
+        verify(autosaveMgr, never()).autosave();
     }
 
     @Test
-    public void testAutoSave() throws RepositoryException {
-        mgr.autoSave(false);
-        mgr.autoSave(true);
+    public void testFindAuthorizableWithQuery() throws RepositoryException {
+        Query q = mock(Query.class);
+        autosaveMgr.findAuthorizables(q);
+
+        verify(mgrDlg, times(1)).findAuthorizables(q);
+        verify(autosaveMgr, never()).autosave();
     }
 
     @Test
     public void testCreateRemoveUser() throws RepositoryException {
-        User u = mgr.createUser("u", "u");
+        User u = autosaveMgr.createUser("u", "u");
         assertFalse(root.hasPendingChanges());
         u.remove();
         assertFalse(root.hasPendingChanges());
     }
 
     @Test
+    public void testCreateUserWithPath() throws Exception {
+        autosaveMgr.createUser("u", "u", new PrincipalImpl("u"), "rel/path");
+        assertFalse(root.hasPendingChanges());
+
+        verify(mgrDlg, times(1)).createUser("u", "u", new PrincipalImpl("u"), 
"rel/path");
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testCreateSystemUser() throws Exception {
+        autosaveMgr.createSystemUser("u", null);
+        assertFalse(root.hasPendingChanges());
+
+        verify(mgrDlg, times(1)).createSystemUser("u", null);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
     public void testCreateRemoveGroup() throws RepositoryException {
-        Group g = mgr.createGroup("g");
+        Group g = autosaveMgr.createGroup("g");
         assertFalse(root.hasPendingChanges());
         g.remove();
         assertFalse(root.hasPendingChanges());
+
+        verify(mgrDlg, times(1)).createGroup("g");
+        verify(autosaveMgr, times(2)).autosave();
+    }
+
+    @Test
+    public void testCreateGroupFromPrincipal() throws RepositoryException {
+        Principal principal = new PrincipalImpl("g");
+        autosaveMgr.createGroup(principal);
+        assertFalse(root.hasPendingChanges());
+
+        verify(mgrDlg, times(1)).createGroup(principal);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testCreateGroupFromPrincipalAndID() throws RepositoryException 
{
+        Principal principal = new PrincipalImpl("g");
+        autosaveMgr.createGroup(principal, "g");
+        assertFalse(root.hasPendingChanges());
+
+        verify(mgrDlg, times(1)).createGroup(principal, "g");
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testCreateGroupFromIdPrincipalAndPath() throws 
RepositoryException {
+        Principal principal = new PrincipalImpl("g");
+        autosaveMgr.createGroup("g", principal, "rel/path");
+        assertFalse(root.hasPendingChanges());
+
+        verify(mgrDlg, times(1)).createGroup("g", principal, "rel/path");
+        verify(autosaveMgr, times(1)).autosave();
     }
 
     @Test
     public void testCommitFailedRevertChanges() throws RepositoryException {
-        User u = mgr.createUser("u", "u");
+        autosaveMgr.createUser("u", "u");
         try {
-            User u2 = mgr.createUser("u", "u");
+            autosaveMgr.createUser("u", "u");
             fail();
         } catch (RepositoryException e) {
             // success
             assertFalse(root.hasPendingChanges());
         }
+        verify(autosaveMgr, times(2)).autosave();
     }
 
     @Test
     public void testAuthorizable() throws Exception {
-        User u = mgr.createUser("u", "u");
+        User u = autosaveMgr.createUser("u", "u");
         u.setProperty("prop", getValueFactory().createValue("value"));
         assertFalse(root.hasPendingChanges());
 
@@ -151,11 +234,13 @@ public class AutoSaveEnabledManagerTest
 
         u.removeProperty("prop");
         assertFalse(root.hasPendingChanges());
+
+        verify(autosaveMgr, times(4)).autosave();
     }
 
     @Test
     public void testUser() throws Exception {
-        User u = mgr.createUser("u", "u");
+        User u = autosaveMgr.createUser("u", "u");
 
         u.disable("disabled");
         assertTrue(u.isDisabled());
@@ -174,10 +259,10 @@ public class AutoSaveEnabledManagerTest
 
     @Test
     public void testImpersonation() throws Exception {
-        User u = mgr.createUser("u", "u");
+        User u = autosaveMgr.createUser("u", "u");
 
         Impersonation imp = u.getImpersonation();
-        Principal p = mgr.getAuthorizable("anonymous").getPrincipal();
+        Principal p = autosaveMgr.getAuthorizable("anonymous").getPrincipal();
         assertTrue(imp.grantImpersonation(p));
         assertFalse(root.hasPendingChanges());
 
@@ -187,8 +272,8 @@ public class AutoSaveEnabledManagerTest
 
     @Test
     public void testGroup() throws Exception {
-        User u = mgr.createUser("u", "u");
-        Group g = mgr.createGroup("g");
+        User u = autosaveMgr.createUser("u", "u");
+        Group g = autosaveMgr.createGroup("g");
 
         assertTrue(g.addMember(u));
         assertFalse(root.hasPendingChanges());
@@ -217,8 +302,8 @@ public class AutoSaveEnabledManagerTest
 
     @Test
     public void testDeclaredMemberOf() throws Exception {
-        User u = mgr.createUser("u", "u");
-        Group g = mgr.createGroup("g");
+        User u = autosaveMgr.createUser("u", "u");
+        Group g = autosaveMgr.createGroup("g");
 
         assertTrue(g.addMember(u));
 
@@ -234,8 +319,8 @@ public class AutoSaveEnabledManagerTest
 
     @Test
     public void testMemberOf() throws Exception {
-        User u = mgr.createUser("u", "u");
-        Group g = mgr.createGroup("g");
+        User u = autosaveMgr.createUser("u", "u");
+        Group g = autosaveMgr.createGroup("g");
 
         assertTrue(g.addMember(u));
 
@@ -251,8 +336,8 @@ public class AutoSaveEnabledManagerTest
 
     @Test
     public void testAddMembers() throws Exception {
-        User u = mgr.createUser("u", "u");
-        Group g = mgr.createGroup("g");
+        User u = autosaveMgr.createUser("u", "u");
+        Group g = autosaveMgr.createGroup("g");
 
         assertTrue(g.addMembers(u.getID()).isEmpty());
         assertFalse(root.hasPendingChanges());
@@ -260,8 +345,8 @@ public class AutoSaveEnabledManagerTest
 
     @Test
     public void testRemoveMembers() throws Exception {
-        User u = mgr.createUser("u", "u");
-        Group g = mgr.createGroup("g");
+        User u = autosaveMgr.createUser("u", "u");
+        Group g = autosaveMgr.createGroup("g");
         g.addMember(u);
 
         assertTrue(g.removeMembers(u.getID()).isEmpty());

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/GroupImplTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/GroupImplTest.java?rev=1856959&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/GroupImplTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/GroupImplTest.java
 Thu Apr  4 16:39:33 2019
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.user.autosave;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class GroupImplTest extends AbstractAutoSaveTest {
+
+    private Group dlg;
+    private User memberDlg;
+    private GroupImpl group;
+
+    @Before
+    @Override
+    public void before() throws Exception {
+        super.before();
+        Group g = mgrDlg.createGroup("g");
+        memberDlg = mgrDlg.createUser("u", null);
+        g.addMember(memberDlg);
+        root.commit();
+
+        dlg = spy(g);
+        assertFalse(dlg instanceof GroupImpl);
+
+        group = new GroupImpl(dlg, autosaveMgr);
+    }
+
+    @After
+    @Override
+    public void after() throws Exception {
+        try {
+            dlg.remove();
+            memberDlg.remove();
+            root.commit();
+        } finally {
+            super.after();
+        }
+    }
+
+    @Test
+    public void testGetDeclaredMembers() throws Exception {
+        assertTrue(group.getDeclaredMembers().hasNext());
+        verify(dlg, times(1)).getDeclaredMembers();
+    }
+
+    @Test
+    public void testGetMembers() throws Exception {
+        assertTrue(group.getMembers().hasNext());
+        verify(dlg, times(1)).getMembers();
+    }
+
+    @Test
+    public void testIsDeclaredMember() throws Exception {
+        User u = new UserImpl(memberDlg, autosaveMgr);
+        assertFalse(group.isDeclaredMember(memberDlg));
+        assertTrue(group.isDeclaredMember(u));
+
+        verify(dlg, times(1)).isDeclaredMember(memberDlg);
+        verify(dlg, never()).isDeclaredMember(u);
+    }
+
+    @Test
+    public void testIsMember() throws Exception {
+        User u = new UserImpl(memberDlg, autosaveMgr);
+        assertFalse(group.isMember(memberDlg));
+        assertTrue(group.isMember(u));
+
+        verify(dlg, times(1)).isMember(memberDlg);
+        verify(dlg, never()).isMember(u);
+    }
+
+    @Test
+    public void testAddInvalidMember() throws Exception {
+        assertFalse(group.addMember(getTestUser()));
+        verify(dlg, never()).addMember(getTestUser());
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testAddMember() throws Exception {
+        User u = new UserImpl(getTestUser(), autosaveMgr);
+        assertTrue(group.addMember(u));
+        verify(dlg, times(1)).addMember(getTestUser());
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testAddMembersById() throws Exception {
+        assertEquals(ImmutableSet.of("m1", "m2", "m3"), group.addMembers("m1", 
"m2", "m3"));
+        verify(dlg, times(1)).addMembers("m1", "m2", "m3");
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testRemoveInvalidMember() throws Exception {
+        assertFalse(group.removeMember(memberDlg));
+        verify(dlg, never()).removeMember(memberDlg);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testRemoveMember() throws Exception {
+        User u = new UserImpl(memberDlg, autosaveMgr);
+        assertTrue(group.removeMember(u));
+        verify(dlg, times(1)).removeMember(memberDlg);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testRemoveMembersById() throws Exception {
+        assertEquals(ImmutableSet.of(getTestUser().getID()), 
group.removeMembers("u", getTestUser().getID()));
+        verify(dlg, times(1)).removeMembers("u", getTestUser().getID());
+        verify(autosaveMgr, times(1)).autosave();
+    }
+}
\ No newline at end of file

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/GroupImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/UserImplTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/UserImplTest.java?rev=1856959&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/UserImplTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/UserImplTest.java
 Thu Apr  4 16:39:33 2019
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.security.user.autosave;
+
+import org.apache.jackrabbit.api.security.user.Impersonation;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.jcr.RepositoryException;
+import java.security.Principal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class UserImplTest extends AbstractAutoSaveTest {
+
+    private User dlg;
+    private UserImpl user;
+    private Impersonation impersonationMock = mock(Impersonation.class);
+
+    @Before
+    @Override
+    public void before() throws Exception {
+        super.before();
+        dlg = spy(getTestUser());
+        assertFalse(dlg instanceof UserImpl);
+        when(dlg.getImpersonation()).thenReturn(impersonationMock);
+
+        user = new UserImpl(dlg, autosaveMgr);
+    }
+
+    @Test
+    public void testIsAdmin() throws Exception {
+        assertEquals(dlg.isAdmin(), user.isAdmin());
+        verify(dlg, times(2)).isAdmin();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testIsSystemUser() throws Exception {
+        assertEquals(dlg.isSystemUser(), user.isSystemUser());
+        verify(dlg, times(2)).isSystemUser();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetCredentials() throws RepositoryException {
+        assertEquals(dlg.getCredentials().getClass().getName(), 
user.getCredentials().getClass().getName());
+        verify(dlg, times(2)).getCredentials();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetImpersonation() throws RepositoryException {
+        user.getImpersonation();
+        verify(dlg, times(2)).getImpersonation();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testChancePassword() throws Exception {
+        user.changePassword("newPw");
+        verify(dlg, times(1)).changePassword("newPw");
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testChancePasswordOldPw() throws Exception {
+        String oldpw = user.getID();
+        user.changePassword("newPw", oldpw);
+        verify(dlg, times(1)).changePassword("newPw", oldpw);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testDisable() throws Exception {
+        user.disable("disable");
+        verify(dlg, times(1)).disable("disable");
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testIsDisabled() throws Exception {
+        assertEquals(dlg.isDisabled(), user.isDisabled());
+        verify(dlg, times(2)).isDisabled();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetDisabledReason() throws Exception {
+        assertEquals(dlg.getDisabledReason(), user.getDisabledReason());
+        verify(dlg, times(2)).getDisabledReason();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGetImpersonators() throws Exception {
+        user.getImpersonation().getImpersonators();
+        verify(impersonationMock, times(1)).getImpersonators();
+        verify(autosaveMgr, never()).autosave();
+    }
+
+    @Test
+    public void testGrantImpersonation() throws Exception {
+        Principal principal = new PrincipalImpl("any");
+        user.getImpersonation().grantImpersonation(principal);
+        verify(impersonationMock, times(1)).grantImpersonation(principal);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testRevokeImpersonation() throws Exception {
+        Principal principal = new PrincipalImpl("any");
+        user.getImpersonation().revokeImpersonation(principal);
+        verify(impersonationMock, times(1)).revokeImpersonation(principal);
+        verify(autosaveMgr, times(1)).autosave();
+    }
+
+    @Test
+    public void testImpersonation() throws Exception {
+        user.getImpersonation().allows(SystemSubject.INSTANCE);
+        verify(impersonationMock, times(1)).allows(SystemSubject.INSTANCE);
+        verify(autosaveMgr, never()).autosave();
+    }
+}
\ No newline at end of file

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/autosave/UserImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to