chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1178250 [3/3] - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/ main/java/org/apache/chemistry/opencmis/inmemory/query/ main/java/org/apache/c...
Date Sun, 02 Oct 2011 20:35:13 GMT
Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclServiceTest.java?rev=1178250&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclServiceTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclServiceTest.java
Sun Oct  2 20:35:12 2011
@@ -0,0 +1,358 @@
+/*
+ * 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.chemistry.opencmis.inmemory;
+
+import static org.junit.Assert.assertEquals;
+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 java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumBasicPermissions;
+import org.apache.chemistry.opencmis.inmemory.ObjectServiceTest.ObjectTestTypeSystemCreator;
+import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition;
+import org.apache.chemistry.opencmis.inmemory.types.InMemoryFolderTypeDefinition;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AclServiceTest extends AbstractServiceTest {
+
+    private static final Log LOG = LogFactory.getLog(AclServiceTest.class);
+    ObjectCreator fCreator;
+    private static final String DOCUMENT_NAME = "DocumentWithAcl";
+    private static final String FOLDER_NAME = "FolderWithAcl";
+    private static final String DOCUMENT_TYPE_ID = InMemoryDocumentTypeDefinition.getRootDocumentType().getId();
+    private static final String FOLDER_TYPE_ID = InMemoryFolderTypeDefinition.getRootFolderType().getId();
+    private static final String USER = "user";
+    private static final String ALICE = "alice";
+    private static final String BOB = "bob";
+    private static final String CHRIS = "chris";
+    private static final String DAN = "dan";
+        
+    
+    @Override
+    @Before
+    public void setUp() {
+        super.setTypeCreatorClass(ObjectTestTypeSystemCreator.class.getName());
+        super.setUp();
+        fCreator = new ObjectCreator(fFactory, fObjSvc, fRepositoryId);
+    }
+
+    @Override
+    @After
+    public void tearDown() {
+        super.tearDown();
+    }
+
+    @Test
+    public void testCreateDocumentWithAcl() {
+        LOG.info("starting testCreateDocumentWithAcl() ...");
+        Acl removeAces = null;
+        Acl acl = createSimpleTestAcl();
+
+        String id = createDocument(fRootFolderId, acl, removeAces);
+        LOG.debug("created document with id: " + id);
+        
+        // get ACL using AclService
+        Acl aclReturn = fAclSvc.getAcl(fRepositoryId, id, true, null);        
+        checkSimpleTestAcl(acl, aclReturn);
+        
+        // get ACL using ObjectService getObject
+        ObjectData objData = fObjSvc.getObject(fRepositoryId, id, "*", false, IncludeRelationships.NONE,
null, false, true, null);
+        checkSimpleTestAcl(acl, aclReturn);
+       
+        // get ACL using ObjectService getObjectByPath
+        objData = fObjSvc.getObjectByPath(fRepositoryId, "/" + DOCUMENT_NAME, "*", false,
IncludeRelationships.NONE, null, false,
+                true, null);
+        assertNotNull(objData);
+        aclReturn = objData.getAcl();
+        checkSimpleTestAcl(acl, aclReturn);
+
+        LOG.info("... testCreateDocumentWithAcl() finished.");
+    }
+
+    @Test
+    public void testCreateFolderWithAcl() {
+        LOG.info("starting testCreateFolderWithAcl() ...");
+        Acl removeAces = null;
+        Acl acl = createSimpleTestAcl();
+        
+        String id = createFolder(fRootFolderId, acl, removeAces);
+        LOG.debug("created folder with id: " + id);
+        
+        // get ACL using AclService
+        Acl aclReturn = fAclSvc.getAcl(fRepositoryId, id, true, null);        
+        checkSimpleTestAcl(acl, aclReturn);
+
+        // get ACL using ObjectService getObject
+        ObjectData objData = fObjSvc.getObject(fRepositoryId, id, "*", false, IncludeRelationships.NONE,
null, false, true, null);
+        checkSimpleTestAcl(acl, aclReturn);
+       
+        // get ACL using ObjectService getObjectByPath
+        objData = fObjSvc.getObjectByPath(fRepositoryId, "/" + FOLDER_NAME, "*", false, IncludeRelationships.NONE,
null, false,
+                true, null);
+        assertNotNull(objData);
+        aclReturn = objData.getAcl();
+        checkSimpleTestAcl(acl, aclReturn);        
+        LOG.info("... testCreateFolderWithAcl() finished.");
+   }
+        
+    @Test
+    public void testApplyAcl() {
+        LOG.info("starting testApplyAcl() ...");
+        Acl acl = createSimpleTestAcl();
+        
+        String id = createDocument(fRootFolderId, null, null);
+        LOG.debug("created document with id: " + id);
+        
+        // apply absolute ACL using AclService
+        Acl acl1 = fAclSvc.applyAcl(fRepositoryId, id, acl, null, AclPropagation.OBJECTONLY,
null);        
+        checkSimpleTestAcl(acl, acl1);
+
+        // get ACL using AclService
+        Acl aclReturn = fAclSvc.getAcl(fRepositoryId, id, true, null);        
+        checkSimpleTestAcl(acl, aclReturn);
+
+        LOG.info("... testApplyAcl() finished.");
+    }
+    
+    @Test
+    public void testAddRemoveAcl() {
+        
+        LOG.info("starting testAddRemoveAcl() ...");
+        Acl acl = createAdvancedTestAcl();        
+        
+        String id = createDocument(fRootFolderId, acl, null);
+        LOG.debug("created document with id: " + id);
+        
+        Acl aclAdd = createAclAdd();        
+        Acl aclRemove = createAclRemove();
+        // apply absolute ACL using AclService
+        Acl aclReturn = fAclSvc.applyAcl(fRepositoryId, id, aclAdd, aclRemove, AclPropagation.OBJECTONLY,
null);        
+
+        checkAclAfterAddRemove(aclReturn);
+                
+        LOG.info("... testAddRemoveAcl() finished.");
+    }
+    
+    @Test
+    public void testAddRemoveDuplicatedAcl() {
+        final String DOCUMENT_NAME_1 = "DocumentWithAcl-1";
+        final String DOCUMENT_NAME_2 = "DocumentWithAcl-2";
+
+        LOG.info("starting testAddRemoveDuplicatedAcl() ...");
+        Acl acl = createAdvancedTestAcl();  
+        String id1 = createDocument(DOCUMENT_NAME_1, fRootFolderId, acl, null);
+        String id2 = createDocument(DOCUMENT_NAME_2, fRootFolderId, acl, null);
+        
+//        // modify ACL of first doc
+//        List<Ace> acesRemove = Arrays.asList(new Ace[] { 
+//                createAce(BOB, EnumBasicPermissions.CMIS_WRITE.value()),
+//                });
+//        Acl aclRemove = new AccessControlListImpl(acesRemove);        
+//        List<Ace> acesAdd = Arrays.asList(new Ace[] { 
+//                createAce(DAN, EnumBasicPermissions.CMIS_WRITE.value()),
+//                });
+//        Acl aclAdd = new AccessControlListImpl(acesAdd);        
+        Acl aclAdd = createAclAdd();        
+        Acl aclRemove = createAclRemove();
+        Acl aclReturn = fAclSvc.applyAcl(fRepositoryId, id1, aclAdd, aclRemove, AclPropagation.OBJECTONLY,
null);        
+
+        checkAclAfterAddRemove(aclReturn);
+  
+        // Ensure that ACL of second doc is unchanged
+        aclReturn = fAclSvc.getAcl(fRepositoryId, id2, true, null);        
+        checkAdvancedTestAcl(acl, aclReturn);
+        LOG.info("... testAddRemoveDuplicatedAcl() finished.");
+    }
+ 
+    @Test
+    public void testApplyAclRecursiveSimple () {
+        LOG.info("starting testApplyAclRecursiveSimple() ...");
+        Acl acl = createSimpleTestAcl();
+        String[] ids = createHierarchy(acl, null);
+        fAclSvc.applyAcl(fRepositoryId, ids[0], acl, null, AclPropagation.PROPAGATE, null);
       
+        checkAclRecursiveSimple(ids, acl);                
+        LOG.info("... testApplyAclRecursiveSimple() finished.");
+    }    
+
+    @Test
+    public void testApplyAclRecursiveIncremental() {
+        LOG.info("starting testApplyAclRecursiveIncremental() ...");
+        Acl acl = createAdvancedTestAcl();        
+        String[] ids = createHierarchy(acl, null);
+               
+        Acl aclRemove = createAclRemove();        
+        Acl aclAdd = createAclAdd();        
+
+        Acl aclReturn = fAclSvc.applyAcl(fRepositoryId, ids[0], aclAdd, aclRemove, AclPropagation.PROPAGATE,
null);        
+        checkAclAfterAddRemove(aclReturn);
+        for (String id : ids) {
+            aclReturn = fAclSvc.getAcl(fRepositoryId, id, true, null);        
+            checkAclAfterAddRemove(aclReturn);
+        }
+        LOG.info("... testApplyAclRecursiveIncremental() finished.");
+    }    
+
+    @Test
+    public void testRemoveAllAcls() {
+        LOG.info("starting testRemoveAllAcls() ...");
+
+        Acl acl = createAdvancedTestAcl();                
+        String id = createDocument(fRootFolderId, acl, null);
+        LOG.debug("created document with id: " + id);
+        
+        Acl aclReturn = fAclSvc.applyAcl(fRepositoryId, id, null, acl, AclPropagation.OBJECTONLY,
null);        
+        assertNull(aclReturn);
+                
+        LOG.info("... testRemoveAllAcls() finished.");
+    }    
+
+    private String createDocument(String name, String folderId, Acl addAces, Acl removeAces)
{
+        return createDocumentNoCatch(name, folderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false, addAces,
+                removeAces);        
+    }
+    
+    private String createDocument(String folderId, Acl addAces, Acl removeAces) {
+        return createDocumentNoCatch(DOCUMENT_NAME, folderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false, addAces,
+                removeAces);        
+    }
+
+    private String createFolder(String folderId, Acl addAces, Acl removeAces) {
+        return createFolderNoCatch(FOLDER_NAME, folderId, FOLDER_TYPE_ID, addAces, removeAces);
       
+    }
+    
+    private String[] createHierarchy(Acl addAces, Acl removeAces) {
+        String result[] = new String [6];
+        String rootFolderId = createFolderNoCatch(FOLDER_NAME, fRootFolderId, FOLDER_TYPE_ID,
addAces, removeAces);
+        result[0] = rootFolderId;
+        result[1] = createDocument(DOCUMENT_NAME + "-1", rootFolderId, addAces, removeAces);
+        result[2] = createDocument(DOCUMENT_NAME + "-2", rootFolderId, addAces, removeAces);
+        String subFolderId = createFolderNoCatch(FOLDER_NAME, rootFolderId, FOLDER_TYPE_ID,
addAces, removeAces);
+        result[3] = subFolderId;
+        result[4] = createDocument(DOCUMENT_NAME + "-1", subFolderId, addAces, removeAces);
+        result[5] = createDocument(DOCUMENT_NAME + "-2", subFolderId, addAces, removeAces);
+        return result;
+    }
+    
+    private void checkAclRecursiveSimple(String[] ids, Acl acl) {
+        // get ACL using ObjectService getObject
+        for (String id : ids) {
+            ObjectData objData = fObjSvc.getObject(fRepositoryId, id, "*", false, IncludeRelationships.NONE,
null, false, true, null);
+            checkSimpleTestAcl(acl, objData.getAcl());
+        }
+    }
+
+    private Acl createSimpleTestAcl() {
+        List<Ace> aces = Arrays.asList(new Ace[] { createAce(USER, EnumBasicPermissions.CMIS_READ.value())
});
+        return fFactory.createAccessControlList(aces);        
+    }
+    
+    private void checkSimpleTestAcl(Acl acl, Acl aclReturn) {
+        assertNotNull(aclReturn);
+        assertEquals(acl.getAces().size(), aclReturn.getAces().size());
+        assertTrue(aclHasPermission(aclReturn, USER, EnumBasicPermissions.CMIS_READ.value()));
       
+    }
+    
+    private Acl createAdvancedTestAcl() {
+        List<Ace> aces = Arrays.asList(new Ace[] { 
+                createAce(ALICE, EnumBasicPermissions.CMIS_READ.value()),
+                createAce(BOB, EnumBasicPermissions.CMIS_WRITE.value()),
+                createAce(CHRIS, EnumBasicPermissions.CMIS_ALL.value()),
+                });
+        return fFactory.createAccessControlList(aces);        
+    }
+    
+    private Acl createAclAdd() {
+        List<Ace> acesAdd = Arrays.asList(new Ace[] { 
+                createAce(DAN, EnumBasicPermissions.CMIS_WRITE.value()),
+                });
+       return fFactory.createAccessControlList(acesAdd);                
+    }
+    
+    private Acl createAclRemove() {
+        List<Ace> acesRemove = Arrays.asList(new Ace[] { 
+                createAce(BOB, EnumBasicPermissions.CMIS_WRITE.value()),
+                createAce(CHRIS, EnumBasicPermissions.CMIS_ALL.value())
+                });
+        return fFactory.createAccessControlList(acesRemove);               
+    }
+    
+    private void checkAclAfterAddRemove(Acl aclReturn) {
+        assertNotNull(aclReturn);
+        assertEquals(2, aclReturn.getAces().size());
+        assertTrue(aclHasPermission(aclReturn, ALICE, EnumBasicPermissions.CMIS_READ.value()));
       
+        assertTrue(aclHasPermission(aclReturn, DAN, EnumBasicPermissions.CMIS_WRITE.value()));
       
+        assertFalse(aclHasPermission(aclReturn, BOB, EnumBasicPermissions.CMIS_WRITE.value()));
       
+        assertFalse(aclHasPermission(aclReturn, CHRIS, EnumBasicPermissions.CMIS_ALL.value()));
       
+        assertTrue(aclHasNoPermission(aclReturn, BOB));        
+        assertTrue(aclHasNoPermission(aclReturn, CHRIS));        
+    }
+    
+   private void checkAdvancedTestAcl(Acl acl, Acl aclReturn) {
+        assertNotNull(aclReturn);
+        assertEquals(acl.getAces().size(), aclReturn.getAces().size());
+        assertTrue(aclHasPermission(aclReturn, ALICE, EnumBasicPermissions.CMIS_READ.value()));
       
+        assertTrue(aclHasPermission(aclReturn, BOB, EnumBasicPermissions.CMIS_WRITE.value()));
       
+        assertTrue(aclHasPermission(aclReturn, CHRIS, EnumBasicPermissions.CMIS_ALL.value()));
       
+    }
+
+    private Ace createAce(String principalId, String permission) {
+        return  fFactory.createAccessControlEntry(principalId, Collections.singletonList(
permission ));
+    }
+    
+    private boolean aclHasPermission(Acl acl, String principalId, String permission) {
+        for (Ace ace : acl.getAces()) {
+            if (ace.getPrincipalId().equals(principalId) && aceContainsPermission(ace,
permission))
+                return true;            
+        }
+        return false;
+    }
+    
+    private boolean aclHasNoPermission(Acl acl, String principalId) {
+        if (null == acl)
+            return false;
+        
+        for (Ace ace : acl.getAces()) {
+            if (ace.getPrincipalId().equals(principalId))
+                return false;
+        }
+        return true;
+    }
+    
+    private boolean aceContainsPermission(Ace ace, String permission) {
+        for (String acePerm : ace.getPermissions())
+            if (permission.equals(acePerm))
+                return true;
+        return false;
+    }
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclTest.java?rev=1178250&r1=1178249&r2=1178250&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AclTest.java
Sun Oct  2 20:35:12 2011
@@ -28,9 +28,11 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumBasicPermissions;
 import org.apache.chemistry.opencmis.inmemory.storedobj.impl.InMemoryAce;
 import org.apache.chemistry.opencmis.inmemory.storedobj.impl.InMemoryAcl;
 import org.apache.chemistry.opencmis.inmemory.storedobj.impl.Permission;
@@ -149,6 +151,23 @@ public class AclTest {
     }
 
     @Test
+    public void testMerge() {
+        final InMemoryAce aceNew = new InMemoryAce("Hugo", Permission.WRITE); // will be
added
+        final InMemoryAce aceRCopy = new InMemoryAce(BERTA, Permission.READ); // is same
+        final InMemoryAce aceChange = new InMemoryAce(CHRISTIAN, Permission.ALL); // changes
permission
+
+        InMemoryAcl acl1 = createDefaultAcl();
+        InMemoryAcl acl2 = new InMemoryAcl(new ArrayList<InMemoryAce>() {{ add(aceNew);
add(aceRCopy);  add(aceChange); }});
+        acl1.mergeAcl(acl2);
+        assertEquals(5, acl1.getAces().size());
+        assertEquals(Permission.NONE, acl1.getPermission(ANDREAS));
+        assertEquals(Permission.READ, acl1.getPermission(BERTA));
+        assertEquals(Permission.ALL, acl1.getPermission(CHRISTIAN));
+        assertEquals(Permission.ALL, acl1.getPermission(DOROTHEE));
+        assertEquals(Permission.WRITE, acl1.getPermission("Hugo"));
+    }
+    
+    @Test
     public void testAclEquality() {
         final InMemoryAce aceNew = new InMemoryAce("Hugo", Permission.WRITE);
         final InMemoryAce aceRCopy = new InMemoryAce(BERTA, Permission.READ);
@@ -188,7 +207,7 @@ public class AclTest {
 
     @Test
     public void testConvertFomCmisAcl() {
-        List<Ace> aces = Arrays.asList(new Ace[] { createAce(ANDREAS, "cmis:read"),
createAce(DOROTHEE, "cmis:write") });
+        List<Ace> aces = Arrays.asList(new Ace[] { createAce(ANDREAS, EnumBasicPermissions.CMIS_READ.value()),
createAce(DOROTHEE, EnumBasicPermissions.CMIS_WRITE.value()) });
         AccessControlListImpl cAcl = new AccessControlListImpl(aces);
         InMemoryAcl acl = InMemoryAcl.createFromCommonsAcl(cAcl);        
         assertEquals(2, acl.size());
@@ -196,7 +215,7 @@ public class AclTest {
         assertEquals(Permission.WRITE, acl.getPermission(DOROTHEE));
         
         try {
-            List<Ace> aces2 = Arrays.asList(new Ace[] { new AccessControlEntryImpl(null,
 Arrays.asList(new String[] { "cmis:read"}))});
+            List<Ace> aces2 = Arrays.asList(new Ace[] { new AccessControlEntryImpl(null,
 Arrays.asList(new String[] { EnumBasicPermissions.CMIS_READ.value()}))});
             acl = InMemoryAcl.createFromCommonsAcl(new AccessControlListImpl(aces2));
             fail("create Ace will null principal should raise exception.");
         } catch (RuntimeException e) { }
@@ -207,6 +226,49 @@ public class AclTest {
         } catch (RuntimeException e) { }
     }
     
+    
+    @Test
+    public void testConvertToCmisAcl() {
+        Ace ace = aceN.toCommonsAce();
+        assertEquals(ANDREAS, ace.getPrincipalId());
+        assertEquals(1, ace.getPermissions().size());
+        assertEquals("", ace.getPermissions().get(0));
+
+        ace = aceR.toCommonsAce();
+        assertEquals(BERTA, ace.getPrincipalId());
+        assertEquals(1, ace.getPermissions().size());
+        assertEquals(EnumBasicPermissions.CMIS_READ.value(), ace.getPermissions().get(0));
+
+        ace = aceW.toCommonsAce();
+        assertEquals(CHRISTIAN, ace.getPrincipalId());
+        assertEquals(1, ace.getPermissions().size());
+        assertEquals(EnumBasicPermissions.CMIS_WRITE.value(), ace.getPermissions().get(0));
+
+        ace = aceA.toCommonsAce();
+        assertEquals(DOROTHEE, ace.getPrincipalId());
+        assertEquals(1, ace.getPermissions().size());
+        assertEquals(EnumBasicPermissions.CMIS_ALL.value(), ace.getPermissions().get(0));
+        
+        InMemoryAcl acl = createDefaultAcl();
+        Acl commonsAcl = acl.toCommonsAcl();
+        assertEquals(4, commonsAcl.getAces().size());
+        assertTrue(hasCommonsAce(commonsAcl, ANDREAS, ""));
+        assertFalse(hasCommonsAce(commonsAcl, ANDREAS, EnumBasicPermissions.CMIS_READ.value()));
+        assertFalse(hasCommonsAce(commonsAcl, ANDREAS, EnumBasicPermissions.CMIS_WRITE.value()));
+        assertFalse(hasCommonsAce(commonsAcl, ANDREAS, EnumBasicPermissions.CMIS_ALL.value()));
+        assertTrue(hasCommonsAce(commonsAcl, BERTA, EnumBasicPermissions.CMIS_READ.value()));
+        assertTrue(hasCommonsAce(commonsAcl, CHRISTIAN, EnumBasicPermissions.CMIS_WRITE.value()));
+        assertTrue(hasCommonsAce(commonsAcl, DOROTHEE, EnumBasicPermissions.CMIS_ALL.value()));
+    }
+    
+    @Test
+    public void testCloneAcl() {
+        InMemoryAcl acl = createDefaultAcl();
+        InMemoryAcl acl2 = acl.clone();
+        assertFalse(acl == acl2);
+        assertEquals(acl, acl2);
+    }
+    
     private InMemoryAcl createDefaultAcl() {
         return  new InMemoryAcl(new ArrayList<InMemoryAce>() {{ add(aceA); add(aceR);
 add(aceN);  add(aceW); }});
     }
@@ -229,4 +291,12 @@ public class AclTest {
         return ace;
     }
 
+    private boolean hasCommonsAce(Acl acl, String principalId, String permission) {
+        for (Ace ace : acl.getAces()) {
+            if (ace.getPrincipalId().equals(principalId) && ace.getPermissions().get(0).equals(permission))
+                return true;
+        }
+        return false;
+        
+    }
 }



Mime
View raw message