You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2011/08/25 13:48:09 UTC

svn commit: r1161521 - in /chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main: java/org/apache/chemistry/opencmis/tck/impl/ java/org/apache/chemistry/opencmis/tck/tests/control/ resources/

Author: fmui
Date: Thu Aug 25 11:48:09 2011
New Revision: 1161521

URL: http://svn.apache.org/viewvc?rev=1161521&view=rev
Log:
added more TCK tests (ACLs)
fixed TCK getObjectByPath() calls

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ACLSmokeTest.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ControlTestGroup.java   (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/resources/cmis-tck-groups.txt

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1161521&r1=1161520&r2=1161521&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java Thu Aug 25 11:48:09 2011
@@ -55,6 +55,8 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
@@ -351,14 +353,7 @@ public abstract class AbstractSessionTes
 
         try {
             // check the new document
-            String[] propertiesToCheck = new String[result.getType().getPropertyDefinitions().size()];
-
-            int i = 0;
-            for (String propId : result.getType().getPropertyDefinitions().keySet()) {
-                propertiesToCheck[i++] = propId;
-            }
-
-            addResult(checkObject(session, result, propertiesToCheck, "New document object spec compliance"));
+            addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
 
             // check content
             try {
@@ -434,7 +429,7 @@ public abstract class AbstractSessionTes
 
         Folder parent = null;
         try {
-            CmisObject parentObject = session.getObjectByPath(testFolderParentPath);
+            CmisObject parentObject = session.getObjectByPath(testFolderParentPath, SELECT_ALL_NO_CACHE_OC);
             if (!(parentObject instanceof Folder)) {
                 addResult(createResult(FAILURE, "Parent folder of the test folder is actually not a folder! Path: "
                         + testFolderParentPath, true));
@@ -771,6 +766,11 @@ public abstract class AbstractSessionTes
                 }
             }
 
+            // check ACL
+            if (object.getAcl() != null && object.getAcl().getAces() != null) {
+                addResult(results, checkACL(session, object.getAcl(), "ACL"));
+            }
+
             // check relationships
             checkRelationships(session, results, object);
 
@@ -784,6 +784,43 @@ public abstract class AbstractSessionTes
         return (result.getStatus().getLevel() <= OK.getLevel() ? null : result);
     }
 
+    protected CmisTestResult checkACL(Session session, Acl acl, String message) {
+        List<CmisTestResult> results = new ArrayList<CmisTestResult>();
+
+        CmisTestResult f;
+
+        f = createResult(FAILURE, "ACL is null!");
+        addResult(results, assertNotNull(acl, null, f));
+
+        if (acl != null) {
+
+            f = createResult(FAILURE, "List of ACEs is null!");
+            addResult(results, assertNotNull(acl.getAces(), null, f));
+
+            if (acl.getAces() != null) {
+                for (Ace ace : acl.getAces()) {
+                    f = createResult(FAILURE, "ACE with empty principal id!");
+                    addResult(results, assertStringNotEmpty(ace.getPrincipalId(), null, f));
+
+                    f = createResult(FAILURE, "ACE with empty permission list!");
+                    addResult(results, assertListNotEmpty(ace.getPermissions(), null, f));
+
+                    if (ace.getPermissions() != null) {
+                        for (String permission : ace.getPermissions()) {
+                            f = createResult(FAILURE, "ACE with empty permission entry!");
+                            addResult(results, assertStringNotEmpty(permission, null, f));
+                        }
+                    }
+                }
+            }
+        }
+
+        CmisTestResultImpl result = createResult(getWorst(results), message);
+        result.getChildren().addAll(results);
+
+        return (result.getStatus().getLevel() <= OK.getLevel() ? null : result);
+    }
+
     private void checkRelationships(Session session, List<CmisTestResult> results, CmisObject object) {
         if (object instanceof Relationship) {
             if (object.getRelationships() != null && !object.getRelationships().isEmpty()) {
@@ -1408,7 +1445,7 @@ public abstract class AbstractSessionTes
                     addResult(results, createResult(FAILURE, "Child has no path! " + child.getId()));
                 } else {
                     for (String path : paths) {
-                        CmisObject objectByPath = session.getObjectByPath(path);
+                        CmisObject objectByPath = session.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC);
 
                         f = createResult(FAILURE, "Child and object fetched by path don't match! Id: " + child.getId());
                         addResult(results, assertEquals(child, objectByPath, null, f));

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ACLSmokeTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ACLSmokeTest.java?rev=1161521&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ACLSmokeTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ACLSmokeTest.java Thu Aug 25 11:48:09 2011
@@ -0,0 +1,126 @@
+/*
+ * 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.tck.tests.control;
+
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
+import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;
+import org.apache.chemistry.opencmis.tck.CmisTestResult;
+import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
+
+/**
+ * Query smoke test.
+ */
+public class ACLSmokeTest extends AbstractSessionTest {
+
+    @Override
+    public void init(Map<String, String> parameters) {
+        super.init(parameters);
+        setName("ACL Test");
+        setDescription("Creates an object and check if the cmis:read ACE is applied!");
+    }
+
+    @Override
+    public void run(Session session) {
+        CmisTestResult f;
+
+        if (supportsACLs(session)) {
+            try {
+                // create folder and document
+                Folder testFolder = createTestFolder(session);
+                Document doc = createDocument(session, testFolder, "acltest.txt", "ACL test");
+
+                // check if there is an ACL
+                Acl acl = doc.getAcl();
+
+                f = createResult(FAILURE, "ACLs are supported but newly created document has no ACL!");
+                addResult(assertNotNull(acl, null, f));
+
+                // check basic permissions
+                Acl basicAcl = session.getAcl(doc, true);
+
+                f = createResult(FAILURE,
+                        "ACLs are supported but repository does not return a basic ACL for the newly created document!");
+                addResult(assertNotNull(basicAcl, null, f));
+
+                if (basicAcl != null) {
+                    addResult(checkACL(session, basicAcl, "Basic ACL"));
+
+                    if (basicAcl.getAces() != null) {
+                        for (Ace ace : basicAcl.getAces()) {
+                            if (ace.getPermissions() != null) {
+                                for (String permission : ace.getPermissions()) {
+                                    if (!"cmis:read".equals(permission) && !"cmis:write".equals(permission)
+                                            && !"cmis:all".equals(permission)) {
+                                        addResult(createResult(FAILURE, "ACE contains a non-basic permission: "
+                                                + permission));
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+                // apply permission "cmis:read"
+                if (getAclCapability(session) == CapabilityAcl.MANAGE) {
+                    // see CMIS spec section "2.2.1.5 ACLs"
+                    String principal = "cmis:user";
+
+                    List<Ace> aces = new ArrayList<Ace>();
+                    aces.add(session.getObjectFactory().createAce(principal, Collections.singletonList("cmis:read")));
+
+                    session.applyAcl(doc, aces, null, null);
+                }
+
+                deleteObject(doc);
+            } finally {
+                deleteTestFolder();
+            }
+        } else {
+            addResult(createResult(SKIPPED, "ACLs are not supported. Test Skipped!"));
+        }
+    }
+
+    protected boolean supportsACLs(Session session) {
+        CapabilityAcl aclCap = getAclCapability(session);
+        return (aclCap != null) && (aclCap != CapabilityAcl.NONE);
+    }
+
+    protected CapabilityAcl getAclCapability(Session session) {
+        RepositoryInfo repository = session.getRepositoryInfo();
+
+        if (repository.getCapabilities().getAclCapability() == null) {
+            return null;
+        }
+
+        return repository.getCapabilities().getAclCapability();
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ACLSmokeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ControlTestGroup.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ControlTestGroup.java?rev=1161521&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ControlTestGroup.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ControlTestGroup.java Thu Aug 25 11:48:09 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.tck.tests.control;
+
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTestGroup;
+
+/**
+ * This test group contains ACL and policy tests.
+ */
+public class ControlTestGroup extends AbstractSessionTestGroup {
+    @Override
+    public void init(Map<String, String> parameters) throws Exception {
+        super.init(parameters);
+
+        setName("Control Test Group");
+        setDescription("ACL and Policy tests.");
+
+        addTest(new ACLSmokeTest());
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/control/ControlTestGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/resources/cmis-tck-groups.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/resources/cmis-tck-groups.txt?rev=1161521&r1=1161520&r2=1161521&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/resources/cmis-tck-groups.txt (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/resources/cmis-tck-groups.txt Thu Aug 25 11:48:09 2011
@@ -24,4 +24,5 @@
 org.apache.chemistry.opencmis.tck.tests.basics.BasicsTestGroup
 org.apache.chemistry.opencmis.tck.tests.crud.CRUDTestGroup
 org.apache.chemistry.opencmis.tck.tests.versioning.VersioningTestGroup
+org.apache.chemistry.opencmis.tck.tests.control.ControlTestGroup
 org.apache.chemistry.opencmis.tck.tests.query.QueryTestGroup
\ No newline at end of file