chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1537810 - in /chemistry/opencmis/trunk: chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/ chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemi...
Date Fri, 01 Nov 2013 02:55:17 GMT
Author: fmui
Date: Fri Nov  1 02:55:16 2013
New Revision: 1537810

URL: http://svn.apache.org/r1537810
Log:
FileShare: added base type check + TCK test

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateInvalidTypeTest.java
  (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CRUDTestGroup.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java?rev=1537810&r1=1537809&r2=1537810&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-fileshare/src/main/java/org/apache/chemistry/opencmis/fileshare/FileShareRepository.java
Fri Nov  1 02:55:16 2013
@@ -448,6 +448,9 @@ public class FileShareRepository {
         if (type == null) {
             throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
         }
+        if (type.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) {
+            throw new CmisInvalidArgumentException("Type must be a document type!");
+        }
 
         // compile the properties
         PropertiesImpl props = compileWriteProperties(typeId, context.getUsername(), context.getUsername(),
properties);
@@ -558,6 +561,9 @@ public class FileShareRepository {
             if (type == null) {
                 throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
             }
+            if (type.getBaseTypeId() != BaseTypeId.CMIS_DOCUMENT) {
+                throw new CmisInvalidArgumentException("Type must be a document type!");
+            }
 
             // replace with new values
             for (PropertyData<?> prop : properties.getProperties().values()) {
@@ -648,6 +654,9 @@ public class FileShareRepository {
         if (type == null) {
             throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
         }
+        if (type.getBaseTypeId() != BaseTypeId.CMIS_FOLDER) {
+            throw new CmisInvalidArgumentException("Type must be a folder type!");
+        }
 
         // compile the properties
         PropertiesImpl props = compileWriteProperties(typeId, context.getUsername(), context.getUsername(),
properties);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CRUDTestGroup.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/crud/CRUDTestGroup.java?rev=1537810&r1=1537809&r2=1537810&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CRUDTestGroup.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CRUDTestGroup.java
Fri Nov  1 02:55:16 2013
@@ -37,6 +37,7 @@ public class CRUDTestGroup extends Abstr
         addTest(new CreateAndDeleteDocumentTest());
         addTest(new CreateBigDocument());
         addTest(new CreateDocumentWithoutContent());
+        addTest(new CreateInvalidTypeTest());
         addTest(new NameCharsetTest());
         addTest(new CreateAndDeleteRelationshipTest());
         addTest(new CreateAndDeleteItemTest());

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateInvalidTypeTest.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/crud/CreateInvalidTypeTest.java?rev=1537810&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateInvalidTypeTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/CreateInvalidTypeTest.java
Fri Nov  1 02:55:16 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.crud;
+
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
+
+import java.io.ByteArrayInputStream;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.impl.IOUtils;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
+
+public class CreateInvalidTypeTest extends AbstractSessionTest {
+
+    @Override
+    public void init(Map<String, String> parameters) {
+        super.init(parameters);
+        setName("Create Object With Invalid Type Test");
+        setDescription("Tries to create document with a folder type and folder with a document
type.");
+    }
+
+    @Override
+    public void run(Session session) {
+        // create a test folder
+        Folder testFolder = createTestFolder(session);
+
+        try {
+            // test document creation
+            try {
+                Map<String, Object> properties = new HashMap<String, Object>();
+                properties.put(PropertyIds.NAME, "never.txt");
+                properties.put(PropertyIds.OBJECT_TYPE_ID, getFolderTestTypeId());
+
+                byte[] contentBytes = IOUtils.toUTF8Bytes("nothing");
+                ContentStream contentStream = new ContentStreamImpl("never.txt",
+                        BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
+
+                testFolder.createDocument(properties, contentStream, null);
+
+                addResult(createResult(FAILURE, "Creation of a document with a folder type
shouldn't work!"));
+            } catch (Exception e) {
+                if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof
CmisConstraintException)) {
+                    addResult(createResult(WARNING,
+                            "Creation of a document with a folder type threw an unexcpeted
exception: " + e.toString()));
+                }
+            }
+
+            // test folder creation
+            try {
+                Map<String, Object> properties = new HashMap<String, Object>();
+                properties.put(PropertyIds.NAME, "never");
+                properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
+
+                testFolder.createFolder(properties);
+
+                addResult(createResult(FAILURE, "Creation of a folder with a document type
shouldn't work!"));
+            } catch (Exception e) {
+                if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof
CmisConstraintException)) {
+                    addResult(createResult(WARNING,
+                            "Creation of a folder with a document type threw an unexcpeted
exception: " + e.toString()));
+                }
+            }
+        } finally {
+            // delete the test folder
+            deleteTestFolder();
+        }
+    }
+}

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



Mime
View raw message