You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/02/14 16:54:23 UTC

svn commit: r1244009 - 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/server/ main/java/org/apache/chemis...

Author: jens
Date: Tue Feb 14 15:54:22 2012
New Revision: 1244009

URL: http://svn.apache.org/viewvc?rev=1244009&view=rev
Log:
more validation code for type mutability

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/TypeManagerCreatable.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceMutabilityTest.java

Modified: 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/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java?rev=1244009&r1=1244008&r2=1244009&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/NameValidator.java Tue Feb 14 15:54:22 2012
@@ -22,7 +22,7 @@ package org.apache.chemistry.opencmis.in
 public class NameValidator {
 
     public static final String ERROR_ILLEGAL_ID = "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_'";
-    public static final String ERROR_ILLEGAL_NAME = "Id contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_', '.', ' '";
+    public static final String ERROR_ILLEGAL_NAME = "Name contains illegal characters, allowed are 'a'..'z', 'A'..'Z', '0'..'9', '-', '_', '.', ' '";
 
     // Utility class
     private NameValidator() {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java?rev=1244009&r1=1244008&r2=1244009&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java Tue Feb 14 15:54:22 2012
@@ -143,18 +143,9 @@ public class TypeManagerImpl implements 
      *            new type to add
      */
     public void addTypeDefinition(TypeDefinition cmisType) {
-        if (fTypesMap.containsKey(cmisType.getId())) {
-            throw new CmisConstraintException("You cannot add type with id " + cmisType.getId()
-                    + " because it already exists.");
-        }
-
+        
         TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(cmisType);
 
-        if (!fTypesMap.containsKey(cmisType.getParentTypeId())) {
-            throw new CmisConstraintException("Cannot add type, because parent with id " + cmisType.getParentTypeId()
-                    + " does not exist.");
-        }
-
         // add new type to children of parent types
         TypeDefinitionContainer parentTypeContainer = fTypesMap.get(cmisType.getParentTypeId());
         parentTypeContainer.getChildren().add(typeContainer);

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java?rev=1244009&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java Tue Feb 14 15:54:22 2012
@@ -0,0 +1,144 @@
+/*
+ * 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 java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.server.support.TypeManager;
+
+/**
+ * A helper class doing some consistency checks when new type definitions are added to the system
+ * 
+ * @author Jens
+ *
+ */
+public class TypeValidator {
+    
+    public static void checkType(TypeManager tm, TypeDefinition td) {
+
+        if (null == tm.getTypeById(td.getParentTypeId())) {
+            throw new CmisInvalidArgumentException("Cannot add type, because parent with id " + td.getParentTypeId()
+                    + " does not exist.");
+        }
+
+        checkTypeId(tm, td.getId());
+        checkTypeQueryName(tm, td.getQueryName());
+        checkTypeLocalName(tm, td.getLocalName());
+    }
+    
+    public static void checkProperties(TypeManager tm, Collection<PropertyDefinition<?>> pds) {
+
+        Collection<TypeDefinitionContainer> tdl = tm.getTypeDefinitionList();
+        for (PropertyDefinition<?> pd2 : pds) {
+            // check id syntax
+            if (null == pd2.getId())
+                throw new CmisInvalidArgumentException("property id cannot be null.");
+            if (!NameValidator.isValidId(pd2.getId()))
+                throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+    
+            // check query name syntax
+            if (null == pd2.getQueryName())
+                throw new CmisInvalidArgumentException("property query name cannot be null.");
+            if (!NameValidator.isValidName(pd2.getQueryName()))
+                throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+    
+            // check local name syntax
+            if (null == pd2.getLocalName())
+                throw new CmisInvalidArgumentException("property local name cannot be null.");
+            if (!NameValidator.isValidName(pd2.getLocalName()))
+                throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+            
+            for (TypeDefinitionContainer tdc : tdl) {
+                TypeDefinition td = tdc.getTypeDefinition();
+                for (PropertyDefinition<?> pd1 : td.getPropertyDefinitions().values()) {
+                    // check if id is used
+                    if (pd1.getId().equals(pd2.getId()))
+                        throw new CmisConstraintException("Property id " + pd2.getId() + " already in use in type "
+                                + td.getId());
+                    // check if query name is used
+                    if (pd1.getQueryName().equals(pd2.getQueryName()))
+                        throw new CmisConstraintException("Property query name " + pd2.getQueryName() + " already in use in type "
+                                + td.getQueryName());
+                    // check if local name is used
+                    if (pd1.getLocalName().equals(pd2.getLocalName()))
+                        throw new CmisConstraintException("Property local name " + pd2.getLocalName() + " already in use in type "
+                                + td.getId());
+                }
+            }
+        }        
+    }
+    
+    private static void checkTypeId(TypeManager tm, String typeId) {
+
+        if (null == typeId) {
+            throw new CmisInvalidArgumentException("Type id cannot be null.");
+        }
+
+        // check name syntax
+        if (!NameValidator.isValidId(typeId)) {
+            throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_ID);
+        }
+
+        if (null != tm.getTypeById(typeId)) {
+            throw new CmisInvalidArgumentException("You cannot add type with id " + typeId
+                    + " because it already exists.");           
+        }
+    }
+    
+    private static void checkTypeQueryName(TypeManager tm, String queryName) {
+
+        if (null == queryName) {
+            throw new CmisInvalidArgumentException("Query name cannot be null.");
+        }
+
+        if (!NameValidator.isValidQueryName(queryName)) {
+            throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+        }
+        
+        // check set query name is unique in the type system
+        if (null != tm.getTypeByQueryName(queryName)) {
+            throw new CmisInvalidArgumentException("You cannot add type with query name " + queryName
+                    + " because it already exists.");           
+        }
+    }
+    
+    private static void checkTypeLocalName(TypeManager tm, String localName) {
+        
+        if (null == localName) {
+            throw new CmisInvalidArgumentException("Local name cannot be null.");
+        }
+
+        if (!NameValidator.isValidLocalName(localName)) {
+            throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+        }
+        
+        for (TypeDefinitionContainer tdc : tm.getTypeDefinitionList()) {
+            if (tdc.getTypeDefinition().getLocalName().equals(localName))
+                throw new CmisConstraintException("You cannot add type with local name " + localName
+                        + " because it already exists.");                       
+        }
+    }
+
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java?rev=1244009&r1=1244008&r2=1244009&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java Tue Feb 14 15:54:22 2012
@@ -34,6 +34,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
+import org.apache.chemistry.opencmis.inmemory.TypeValidator;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.TypeManagerCreatable;
@@ -146,28 +147,17 @@ public class InMemoryRepositoryServiceIm
 
     public void createTypeDefinition(String repositoryId, Holder<TypeDefinition> type, ExtensionsData extension) {
 
+        if (null == repositoryId)
+            throw new CmisInvalidArgumentException("Repository id may not be null");
+
         TypeManagerCreatable typeManager = fStoreManager.getTypeManager(repositoryId);
         if (null == typeManager)
             throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
         
-        String typeId = type.getValue().getId();
-
-        if (null == typeId)
-            throw new CmisInvalidArgumentException("Cannot add type, type id is required.");
-        
-        if (typeManager.getTypeById(typeId) != null)
-            throw new CmisInvalidArgumentException("Cannot add type "
-                    + typeId + ", type already exists");
+        TypeDefinition td = type.getValue();
+        TypeValidator.checkType(typeManager, td);
+        TypeValidator.checkProperties(typeManager, td.getPropertyDefinitions().values());
         
-        String parentTypeId = type.getValue().getParentTypeId();
-
-        if (null == parentTypeId)
-            throw new CmisInvalidArgumentException("Cannot add type, parent type id is required.");
-        
-        if (typeManager.getTypeById(parentTypeId) == null)
-            throw new CmisInvalidArgumentException("Cannot add type "
-                    + parentTypeId + " is unknown.");
-
         typeManager.addTypeDefinition(type.getValue());
     }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/TypeManagerCreatable.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/TypeManagerCreatable.java?rev=1244009&r1=1244008&r2=1244009&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/TypeManagerCreatable.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/TypeManagerCreatable.java Tue Feb 14 15:54:22 2012
@@ -31,7 +31,7 @@ public interface TypeManagerCreatable ex
      * @param cmisType
      *            new type to add
      */
-    public abstract void addTypeDefinition(TypeDefinition typeDefinition);
+    void addTypeDefinition(TypeDefinition typeDefinition);
     
     /**
      * Modify an existing type definition
@@ -39,7 +39,7 @@ public interface TypeManagerCreatable ex
      * @param typeDefinition
      *          type to be modified
      */    
-    public void updateTypeDefinition(TypeDefinition typeDefinition);
+    void updateTypeDefinition(TypeDefinition typeDefinition);
 
    /**
      * Delete a type from the type system. Delete will succeed only if type is not in use.
@@ -48,5 +48,5 @@ public interface TypeManagerCreatable ex
      * @param cmisType
      *            type to delete
      */
-    public abstract void deleteTypeDefinition(String typeId);
+    void deleteTypeDefinition(String typeId);
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceMutabilityTest.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/RepositoryServiceMutabilityTest.java?rev=1244009&r1=1244008&r2=1244009&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceMutabilityTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceMutabilityTest.java Tue Feb 14 15:54:22 2012
@@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.in
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.HashMap;
@@ -36,6 +37,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
 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.CmisNotSupportedException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
@@ -65,6 +67,8 @@ public class RepositoryServiceMutability
     private static final Log log = LogFactory.getLog(RepositoryServiceTest.class);
     private static final String REPOSITORY_ID = "UnitTestRepository";
     private static final String TYPE_ID_MUTABILITY = "BookTypeAddedLater";
+    private static final String PROPERTY_ID_TITLE = "Title";
+    private static final String PROPERTY_ID_NUMBER = "Number";
 
     private InMemoryRepositoryServiceImpl repSvc;
     private InMemoryObjectServiceImpl objSvc;
@@ -94,6 +98,9 @@ public class RepositoryServiceMutability
         super.tearDown();
     }
 
+    // This test is just added because this test class uses a different setup to connect to the
+    // server as long as the server bindings do not support the type mutability extension of 
+    // CMIS 1.1. If this test fails then the setUp() fails! 
     @Test
     public void testRepositoryInfo() {
         log.info("starting testRepositoryInfo() ...");
@@ -118,7 +125,7 @@ public class RepositoryServiceMutability
     public void testTypeMutabilityCreation() throws Exception {
         log.info("");
         log.info("starting testTypeMutabilityCreation() ...");
-        TypeDefinition typeDefRef = getTypeForAddingAtRuntime();
+        TypeDefinition typeDefRef = createTypeForAddingAtRuntime();
         String repositoryId = getRepositoryId();
         // add type.
         repSvc.createTypeDefinition(repositoryId, new Holder<TypeDefinition>(typeDefRef), null);
@@ -131,12 +138,128 @@ public class RepositoryServiceMutability
         RepositoryServiceTest.containsAllBasePropertyDefinitions(type);
         log.info("... testTypeMutabilityCreation() finished.");
     }
+    
+    @Test
+    public void testTypeMutabilityCreateDuplicate() throws Exception {
+        log.info("");
+        log.info("starting testTypeMutabilityCreateDuplicate() ...");
+        TypeDefinition typeDefRef = createTypeForAddingAtRuntime();
+        String repositoryId = getRepositoryId();
+        // add type.
+        repSvc.createTypeDefinition(repositoryId, new Holder<TypeDefinition>(typeDefRef), null);
+        // add type again should fail
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+        // type should still exist then
+        TypeDefinition type = repSvc.getTypeDefinition(fTestCallContext, repositoryId, typeDefRef.getId(), null);
+        assertEquals(typeDefRef.getId(), type.getId());
+        log.info("... testTypeMutabilityCreateDuplicate() finished.");
+    }
+    
+    
+    @Test
+    public void testTypeMutabilityTypeNameConstraints() throws Exception {
+        log.info("starting testTypeMutabilityTypeNameConstraints() ...");
+        
+        String repositoryId = getRepositoryId();
+        
+        // test illegal type id
+        InMemoryDocumentTypeDefinition typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setId(typeDefRef.getId() + "!!!");
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+
+        // test illegal parent type id
+        typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setParentTypeId("NonExistingParentType");
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+
+        // test null type id
+        typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setId(null);
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+        
+        // test null query name
+        typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setQueryName(null);
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+
+        // test illegal query name
+        typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setQueryName(typeDefRef.getQueryName() + "!!!");
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+
+        // test null local name
+        typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setLocalName(null);
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
+
+        // test illegal local name
+        typeDefRef = createTypeForAddingAtRuntime();
+        typeDefRef.setLocalName(typeDefRef.getLocalName() + "!!!");
+        checkAddingType(repositoryId, typeDefRef, CmisInvalidArgumentException.class);
 
+        log.info("... testTypeMutabilityTypeNameConstraints() finished.");              
+    }
+    
+    @Test
+    public void testTypeMutabilityPropertyNameConstraints() throws Exception {
+        log.info("starting testTypeMutabilityPropertyNameConstraints() ...");
+        
+        String repositoryId = getRepositoryId();
+        
+        // test null property id
+        InMemoryDocumentTypeDefinition typeDef = createTypeForAddingAtRuntime();
+        PropertyStringDefinitionImpl pd = getPropertyDefinitionImpl(typeDef);
+        pd.setId(null);
+        checkAddingType(repositoryId, typeDef, CmisInvalidArgumentException.class);
+        
+        // test illegal property id
+        typeDef = createTypeForAddingAtRuntime();
+        pd = getPropertyDefinitionImpl(typeDef);
+        pd.setQueryName(pd.getQueryName() + "!!!");
+        checkAddingType(repositoryId, typeDef, CmisInvalidArgumentException.class);
+
+        // test null property query name
+        typeDef = createTypeForAddingAtRuntime();
+        pd = getPropertyDefinitionImpl(typeDef);
+        pd.setQueryName(null);
+        checkAddingType(repositoryId, typeDef, CmisInvalidArgumentException.class);
+
+        // test illegal property query name
+        typeDef = createTypeForAddingAtRuntime();
+        pd = getPropertyDefinitionImpl(typeDef);
+        pd.setQueryName(pd.getQueryName() + "!!!");
+        checkAddingType(repositoryId, typeDef, CmisInvalidArgumentException.class);
+
+        // test null property local name
+        typeDef = createTypeForAddingAtRuntime();
+        pd = getPropertyDefinitionImpl(typeDef);
+        pd.setLocalName(null);
+        checkAddingType(repositoryId, typeDef, CmisInvalidArgumentException.class);
+
+        // test illegal property local name
+        typeDef = createTypeForAddingAtRuntime();
+        pd = getPropertyDefinitionImpl(typeDef);
+        pd.setLocalName(typeDef.getLocalName() + "!!!");
+        checkAddingType(repositoryId, typeDef, CmisInvalidArgumentException.class);
+
+        log.info("... testTypeMutabilityPropertyNameConstraints() finished.");              
+    }
+    
+    private void checkAddingType(String repositoryId, TypeDefinition typeDef, Class<? extends Exception> clazz) {
+        try { 
+            repSvc.createTypeDefinition(repositoryId, new Holder<TypeDefinition>(typeDef), null);
+            fail("Illegal type should throw a " + clazz.getName());
+        } catch (RuntimeException e) {
+            assertTrue("Illegal type name threw wrong exception type (should be a " + clazz.getName() + ")",
+                    clazz.isInstance(e));
+        }        
+    }
+    
     @Test
     public void testTypeMutabilityUpdate() throws Exception {
         log.info("");
         log.info("starting testTypeMutabilityUpdate() ...");
-        TypeDefinition typeDefRef = getTypeForAddingAtRuntime();
+        TypeDefinition typeDefRef = createTypeForAddingAtRuntime();
         String repositoryId = getRepositoryId();
         repSvc.createTypeDefinition(repositoryId, new Holder<TypeDefinition>(typeDefRef), null);
         // update type.
@@ -148,11 +271,12 @@ public class RepositoryServiceMutability
         }
         log.info("... testTypeMutabilityUpdate() finished.");
     }
+   
     @Test
     public void testTypeMutabilityDeletion() throws Exception {
         log.info("");
         log.info("starting testTypeMutabilityDeletion() ...");
-        TypeDefinition typeDefRef = getTypeForAddingAtRuntime();
+        TypeDefinition typeDefRef = createTypeForAddingAtRuntime();
         String repositoryId = getRepositoryId();
         repSvc.createTypeDefinition(repositoryId, new Holder<TypeDefinition>(typeDefRef), null);
         
@@ -209,18 +333,24 @@ public class RepositoryServiceMutability
         return repository.getRootFolderId();
     }
 
-    private TypeDefinition getTypeForAddingAtRuntime() {
+    private PropertyStringDefinitionImpl getPropertyDefinitionImpl(TypeDefinition typeDef) {
+        @SuppressWarnings("unchecked")
+        PropertyStringDefinitionImpl pd = (PropertyStringDefinitionImpl) typeDef.getPropertyDefinitions().get(PROPERTY_ID_TITLE);
+        return pd;
+    }
+    
+    private InMemoryDocumentTypeDefinition createTypeForAddingAtRuntime() {
         
         InMemoryDocumentTypeDefinition cmisLaterType = new InMemoryDocumentTypeDefinition(TYPE_ID_MUTABILITY,
                 "Type with two properties", InMemoryDocumentTypeDefinition.getRootDocumentType());
 
         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
 
-        PropertyIntegerDefinitionImpl prop1 = PropertyCreationHelper.createIntegerDefinition("Number",
+        PropertyIntegerDefinitionImpl prop1 = PropertyCreationHelper.createIntegerDefinition(PROPERTY_ID_NUMBER,
                 "Sample Int Property", Updatability.READWRITE);
         propertyDefinitions.put(prop1.getId(), prop1);
 
-        PropertyStringDefinitionImpl prop2 = PropertyCreationHelper.createStringDefinition("Title",
+        PropertyStringDefinitionImpl prop2 = PropertyCreationHelper.createStringDefinition(PROPERTY_ID_TITLE,
                 "Sample String Property", Updatability.READWRITE);
         propertyDefinitions.put(prop2.getId(), prop2);