directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1089052 - in /directory: apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/ shared/trunk/integ/src/test/java/org/apache/directory/shared/...
Date Tue, 05 Apr 2011 14:05:45 GMT
Author: elecharny
Date: Tue Apr  5 14:05:45 2011
New Revision: 1089052

URL: http://svn.apache.org/viewvc?rev=1089052&view=rev
Log:
o The Value isValid() method throws a LdapInvalidAttributeValueException instead of a LdapException
o The Attribute isValid() method now takes an AttributeType instead of a SyntaxChecker
o Moved the schema aware tests to shared-integ
o Fixed the impacted tests and code

Added:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
Modified:
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializationTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Attribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/DefaultAttributeTest.java

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
(original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
Tue Apr  5 14:05:45 2011
@@ -42,9 +42,9 @@ import java.util.Set;
 import javax.naming.directory.InvalidAttributeValueException;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.BinaryValue;
 import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
-import org.apache.directory.shared.ldap.model.entry.Attribute;
 import org.apache.directory.shared.ldap.model.entry.StringValue;
 import org.apache.directory.shared.ldap.model.entry.Value;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
@@ -602,25 +602,25 @@ public class SchemaAwareEntryAttributeTe
         Attribute attr = new DefaultAttribute( atCN );
 
         // No value, this should not be valid
-        assertFalse( attr.isValid( atCN.getEquality().getSyntax().getSyntaxChecker() ) );
+        assertFalse( attr.isValid( atCN ) );
 
         attr.add( "test", "test2", "A123\\;" );
-        assertTrue( attr.isValid( atCN.getEquality().getSyntax().getSyntaxChecker() ) );
+        assertTrue( attr.isValid( atCN ) );
 
         // If we try to add a wrong value, it will not be added. The
         // attribute remains valid.
         assertEquals( 0, attr.add( new byte[]
             { 0x01 } ) );
-        assertTrue( attr.isValid( atCN.getEquality().getSyntax().getSyntaxChecker() ) );
+        assertTrue( attr.isValid( atCN ) );
 
         // test a SINGLE-VALUE attribute. CountryName is SINGLE-VALUE
         attr.clear();
         attr.apply( atC );
         attr.add( "FR" );
-        assertTrue( attr.isValid( atC.getEquality().getSyntax().getSyntaxChecker() ) );
+        assertTrue( attr.isValid( atC ) );
         assertEquals( 0, attr.add( "US" ) );
         assertFalse( attr.contains( "US" ) );
-        assertTrue( attr.isValid( atC.getEquality().getSyntax().getSyntaxChecker() ) );
+        assertTrue( attr.isValid( atC ) );
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
Tue Apr  5 14:05:45 2011
@@ -1069,7 +1069,7 @@ public class SchemaInterceptor extends B
                         Attribute newAttribute = attribute.clone();
                         
                         // Check that the attribute allows null values if we don'y have any
value
-                        if ( ( newAttribute.size() == 0 ) && !newAttribute.isValid(
attributeType.getSyntax().getSyntaxChecker() ) )
+                        if ( ( newAttribute.size() == 0 ) && !newAttribute.isValid(
attributeType ) )
                         {
                             // This is an error.
                             String msg = I18n.err( I18n.ERR_54, null );

Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java?rev=1089052&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
(added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareAttributeTest.java
Tue Apr  5 14:05:45 2011
@@ -0,0 +1,77 @@
+/*
+ *  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.directory.shared.ldap.entry;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+/**
+ * Test the schema aware Attribute
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaAwareAttributeTest
+{
+    private static AttributeType atCn = null;
+
+    private static SchemaManager schemaManager;
+
+    /**
+     * Initialize the schemaManager
+     */
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+        atCn = schemaManager.getAttributeType( "cn" );
+    }
+
+    
+    /**
+     * Test method isValid( SyntaxChecker ) 
+     */
+    @Test
+    public void testIsValidSyntaxChecker() throws LdapException
+    {
+        Attribute attr = new DefaultAttribute( "test" );
+        
+        attr.add( "test", "another test" );
+        
+        assertTrue( attr.isValid( atCn ) );
+        
+        attr.add( "test an invalid '\uFFFD' char" );
+        assertFalse( attr.isValid( atCn ) );
+    }
+}

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializationTest.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializationTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializationTest.java
Tue Apr  5 14:05:45 2011
@@ -41,7 +41,7 @@ import com.mycila.junit.concurrent.Concu
 import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
- * Test the EntryAttribute Serialization
+ * Test the Attribute Serialization
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
Tue Apr  5 14:05:45 2011
@@ -278,13 +278,13 @@ public abstract class AbstractValue<T> i
     /**
      * {@inheritDoc}
      */
-    public final boolean isValid( SyntaxChecker syntaxChecker ) throws LdapException
+    public final boolean isValid( SyntaxChecker syntaxChecker ) throws LdapInvalidAttributeValueException
     {
         if ( syntaxChecker == null )
         {
             String message = I18n.err( I18n.ERR_04139, toString() );
             LOG.error( message );
-            throw new LdapException( message );
+            throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
message );
         }
         
         return syntaxChecker.isValidSyntax( normalizedValue );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Attribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Attribute.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Attribute.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Attribute.java
Tue Apr  5 14:05:45 2011
@@ -22,10 +22,8 @@ package org.apache.directory.shared.ldap
 import java.io.Externalizable;
 import java.util.Iterator;
 
-import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
-import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
 
 
 /**
@@ -426,9 +424,9 @@ public interface Attribute extends Itera
     /**
      * Checks to see if this attribute is valid along with the values it contains.
      *
-     * @param checker The syntax checker
+     * @param attributeType The AttributeType
      * @return true if the attribute and it's values are valid, false otherwise
-     * @throws LdapException if there is a failure to check syntaxes of values
+     * @throws LdapInvalidAttributeValueException if there is a failure to check syntaxes
of values
      */
-    boolean isValid( SyntaxChecker checker) throws LdapException;
+    boolean isValid( AttributeType attributeType ) throws LdapInvalidAttributeValueException;
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultAttribute.java
Tue Apr  5 14:05:45 2011
@@ -32,6 +32,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.LdapSyntax;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
 import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
@@ -651,17 +652,49 @@ public class DefaultAttribute implements
     /**
      * {@inheritDoc}
      */
-    public boolean isValid( SyntaxChecker checker ) throws LdapException
+    public boolean isValid( AttributeType attributeType ) throws LdapInvalidAttributeValueException
     {
+        LdapSyntax syntax = attributeType.getSyntax();
+        
+        if ( syntax == null )
+        {
+            return false;
+        }
+        
+        SyntaxChecker syntaxChecker = syntax.getSyntaxChecker();
+        
+        if ( syntaxChecker == null )
+        {
+            return false;
+        }
+        
+        
         // Check that we can have no value for this attributeType
         if ( values.size() == 0 )
         {
-            return checker.isValidSyntax( null );
+            return syntaxChecker.isValidSyntax( null );
+        }
+        
+        // Check that we can't have more than one value if the AT is single-value
+        if ( attributeType.isSingleValued() )
+        {
+            if ( values.size() > 1 )
+            {
+                return false;
+            }
         }
 
+        // Now check the values
         for ( Value<?> value : values )
         {
-            if ( !value.isValid( checker ) )
+            try
+            {
+                if ( !value.isValid( syntaxChecker ) )
+                {
+                    return false;
+                }
+            }
+            catch ( LdapException le )
             {
                 return false;
             }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
Tue Apr  5 14:05:45 2011
@@ -22,7 +22,6 @@ package org.apache.directory.shared.ldap
 
 import java.io.Externalizable;
 
-import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
@@ -139,9 +138,9 @@ public interface Value<T> extends Clonea
      * 
      * @param checker the SyntaxChecker to use to validate the value
      * @return <code>true</code> if the value is valid
-     * @exception LdapException if the value cannot be validated
+     * @exception LdapInvalidAttributeValueException if the value cannot be validated
      */
-    boolean isValid( SyntaxChecker checker ) throws LdapException;
+    boolean isValid( SyntaxChecker checker ) throws LdapInvalidAttributeValueException;
 
     
     /**

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/DefaultAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/DefaultAttributeTest.java?rev=1089052&r1=1089051&r2=1089052&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/DefaultAttributeTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/DefaultAttributeTest.java
Tue Apr  5 14:05:45 2011
@@ -37,7 +37,6 @@ import javax.naming.directory.InvalidAtt
 
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
-import org.apache.directory.shared.ldap.model.schema.syntaxCheckers.Ia5StringSyntaxChecker;
 import org.apache.directory.shared.util.StringConstants;
 import org.apache.directory.shared.util.Strings;
 import org.junit.BeforeClass;
@@ -435,23 +434,6 @@ public class DefaultAttributeTest
 
 
     /**
-     * Test method isValid( SyntaxChecker ) 
-     */
-    @Test
-    public void testIsValidSyntaxChecker() throws LdapException
-    {
-        Attribute attr = new DefaultAttribute( "test" );
-        
-        attr.add( "test", "another test" );
-        
-        assertTrue( attr.isValid( new Ia5StringSyntaxChecker() ) );
-        
-        attr.add( "é" );
-        assertFalse( attr.isValid( new Ia5StringSyntaxChecker() ) );
-    }
-
-
-    /**
      * Test method iterator()
      */
     @Test



Mime
View raw message