chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r980159 - in /incubator/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/server/ main/java/org/apac...
Date Wed, 28 Jul 2010 19:01:30 GMT
Author: jens
Date: Wed Jul 28 19:01:30 2010
New Revision: 980159

URL: http://svn.apache.org/viewvc?rev=980159&view=rev
Log:
InMemory: Fix bug with insufficent name validation on create... calls in ObjectService, improve
exception handling, add tests

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java?rev=980159&r1=980158&r2=980159&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java
Wed Jul 28 19:01:30 2010
@@ -32,6 +32,9 @@ public class NameValidator {
      *            string to verify
      */
     static public boolean isValidId(String s) {
+        if (null == s || s.length() == 0)
+            return false;
+        
         if (s.startsWith("cmis:"))
             s = s.substring(5);
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=980159&r1=980158&r2=980159&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
Wed Jul 28 19:01:30 2010
@@ -825,20 +825,17 @@ public class InMemoryObjectServiceImpl e
         else
             throw new CmisInvalidArgumentException("Can't create folder, folderId does not
refer to a folder: "
                     + folderId);
-        try {
-            ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
-            Folder newFolder = objStore.createFolder(folderName);
-            // set default system attributes
-            if (user == null)
-                user = "unknown";
-            newFolder.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
-            newFolder.setCustomProperties(properties.getProperties());
-            parent.addChildFolder(newFolder);
-            LOG.debug("stop createFolder()");
-            return newFolder;
-        } catch (Exception e) {
-            throw new CmisInvalidArgumentException("Failed to create child folder.", e);
-        }
+
+        ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
+        Folder newFolder = objStore.createFolder(folderName);
+        // set default system attributes
+        if (user == null)
+            user = "unknown";
+        newFolder.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
+        newFolder.setCustomProperties(properties.getProperties());
+        parent.addChildFolder(newFolder);
+        LOG.debug("stop createFolder()");
+        return newFolder;
     }
 
     private StoredObject createPolicyIntern(String repositoryId, Properties properties, String
folderId,

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java?rev=980159&r1=980158&r2=980159&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
Wed Jul 28 19:01:30 2010
@@ -30,6 +30,7 @@ import java.util.Map;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
 import org.apache.chemistry.opencmis.inmemory.FilterParser;
 import org.apache.chemistry.opencmis.inmemory.NameValidator;
@@ -63,7 +64,7 @@ public class FolderImpl extends Abstract
             String name = folder.getName();
             hasChild = hasChild(name);
             if (hasChild)
-                throw new RuntimeException("Cannot create folder " + name + ". Name already
exists in parent folder");
+                throw new CmisNameConstraintViolationException("Cannot create folder " +
name + ". Name already exists in parent folder");
             folder.setParent(this);
             folder.persist();
         } finally {
@@ -96,14 +97,14 @@ public class FolderImpl extends Abstract
             boolean hasChild;
             hasChild = hasChild(name);
             if (hasChild)
-                throw new RuntimeException("Cannot create document " + name + ". Name already
exists in parent folder");
+                throw new CmisNameConstraintViolationException("Cannot create object: " +
name + ". Name already exists in parent folder");
 
             if (so instanceof SingleFiling)
                 ((SingleFiling) so).setParent(this);
             else if (so instanceof MultiFiling)
                 ((MultiFiling) so).addParent(this);
             else
-                throw new RuntimeException("Cannot create document, object is not fileable.");
+                throw new CmisInvalidArgumentException("Cannot create document, object is
not fileable.");
             
             so.persist();
         } finally {

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java?rev=980159&r1=980158&r2=980159&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
Wed Jul 28 19:01:30 2010
@@ -147,10 +147,9 @@ public class AbstractServiceTst /* exten
     }
 
     protected String createFolder(String folderName, String parentFolderId, String typeId)
{
-        Properties props = createFolderProperties(folderName, typeId);
         String id = null;
         try {
-            id = fObjSvc.createFolder(fRepositoryId, props, parentFolderId, null, null, null,
null);
+            id = createFolderNoCatch(folderName, parentFolderId, typeId);
             if (null == id)
                 fail("createFolder failed.");
         } catch (Exception e) {
@@ -159,7 +158,13 @@ public class AbstractServiceTst /* exten
         return id;
     }
 
-    protected String createDocument(String name, String folderId, String typeId, VersioningState
versioningState,
+    protected String createFolderNoCatch(String folderName, String parentFolderId, String
typeId) {
+        Properties props = createFolderProperties(folderName, typeId);
+        String id = fObjSvc.createFolder(fRepositoryId, props, parentFolderId, null, null,
null, null);
+        return id;
+    }
+
+    protected String createDocumentNoCatch(String name, String folderId, String typeId, VersioningState
versioningState,
             boolean withContent) {
         ContentStream contentStream = null;
         List<String> policies = null;
@@ -172,17 +177,22 @@ public class AbstractServiceTst /* exten
         if (withContent)
             contentStream = createContent();
 
+        String id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream,
versioningState, policies,
+                addACEs, removeACEs, extension);
+        return id;
+    }
+
+    protected String createDocument(String name, String folderId, String typeId, VersioningState
versioningState,
+            boolean withContent) {
         String id = null;
         try {
-            id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream, versioningState,
policies,
-                    addACEs, removeACEs, extension);
+            id = createDocumentNoCatch(name , folderId, typeId, versioningState, withContent);
             if (null == id)
                 fail("createDocument failed.");
         } catch (Exception e) {
             fail("createDocument() failed with exception: " + e);
         }
         return id;
-
     }
 
     protected String createDocument(String name, String folderId, String typeId, boolean
withContent) {

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=980159&r1=980158&r2=980159&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
Wed Jul 28 19:01:30 2010
@@ -50,8 +50,8 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
-import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
@@ -145,6 +145,70 @@ public class ObjectServiceTest extends A
     }
 
     @Test
+    public void testCreateDocumentInvalidNames() {
+        try {
+            createDocumentNoCatch(null, fRootFolderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false);
+            fail("Document creation with null name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisInvalidArgumentException);
+        }
+        
+        try {
+            createDocumentNoCatch("", fRootFolderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false);
+            fail("Document creation with empty name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisInvalidArgumentException);
+        }
+ 
+        try {
+            createDocumentNoCatch("/(%#$§", fRootFolderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false);
+            fail("Document creation with ilegal name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisInvalidArgumentException);
+        }
+
+        try {
+            createDocumentNoCatch("DuplicatedName", fRootFolderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false);
+            createDocumentNoCatch("DuplicatedName", fRootFolderId, DOCUMENT_TYPE_ID, VersioningState.NONE,
false);
+            fail("Document creation with existing name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisNameConstraintViolationException);
+        }
+    }
+    
+    @Test
+    public void testCreateFolderInvalidNames() {
+        try {
+            createFolderNoCatch(null, fRootFolderId, FOLDER_TYPE_ID);
+            fail("Folder creation with null name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisInvalidArgumentException);
+        }
+        
+        try {
+            createFolderNoCatch("", fRootFolderId, FOLDER_TYPE_ID);
+            fail("Folder creation with empty name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisInvalidArgumentException);
+        }
+ 
+        try {
+            createFolderNoCatch("/(%#$§", fRootFolderId, FOLDER_TYPE_ID);
+            fail("Folder creation with ilegal name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisInvalidArgumentException);
+        }
+
+        try {
+            createFolderNoCatch("DuplicatedName", fRootFolderId, FOLDER_TYPE_ID);
+            createFolderNoCatch("DuplicatedName", fRootFolderId, FOLDER_TYPE_ID);
+            fail("Folder creation with existing name should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisNameConstraintViolationException);
+        }
+    }
+     
+    @Test
     public void testGetObject() {
         log.info("starting testGetObject() ...");
         log.info("  creating object");



Mime
View raw message