directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r928296 [3/3] - in /directory: apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/ apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/context/ apacheds/trunk/core-entry/...
Date Sat, 27 Mar 2010 22:50:34 GMT
Copied: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java
(from r927043, directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java?p2=directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java&p1=directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java&r1=927043&r2=928296&rev=928296&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/ClientBinaryValueTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueTest.java
Sat Mar 27 22:50:33 2010
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.directory.shared.ldap.entry.client;
+package org.apache.directory.shared.ldap.entry;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -32,6 +32,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.Arrays;
 
+import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.schema.Normalizer;
@@ -41,12 +42,12 @@ import org.junit.Test;
 
 /**
  * 
- * Test the ClientBinaryValue class
+ * Test the BinaryValue class
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ClientBinaryValueTest
+public class BinaryValueTest
 {
     private static final byte[] BYTES1 = new byte[]{0x01, 0x02, 0x03, 0x04};
     private static final byte[] BYTES2 = new byte[]{(byte)0x81, (byte)0x82, (byte)0x83, (byte)0x84};
@@ -71,7 +72,7 @@ public class ClientBinaryValueTest
                     newVal[i++] = (byte)(b & 0x007F); 
                 }
                 
-                return new ClientBinaryValue( StringTools.trim( newVal ) );
+                return new BinaryValue( StringTools.trim( newVal ) );
             }
 
             throw new IllegalStateException( "expected byte[] to normalize" );
@@ -95,7 +96,7 @@ public class ClientBinaryValueTest
         {
             if ( value.isBinary() )
             {
-                return new ClientBinaryValue( StringTools.EMPTY_BYTES );
+                return new BinaryValue( StringTools.EMPTY_BYTES );
             }
 
             throw new IllegalStateException( "expected byte[] to normalize" );
@@ -123,9 +124,9 @@ public class ClientBinaryValueTest
     
     
     /**
-     * Serialize a ClientBinaryValue
+     * Serialize a BinaryValue
      */
-    private ByteArrayOutputStream serializeValue( ClientBinaryValue value ) throws IOException
+    private ByteArrayOutputStream serializeValue( BinaryValue value ) throws IOException
     {
         ObjectOutputStream oOut = null;
         ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -160,9 +161,9 @@ public class ClientBinaryValueTest
     
     
     /**
-     * Deserialize a ClientBinaryValue
+     * Deserialize a BinaryValue
      */
-    private ClientBinaryValue deserializeValue( ByteArrayOutputStream out ) throws IOException,
ClassNotFoundException
+    private BinaryValue deserializeValue( ByteArrayOutputStream out ) throws IOException,
ClassNotFoundException
     {
         ObjectInputStream oIn = null;
         ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
@@ -171,7 +172,7 @@ public class ClientBinaryValueTest
         {
             oIn = new ObjectInputStream( in );
 
-            ClientBinaryValue value = ( ClientBinaryValue ) oIn.readObject();
+            BinaryValue value = ( BinaryValue ) oIn.readObject();
 
             return value;
         }
@@ -199,7 +200,7 @@ public class ClientBinaryValueTest
     @Test
     public void testHashCode()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         assertEquals( 0, cbv.hashCode() );
         
         cbv.set( StringTools.EMPTY_BYTES );
@@ -215,7 +216,7 @@ public class ClientBinaryValueTest
     @Test
     public void testClear() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue( BYTES2 );
+        BinaryValue cbv = new BinaryValue( BYTES2 );
         cbv.normalize( BINARY_NORMALIZER );
         cbv.isValid( BINARY_CHECKER );
         
@@ -233,9 +234,9 @@ public class ClientBinaryValueTest
 
 
     @Test
-    public void testClientBinaryValueNull() throws LdapException
+    public void testBinaryValueNull() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue( null );
+        BinaryValue cbv = new BinaryValue( (byte[])null );
         
         assertNull( cbv.get() );
         assertFalse( cbv.isNormalized() );
@@ -246,9 +247,9 @@ public class ClientBinaryValueTest
 
 
     @Test
-    public void testClientBinaryValueEmpty() throws LdapException
+    public void testBinaryValueEmpty() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue( StringTools.EMPTY_BYTES );
+        BinaryValue cbv = new BinaryValue( StringTools.EMPTY_BYTES );
         
         assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getBytes() ) );
         assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, cbv.getCopy() ) );
@@ -263,9 +264,9 @@ public class ClientBinaryValueTest
 
 
     @Test
-    public void testClientBinaryValue() throws LdapException
+    public void testBinaryValue() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue( BYTES1 );
+        BinaryValue cbv = new BinaryValue( BYTES1 );
         
         assertTrue( Arrays.equals( BYTES1, cbv.getBytes() ) );
         assertTrue( Arrays.equals( BYTES1, cbv.getCopy() ) );
@@ -281,7 +282,7 @@ public class ClientBinaryValueTest
     @Test
     public void testSetByteArray() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         cbv.set( BYTES1 );
         
@@ -299,7 +300,7 @@ public class ClientBinaryValueTest
     @Test
     public void testGetNormalizedValueCopy()  throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue( BYTES2 );
+        BinaryValue cbv = new BinaryValue( BYTES2 );
         
         assertTrue( Arrays.equals( BYTES2, cbv.getBytes() ) );
         assertTrue( Arrays.equals( BYTES2, cbv.getCopy() ) );
@@ -321,7 +322,7 @@ public class ClientBinaryValueTest
     @Test
     public void testNormalizeNormalizer() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         cbv.normalize( BINARY_NORMALIZER );
         assertTrue( cbv.isNormalized() );
@@ -350,8 +351,8 @@ public class ClientBinaryValueTest
     @Test
     public void testCompareToValueOfbyte() throws LdapException
     {
-        ClientBinaryValue cbv1 = new ClientBinaryValue();
-        ClientBinaryValue cbv2 = new ClientBinaryValue();
+        BinaryValue cbv1 = new BinaryValue();
+        BinaryValue cbv2 = new BinaryValue();
         
         assertEquals( 0, cbv1.compareTo( cbv2 ) );
         
@@ -372,8 +373,8 @@ public class ClientBinaryValueTest
     @Test
     public void testEquals() throws LdapException
     {
-        ClientBinaryValue cbv1 = new ClientBinaryValue();
-        ClientBinaryValue cbv2 = new ClientBinaryValue();
+        BinaryValue cbv1 = new BinaryValue();
+        BinaryValue cbv2 = new BinaryValue();
         
         assertEquals( cbv1, cbv2 );
         
@@ -394,8 +395,8 @@ public class ClientBinaryValueTest
     @Test
     public void testClone()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
-        ClientBinaryValue copy = cbv.clone();
+        BinaryValue cbv = new BinaryValue();
+        BinaryValue copy = cbv.clone();
         
         assertEquals( cbv, copy );
         
@@ -415,7 +416,7 @@ public class ClientBinaryValueTest
     @Test
     public void testGetCopy()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertNull( cbv.getCopy() );
         
@@ -437,8 +438,8 @@ public class ClientBinaryValueTest
     @Test
     public void testCompareTo() throws LdapException
     {
-        ClientBinaryValue cbv1 = new ClientBinaryValue();
-        ClientBinaryValue cbv2 = new ClientBinaryValue();
+        BinaryValue cbv1 = new BinaryValue();
+        BinaryValue cbv2 = new BinaryValue();
         
         assertEquals( 0, cbv1.compareTo( cbv2 ) );
         
@@ -468,7 +469,7 @@ public class ClientBinaryValueTest
     @Test
     public void testToString()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertEquals( "null", cbv.toString() );
 
@@ -486,7 +487,7 @@ public class ClientBinaryValueTest
     @Test
     public void testGetReference()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertNull( cbv.getReference() );
         
@@ -508,7 +509,7 @@ public class ClientBinaryValueTest
     @Test
     public void testGet()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertNull( cbv.get() );
         
@@ -530,7 +531,7 @@ public class ClientBinaryValueTest
     @Test
     public void testGetNormalizedValue() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertFalse( cbv.isNormalized() );
 
@@ -551,7 +552,7 @@ public class ClientBinaryValueTest
     @Test
     public void testGetNormalizedValueReference() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertFalse( cbv.isNormalized() );
 
@@ -572,7 +573,7 @@ public class ClientBinaryValueTest
     @Test
     public void testIsNull()
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertTrue( cbv.isNull() );
         
@@ -590,7 +591,7 @@ public class ClientBinaryValueTest
     @Test
     public void testIsValid() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertFalse( cbv.isValid() );
         cbv.isValid( BINARY_CHECKER );
@@ -616,7 +617,7 @@ public class ClientBinaryValueTest
     @Test
     public void testIsValidSyntaxChecker() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertTrue( cbv.isValid( BINARY_CHECKER ) ) ;
         
@@ -634,7 +635,7 @@ public class ClientBinaryValueTest
     @Test
     public void testNormalize() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         cbv.normalize();
         assertTrue( cbv.isNormalized() );
@@ -655,7 +656,7 @@ public class ClientBinaryValueTest
     @Test
     public void testSet() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         cbv.set( null );
         assertNull( cbv.get() );
@@ -682,7 +683,7 @@ public class ClientBinaryValueTest
     @Test
     public void testIsNormalized() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertFalse( cbv.isNormalized() );
         
@@ -705,14 +706,14 @@ public class ClientBinaryValueTest
     @Test
     public void testSetNormalized() throws LdapException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         
         assertFalse( cbv.isNormalized() );
         
         cbv.setNormalized( true );
         assertTrue( cbv.isNormalized() );
         
-        cbv.set(  BYTES2 );
+        cbv.set( BYTES2 );
         assertFalse( cbv.isNormalized() );
         
         cbv.normalize( BINARY_NORMALIZER );
@@ -721,8 +722,8 @@ public class ClientBinaryValueTest
         assertTrue( cbv.isNormalized() );
         
         cbv.setNormalized( false );
-        assertTrue( Arrays.equals( BYTES1, cbv.getNormalizedValue() ) );
-        assertFalse( cbv.isNormalized() );
+        assertTrue( Arrays.equals( BYTES2, cbv.getNormalizedValue() ) );
+        assertTrue( cbv.isNormalized() );
 
         cbv.normalize( BINARY_NORMALIZER );
         cbv.clear();
@@ -736,13 +737,13 @@ public class ClientBinaryValueTest
     @Test
     public void testSerializeStandard() throws LdapException, IOException, ClassNotFoundException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         cbv.setNormalized( true );
         cbv.set( BYTES2 );
         cbv.normalize( BINARY_NORMALIZER );
         cbv.isValid( BINARY_CHECKER );
 
-        ClientBinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
+        BinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
          assertNotSame( cbv, cbvSer );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getReference() ) );
          assertTrue( Arrays.equals( cbv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference()
) );
@@ -757,16 +758,16 @@ public class ClientBinaryValueTest
     @Test
     public void testSerializeNotNormalized() throws LdapException, IOException, ClassNotFoundException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         cbv.setNormalized( false );
         cbv.set( BYTES2 );
         cbv.isValid( BINARY_CHECKER );
 
-        ClientBinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
+        BinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
          assertNotSame( cbv, cbvSer );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getReference() ) );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getNormalizedValueReference()
) );
-         assertFalse( cbvSer.isNormalized() );
+         assertTrue( cbvSer.isNormalized() );
          assertFalse( cbvSer.isValid() );
     }
     
@@ -777,13 +778,13 @@ public class ClientBinaryValueTest
     @Test
     public void testSerializeEmptyNormalized() throws LdapException, IOException, ClassNotFoundException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         cbv.setNormalized( true );
         cbv.set( BYTES2 );
         cbv.isValid( BINARY_CHECKER );
         cbv.normalize( BINARY_NORMALIZER_EMPTY );
 
-        ClientBinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
+        BinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
          assertNotSame( cbv, cbvSer );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getReference() ) );
          assertTrue( Arrays.equals( cbv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference()
) );
@@ -798,13 +799,13 @@ public class ClientBinaryValueTest
     @Test
     public void testSerializeNullValue() throws LdapException, IOException, ClassNotFoundException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         cbv.setNormalized( true );
         cbv.set( null );
         cbv.isValid( BINARY_CHECKER );
         cbv.normalize( BINARY_NORMALIZER );
 
-        ClientBinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
+        BinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
          assertNotSame( cbv, cbvSer );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getReference() ) );
          assertTrue( Arrays.equals( cbv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference()
) );
@@ -819,13 +820,13 @@ public class ClientBinaryValueTest
     @Test
     public void testSerializeEmptyValue() throws LdapException, IOException, ClassNotFoundException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         cbv.setNormalized( true );
         cbv.set( StringTools.EMPTY_BYTES );
         cbv.isValid( BINARY_CHECKER );
         cbv.normalize( BINARY_NORMALIZER );
 
-        ClientBinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
+        BinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
          assertNotSame( cbv, cbvSer );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getReference() ) );
          assertTrue( Arrays.equals( cbv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference()
) );
@@ -840,16 +841,16 @@ public class ClientBinaryValueTest
     @Test
     public void testSerializeEmptyValueNotNormalized() throws LdapException, IOException,
ClassNotFoundException
     {
-        ClientBinaryValue cbv = new ClientBinaryValue();
+        BinaryValue cbv = new BinaryValue();
         cbv.setNormalized( false );
         cbv.set( StringTools.EMPTY_BYTES );
         cbv.isValid( BINARY_CHECKER );
 
-        ClientBinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
+        BinaryValue cbvSer = deserializeValue( serializeValue( cbv ) );
          assertNotSame( cbv, cbvSer );
          assertTrue( Arrays.equals( cbv.getReference(), cbvSer.getReference() ) );
          assertTrue( Arrays.equals( cbv.getNormalizedValueReference(), cbvSer.getNormalizedValueReference()
) );
-         assertFalse( cbvSer.isNormalized() );
+         assertTrue( cbvSer.isNormalized() );
          assertFalse( cbvSer.isValid() );
     }
 }

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/EntryUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/EntryUtils.java?rev=928296&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/EntryUtils.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/EntryUtils.java
Sat Mar 27 22:50:33 2010
@@ -0,0 +1,291 @@
+/*
+ *  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 org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.entry.BinaryValue;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
+import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimToLowerNormalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * Some common declaration used by the serverEntry tests.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryUtils
+{
+    /**
+     * A local Syntax class for tests
+     */
+    static class AT extends AttributeType
+    {
+        private static final long serialVersionUID = 0L;
+
+        protected AT( String oid )
+        {
+            super( oid );
+        }
+    }
+
+    public static MatchingRule matchingRuleFactory( String oid )
+    {
+        MatchingRule matchingRule = new MatchingRule( oid );
+        
+        return matchingRule;
+    }
+    /**
+     * A local MatchingRule class for tests
+     */
+    static class MR extends MatchingRule
+    {
+        private static final long serialVersionUID = 0L;
+
+        protected MR( String oid )
+        {
+            super( oid );
+        }
+    }
+
+
+    /**
+     * A local Syntax class used for the tests
+     */
+    public static LdapSyntax syntaxFactory( String oid, boolean humanReadable )
+    {
+        LdapSyntax ldapSyntax = new LdapSyntax( oid );
+        
+        ldapSyntax.setHumanReadable( humanReadable );
+        
+        return ldapSyntax;
+    }
+    static class S extends LdapSyntax
+    {
+        private static final long serialVersionUID = 0L;
+
+        public S( String oid, boolean humanReadible )
+        {
+            super( oid, "", humanReadible );
+        }
+    }
+
+    /* no protection*/ static AttributeType getCaseIgnoringAttributeNoNumbersType()
+    {
+        AttributeType attributeType = new AttributeType( "1.1.3.1" );
+        LdapSyntax syntax = new LdapSyntax( "1.1.1.1", "", true );
+
+        syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2.1" )
+        {
+            private static final long serialVersionUID = 0L;
+
+            public boolean isValidSyntax( Object value )
+            {
+                if ( !( value instanceof String ) )
+                {
+                    return false;
+                }
+
+                String strval = ( String ) value;
+                
+                for ( char c:strval.toCharArray() )
+                {
+                    if ( Character.isDigit( c ) )
+                    {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        } );
+        
+        MatchingRule matchingRule = new MatchingRule( "1.1.2.1" );
+        matchingRule.setSyntax( syntax );
+
+
+        matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid()
)
+        {
+            private static final long serialVersionUID = 0L;
+
+            public int compare( String o1, String o2 )
+            {
+                return ( o1 == null ? 
+                    ( o2 == null ? 0 : -1 ) :
+                    ( o2 == null ? 1 : o1.compareTo( o2 ) ) );
+            }
+
+            int getValue( String val )
+            {
+                if ( val.equals( "LOW" ) ) 
+                {
+                    return 0;
+                }
+                else if ( val.equals( "MEDIUM" ) ) 
+                {
+                    return 1;
+                }
+                else if ( val.equals( "HIGH" ) ) 
+                {
+                    return 2;
+                }
+                
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04473 ) );
+            }
+        } );
+        
+        Normalizer normalizer = new Normalizer( "1.1.1" )
+        {
+            private static final long serialVersionUID = 0L;
+
+            public Value<?> normalize( Value<?> value ) throws LdapException
+            {
+                if ( !value.isBinary() )
+                {
+                    return new ClientStringValue( value.getString().toLowerCase() );
+                }
+
+                throw new IllegalStateException( I18n.err( I18n.ERR_04474 ) );
+            }
+            
+            
+            public String normalize( String value ) throws LdapException
+            {
+                return value.toLowerCase();
+            }
+        };
+        
+        matchingRule.setNormalizer( normalizer );
+        
+        attributeType.setEquality( matchingRule );
+        attributeType.setSyntax( syntax );
+        
+        return attributeType;
+    }
+
+
+    /* no protection*/ static AttributeType getIA5StringAttributeType()
+    {
+        AttributeType attributeType = new AttributeType( "1.1" );
+        attributeType.addName( "1.1" );
+        LdapSyntax syntax = new LdapSyntax( "1.1.1", "", true );
+
+        syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2" )
+        {
+            private static final long serialVersionUID = 0L;
+
+            public boolean isValidSyntax( Object value )
+            {
+                return ((String)value == null) || (((String)value).length() < 7) ;
+            }
+        } );
+        
+        MatchingRule matchingRule = new MatchingRule( "1.1.2" );
+        matchingRule.setSyntax( syntax );
+
+
+        matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid()
)
+        {
+            private static final long serialVersionUID = 0L;
+
+            public int compare( String o1, String o2 )
+            {
+                return ( ( o1 == null ) ? 
+                    ( o2 == null ? 0 : -1 ) :
+                    ( o2 == null ? 1 : o1.compareTo( o2 ) ) );
+            }
+        } );
+        
+        matchingRule.setNormalizer( new DeepTrimToLowerNormalizer( matchingRule.getOid()
) );
+        
+        attributeType.setEquality( matchingRule );
+        attributeType.setSyntax( syntax );
+        
+        return attributeType;
+    }
+
+
+    /* No protection */ static AttributeType getBytesAttributeType()
+    {
+        AttributeType attributeType = new AttributeType( "1.2" );
+        LdapSyntax syntax = new LdapSyntax( "1.2.1", "", true );
+
+        syntax.setSyntaxChecker( new SyntaxChecker( "1.2.1" )
+        {
+            private static final long serialVersionUID = 0L;
+
+            public boolean isValidSyntax( Object value )
+            {
+                return ( value == null ) || ( ((byte[])value).length < 5 );
+            }
+        } );
+
+        MatchingRule matchingRule = new MatchingRule( "1.2.2" );
+        matchingRule.setSyntax( syntax );
+
+        matchingRule.setLdapComparator( new ByteArrayComparator( "1.2.2" ) );
+        
+        matchingRule.setNormalizer( new Normalizer( "1.1.1" )
+        {
+            // The serial UID
+            private static final long serialVersionUID = 1L;
+            
+            public Value<?> normalize( Value<?> value ) throws LdapException
+            {
+                if ( value.isBinary() )
+                {
+                    byte[] val = value.getBytes();
+                    
+                    // each byte will be changed to be > 0, and spaces will be trimmed
+                    byte[] newVal = new byte[ val.length ];
+                    
+                    int i = 0;
+                    
+                    for ( byte b:val )
+                    {
+                        newVal[i++] = (byte)(b & 0x007F); 
+                    }
+                    
+                    return new BinaryValue( StringTools.trim( newVal ) );
+                }
+
+                throw new IllegalStateException( I18n.err( I18n.ERR_04475 ) );
+            }
+
+            public String normalize( String value ) throws LdapException
+            {
+                throw new IllegalStateException( I18n.err( I18n.ERR_04475 ) );
+            }
+        } );
+        
+        attributeType.setEquality( matchingRule );
+        attributeType.setSyntax( syntax );
+
+        return attributeType;
+    }
+}

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttributeTest.java?rev=928296&r1=928295&r2=928296&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttributeTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttributeTest.java
Sat Mar 27 22:50:33 2010
@@ -37,6 +37,7 @@ import java.util.List;
 
 import javax.naming.directory.InvalidAttributeValueException;
 
+import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
@@ -55,7 +56,7 @@ import org.junit.Test;
 public class DefaultClientAttributeTest
 {
     private static final Value<String> NULL_STRING_VALUE = new ClientStringValue( null
);
-    private static final Value<byte[]> NULL_BINARY_VALUE = new ClientBinaryValue( null
);
+    private static final Value<byte[]> NULL_BINARY_VALUE = new BinaryValue( (byte[])null
);
     private static final byte[] BYTES1 = new byte[]{ 'a', 'b' };
     private static final byte[] BYTES2 = new byte[]{ 'b' };
     private static final byte[] BYTES3 = new byte[]{ 'c' };
@@ -66,10 +67,10 @@ public class DefaultClientAttributeTest
     private static final ClientStringValue STR_VALUE3 = new ClientStringValue( "c" );
     private static final ClientStringValue STR_VALUE4 = new ClientStringValue( "d" );
 
-    private static final ClientBinaryValue BIN_VALUE1 = new ClientBinaryValue( BYTES1 );
-    private static final ClientBinaryValue BIN_VALUE2 = new ClientBinaryValue( BYTES2 );
-    private static final ClientBinaryValue BIN_VALUE3 = new ClientBinaryValue( BYTES3 );
-    private static final ClientBinaryValue BIN_VALUE4 = new ClientBinaryValue( BYTES4 );
+    private static final BinaryValue BIN_VALUE1 = new BinaryValue( BYTES1 );
+    private static final BinaryValue BIN_VALUE2 = new BinaryValue( BYTES2 );
+    private static final BinaryValue BIN_VALUE3 = new BinaryValue( BYTES3 );
+    private static final BinaryValue BIN_VALUE4 = new BinaryValue( BYTES4 );
 
     
     
@@ -487,7 +488,7 @@ public class DefaultClientAttributeTest
         
         EntryAttribute attr2 = new DefaultClientAttribute( "test" );
         
-        nbAdded = attr2.add( new ClientBinaryValue( null ) );
+        nbAdded = attr2.add( new BinaryValue( (byte[])null ) );
         assertEquals( 1, nbAdded );
         assertFalse( attr2.isHR() );
         assertEquals( NULL_BINARY_VALUE, attr2.get() );
@@ -502,7 +503,7 @@ public class DefaultClientAttributeTest
         
         EntryAttribute attr4 = new DefaultClientAttribute( "test" );
         
-        nbAdded = attr4.add( new ClientBinaryValue( BYTES1 ), new ClientBinaryValue( BYTES2
) );
+        nbAdded = attr4.add( new BinaryValue( BYTES1 ), new BinaryValue( BYTES2 ) );
         assertEquals( 2, nbAdded );
         assertFalse( attr4.isHR() );
         assertTrue( attr4.contains( BYTES1 ) );
@@ -510,7 +511,7 @@ public class DefaultClientAttributeTest
         
         EntryAttribute attr5 = new DefaultClientAttribute( "test" );
         
-        nbAdded = attr5.add( new ClientStringValue( "c" ), new ClientBinaryValue( BYTES1
) );
+        nbAdded = attr5.add( new ClientStringValue( "c" ), new BinaryValue( BYTES1 ) );
         assertEquals( 2, nbAdded );
         assertTrue( attr5.isHR() );
         assertTrue( attr5.contains( "ab" ) );
@@ -518,7 +519,7 @@ public class DefaultClientAttributeTest
 
         EntryAttribute attr6 = new DefaultClientAttribute( "test" );
         
-        nbAdded = attr6.add( new ClientBinaryValue( BYTES1 ), new ClientStringValue( "c"
) );
+        nbAdded = attr6.add( new BinaryValue( BYTES1 ), new ClientStringValue( "c" ) );
         assertEquals( 2, nbAdded );
         assertFalse( attr6.isHR() );
         assertTrue( attr6.contains( BYTES1 ) );
@@ -526,7 +527,7 @@ public class DefaultClientAttributeTest
 
         EntryAttribute attr7 = new DefaultClientAttribute( "test" );
         
-        nbAdded = attr7.add( new ClientBinaryValue( null ), new ClientStringValue( "c" )
);
+        nbAdded = attr7.add( new BinaryValue( (byte[])null ), new ClientStringValue( "c"
) );
         assertEquals( 2, nbAdded );
         assertFalse( attr7.isHR() );
         assertTrue( attr7.contains( NULL_BINARY_VALUE ) );
@@ -534,7 +535,7 @@ public class DefaultClientAttributeTest
 
         EntryAttribute attr8 = new DefaultClientAttribute( "test" );
         
-        nbAdded = attr8.add( new ClientStringValue( null ), new ClientBinaryValue( BYTES1
) );
+        nbAdded = attr8.add( new ClientStringValue( null ), new BinaryValue( BYTES1 ) );
         assertEquals( 2, nbAdded );
         assertTrue( attr8.isHR() );
         assertTrue( attr8.contains( NULL_STRING_VALUE ) );

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntryTest.java?rev=928296&r1=928295&r2=928296&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntryTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntryTest.java
Sat Mar 27 22:50:33 2010
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Value;
@@ -411,7 +412,7 @@ public class DefaultClientEntryTest
         assertTrue( attributeSN.contains( value1 ) );
         assertTrue( attributeSN.contains( value2 ) );
         
-        Value<byte[]> value4 = new ClientBinaryValue( BYTES1 );
+        Value<byte[]> value4 = new BinaryValue( BYTES1 );
         entry.add( "l", value1, value4 );
         assertEquals( 3, entry.size() );
         EntryAttribute attributeL = entry.get( "l" );
@@ -583,10 +584,10 @@ public class DefaultClientEntryTest
         Value<String> strValue3 = new ClientStringValue( "test3" );
         Value<String> strNullValue = new ClientStringValue( null);
 
-        Value<byte[]> binValue1 = new ClientBinaryValue( BYTES1 );
-        Value<byte[]> binValue2 = new ClientBinaryValue( BYTES2 );
-        Value<byte[]> binValue3 = new ClientBinaryValue( BYTES3 );
-        Value<byte[]> binNullValue = new ClientBinaryValue( null );
+        Value<byte[]> binValue1 = new BinaryValue( BYTES1 );
+        Value<byte[]> binValue2 = new BinaryValue( BYTES2 );
+        Value<byte[]> binValue3 = new BinaryValue( BYTES3 );
+        Value<byte[]> binNullValue = new BinaryValue( (byte[])null );
 
         assertTrue( entry.contains( "CN", strValue1, strValue2, strNullValue ) );
         assertTrue( entry.contains( "userpassword", binValue1, binValue2, binNullValue )
);
@@ -943,10 +944,10 @@ public class DefaultClientEntryTest
         Value<String> strValueTop2 = new ClientStringValue( "top" );
         Value<String> strNullValue = new ClientStringValue( null);
 
-        Value<byte[]> binValue1 = new ClientBinaryValue( BYTES1 );
-        Value<byte[]> binValue2 = new ClientBinaryValue( BYTES2 );
-        Value<byte[]> binValue3 = new ClientBinaryValue( BYTES1 );
-        Value<byte[]> binNullValue = new ClientBinaryValue( null );
+        Value<byte[]> binValue1 = new BinaryValue( BYTES1 );
+        Value<byte[]> binValue2 = new BinaryValue( BYTES2 );
+        Value<byte[]> binValue3 = new BinaryValue( BYTES1 );
+        Value<byte[]> binNullValue = new BinaryValue( (byte[])null );
 
         try
         {
@@ -1139,10 +1140,10 @@ public class DefaultClientEntryTest
         Value<String> strValue3 = new ClientStringValue( "test3" );
         Value<String> strNullValue = new ClientStringValue( null);
 
-        Value<byte[]> binValue1 = new ClientBinaryValue( BYTES1 );
-        Value<byte[]> binValue2 = new ClientBinaryValue( BYTES2 );
-        Value<byte[]> binValue3 = new ClientBinaryValue( BYTES3 );
-        Value<byte[]> binNullValue = new ClientBinaryValue( null );
+        Value<byte[]> binValue1 = new BinaryValue( BYTES1 );
+        Value<byte[]> binValue2 = new BinaryValue( BYTES2 );
+        Value<byte[]> binValue3 = new BinaryValue( BYTES3 );
+        Value<byte[]> binNullValue = new BinaryValue( (byte[])null );
         
         assertTrue( entry.remove( "cn", strValue1, strNullValue ) );
         assertTrue( entry.contains( "cn", strValue2 ) );
@@ -1239,9 +1240,9 @@ public class DefaultClientEntryTest
         Value<String> strValuePerson = new ClientStringValue( "person" );
         Value<String> strNullValue = new ClientStringValue( null);
 
-        Value<byte[]> binValue1 = new ClientBinaryValue( BYTES1 );
-        Value<byte[]> binValue2 = new ClientBinaryValue( BYTES2 );
-        Value<byte[]> binNullValue = new ClientBinaryValue( null );
+        Value<byte[]> binValue1 = new BinaryValue( BYTES1 );
+        Value<byte[]> binValue2 = new BinaryValue( BYTES2 );
+        Value<byte[]> binNullValue = new BinaryValue( (byte[])null );
         
         entry.put( "ObjectClass", strValueTop, strValuePerson, strNullValue );
         entry.put( "UserPassword", binValue1, binValue2, binNullValue );

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/normalizers/BooleanNormalizerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/normalizers/BooleanNormalizerTest.java?rev=928296&r1=928295&r2=928296&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/normalizers/BooleanNormalizerTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/normalizers/BooleanNormalizerTest.java
Sat Mar 27 22:50:33 2010
@@ -20,8 +20,8 @@
 package org.apache.directory.shared.ldap.schema.normalizers;
 
 
+import org.apache.directory.shared.ldap.entry.BinaryValue;
 import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
 import org.apache.directory.shared.ldap.schema.normalizers.BooleanNormalizer;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
@@ -66,8 +66,8 @@ public class BooleanNormalizerTest
     @Test
     public void testNormalizeByteValue() throws Exception
     {
-        assertEquals( "TRUE", normalizer.normalize( new ClientBinaryValue( "tRuE".getBytes()
) ).getString() );
-        assertEquals( "TRUE", normalizer.normalize( new ClientBinaryValue( "true".getBytes()
) ).getString() );
+        assertEquals( "TRUE", normalizer.normalize( new BinaryValue( "tRuE".getBytes() )
).getString() );
+        assertEquals( "TRUE", normalizer.normalize( new BinaryValue( "true".getBytes() )
).getString() );
     }
 
 }



Mime
View raw message