directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r634271 - in /directory/apacheds/branches/bigbang/core-entry/src: main/java/org/apache/directory/server/core/entry/ test/java/org/apache/directory/server/core/entry/
Date Thu, 06 Mar 2008 14:07:15 GMT
Author: elecharny
Date: Thu Mar  6 06:07:13 2008
New Revision: 634271

URL: http://svn.apache.org/viewvc?rev=634271&view=rev
Log:
Added some tests for ServerStringValue.
Fixed some minor issues in the API
Added the hashCode() method into ServerStringValue
Removed the ServerValue class
Removed the ServerStreamedValueTest class
Changed one AT OID in TestServerEntryUtils

Removed:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
    directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStreamedValueTest.java
Modified:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java
    directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=634271&r1=634270&r2=634271&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
Thu Mar  6 06:07:13 2008
@@ -331,7 +331,7 @@
      * change. Syntax checks only result on the first check, and when the wrapped
      * value changes.
      *
-     * @see ServerValue#isValid()
+     * @see Value<T>#isValid()
      */
     public final boolean isValid()
     {
@@ -366,11 +366,11 @@
 
     /**
      *
-     * @see ServerValue#compareTo(ServerValue)
+     * @see Value<T>#compareTo(ServerValue)
      * @throws IllegalStateException on failures to extract the comparator, or the
      * normalizers needed to perform the required comparisons based on the schema
      */
-    public int compareTo( ServerValue<byte[]> value )
+    public int compareTo( Value<byte[]> value )
     {
         if ( isNull() )
         {

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=634271&r1=634270&r2=634271&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
Thu Mar  6 06:07:13 2008
@@ -222,6 +222,7 @@
     {
         if ( isNull() )
         {
+            normalized = true;
             return null;
         }
 
@@ -250,7 +251,7 @@
      * change. Syntax checks only result on the first check, and when the wrapped
      * value changes.
      *
-     * @see ServerValue#isValid()
+     * @see Value<T>#isValid()
      */
     public final boolean isValid()
     {
@@ -275,7 +276,7 @@
 
 
     /**
-     * @see ServerValue#compareTo(ServerValue)
+     * @see Value<T>#compareTo(ServerValue)
      * @throws IllegalStateException on failures to extract the comparator, or the
      * normalizers needed to perform the required comparisons based on the schema
      */
@@ -382,6 +383,11 @@
      *
      * This equals implementation overrides the StringValue implementation which
      * is not schema aware.
+     * 
+     * Two ServerStringValues are equal if they have the same AttributeType,
+     * they are both null, their value are equal or their normalized value 
+     * are equal. If the AttributeType has a comparator, we use it to
+     * compare both values.
      * @throws IllegalStateException on failures to extract the comparator, or the
      * normalizers needed to perform the required comparisons based on the schema
      */
@@ -399,6 +405,11 @@
 
         ServerStringValue other = ( ServerStringValue ) obj;
         
+        if ( !attributeType.equals( other.attributeType ) )
+        {
+            return false;
+        }
+        
         if ( isNull() )
         {
             return other.isNull();
@@ -406,8 +417,8 @@
 
         // Shortcut : compare the values without normalization
         // If they are equal, we may avoid a normalization.
-        // Note : if two values are equals, then their normalized
-        // value is equal too.
+        // Note : if two values are equal, then their normalized
+        // value are equal too if their attributeType are equal. 
         if ( get().equals( other.get() ) )
         {
             return true;
@@ -488,6 +499,33 @@
     }
 
 
+    /**
+     * Implement the hashCode method.
+     * 
+     * @see Object#hashCode()
+     * @throws IllegalStateException on failures to extract the comparator, or the
+     * normalizers needed to perform the required comparisons based on the schema
+     */
+    public int hashCode()
+    {
+        // return the OID hashcode if the value is null. 
+        if ( isNull() )
+        {
+            return attributeType.getOid().hashCode();
+        }
+
+        // If the normalized value is null, will default to wrapped
+        // which cannot be null at this point.
+        int h = 17;
+        h = h*37 + getNormalizedValue().hashCode();
+        
+        // Add the OID hashcode
+        h = h*37 + attributeType.getOid().hashCode();
+        
+        return h;
+    }
+
+    
     /**
      * Gets a comparator using getMatchingRule() to resolve the matching
      * that the comparator is extracted from.

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java?rev=634271&r1=634270&r2=634271&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java
Thu Mar  6 06:07:13 2008
@@ -352,15 +352,15 @@
 
     /* No protection */ static AttributeType getBytesAttributeType()
     {
-        AT at = new AT( "1.1" );
+        AT at = new AT( "1.2" );
 
-        S s = new S( "1.1.1", true );
+        S s = new S( "1.2.1", true );
 
         s.setSyntaxChecker( new SyntaxChecker()
         {
             public String getSyntaxOid()
             {
-                return "1.1.1";
+                return "1.2.1";
             }
             public boolean isValidSyntax( Object value )
             {
@@ -376,7 +376,7 @@
             }
         } );
 
-        final MR mr = new MR( "1.1.2" );
+        final MR mr = new MR( "1.2.2" );
         mr.syntax = s;
         mr.comparator = new Comparator<byte[]>()
         {

Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java?rev=634271&r1=634270&r2=634271&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerStringValueTest.java
Thu Mar  6 06:07:13 2008
@@ -21,6 +21,7 @@
 
 
 import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
 import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
@@ -46,6 +47,7 @@
 import jdbm.helper.StringComparator;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertFalse;
@@ -91,63 +93,136 @@
         at.setSyntax( s );
     }
     
-
     /**
-     * Test the constructor with bad AttributeType
+     * Test the constructor with a null value
      */
-    @Test public void testBadConstructor()
+    @Test 
+    public void testServerStringValueNullValue()
     {
-        try
-        {
-            new ServerStringValue( null );
-            fail();
-        }
-        catch ( AssertionError ae )
-        {
-            // Expected...
-        }
+        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
         
-        // create a AT without any syntax
-        AttributeType at = new TestServerEntryUtils.AT( "1.1.3.1" );
+        ServerStringValue value = new ServerStringValue( at, null );
         
-        try
-        {
-            new ServerStringValue( at );
-            fail();
-        }
-        catch ( AssertionError ae )
-        {
-            // Expected...
-        }
+        assertNull( value.get() );
+        assertTrue( value.isNull() );
     }
+    
+    
+    /**
+     * Test the getNormalizedValue method
+     */
+    @Test public void testGetNormalizedValue() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
+        
+        ServerStringValue value = new ServerStringValue( at, null );
+        
+        assertFalse( value.isNormalized() );
+        assertNull( value.getNormalizedValue() );
+        assertTrue( value.isNormalized() );
+
+        value.set( "" );
+        assertFalse( value.isNormalized() );
+        assertEquals( "", value.getNormalizedValue() );
+        assertTrue( value.isNormalized() );
 
+        value.set( "TEST" );
+        assertFalse( value.isNormalized() );
+        assertEquals( "test", value.getNormalizedValue() );
+        assertTrue( value.isNormalized() );
+    }
+    
 
     /**
-     * Test the constructor with a null value
+     * Test the isValid method
+     * 
+     * The SyntaxChecker does not accept values longer than 5 chars.
      */
-    @Test public void testNullValue()
+    @Test public void testIsValid() throws NamingException
     {
         AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
         
         ServerStringValue value = new ServerStringValue( at, null );
+        assertTrue( value.isValid() );
+
+        value.set( "" );
+        assertTrue( value.isValid() );
+
+        value.set( "TEST" );
+        assertTrue( value.isValid() );
+
+        value.set( "testlong" );
+        assertFalse( value.isValid() );
+    }
+    
+    
+    /**
+     * Test the normalize method
+     */
+    @Test
+    public void testNormalize() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
+        ServerStringValue ssv = new ServerStringValue( at );
+
+        ssv.normalize();
+        assertEquals( null, ssv.getNormalizedValue() );
         
-        assertNull( value.get() );
-        assertTrue( value.isNull() );
+        ssv.set( "" );
+        ssv.normalize();
+        assertEquals( "", ssv.getNormalizedValue() );
+
+        ssv.set(  "  This is    a   TEST  " );
+        ssv.normalize();
+        assertEquals( "this is a test", ssv.getNormalizedValue() );
     }
     
+
+    /**
+     * Test the instanceOf method
+     */
+    @Test
+    public void testInstanceOf() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
+        ServerStringValue ssv = new ServerStringValue( at );
+        
+        assertTrue( ssv.instanceOf( at ) );
+        
+        at = TestServerEntryUtils.getBytesAttributeType();
+        
+        assertFalse( ssv.instanceOf( at ) );
+    }    
+    
+
+    /**
+     * Test the getAttributeType method
+     */
+    @Test
+    public void testgetAttributeType() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
+        ServerStringValue ssv = new ServerStringValue( at );
+        
+        assertEquals( at, ssv.getAttributeType() );
+    }    
+
     
     /**
      * Test the equals method
      */
     @Test public void testEquals()
     {
-        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
+        AttributeType at1 = TestServerEntryUtils.getIA5StringAttributeType();
+        AttributeType at2 = TestServerEntryUtils.getBytesAttributeType();
         
-        ServerStringValue value1 = new ServerStringValue( at, "test" );
-        ServerStringValue value2 = new ServerStringValue( at, "test" );
-        ServerStringValue value3 = new ServerStringValue( at, "TEST" );
-        ServerStringValue value4 = new ServerStringValue( at, "tes" );
-        ServerStringValue value5 = new ServerStringValue( at, null );
+        ServerStringValue value1 = new ServerStringValue( at1, "test" );
+        ServerStringValue value2 = new ServerStringValue( at1, "test" );
+        ServerStringValue value3 = new ServerStringValue( at1, "TEST" );
+        ServerStringValue value4 = new ServerStringValue( at1, "tes" );
+        ServerStringValue value5 = new ServerStringValue( at1, null );
+        ServerBinaryValue valueBytes = new ServerBinaryValue( at2, new byte[]{0x01} );
+        ServerStringValue valueString = new ServerStringValue( at, "test" );
         
         assertTrue( value1.equals( value1 ) );
         assertTrue( value1.equals( value2 ) );
@@ -156,76 +231,133 @@
         assertFalse( value1.equals( value5 ) );
         assertFalse( value1.equals( "test" ) );
         assertFalse( value1.equals( null ) );
+        
+        assertFalse( value1.equals( valueString ) );
+        assertFalse( value1.equals( valueBytes ) );
     }
 
     
-    /**
-     * Test the getNormalized method
-     * TODO testNormalized.
-     *
-     */
-    @Test public void testGetNormalized() throws NamingException
-    {
-        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
-        
-        ServerStringValue value = new ServerStringValue( at, "TEST" );
-        
-        assertEquals( "test", value.getNormalizedValue() );
-
-        value = new ServerStringValue( at, null );
-        
-        assertNull( value.getNormalizedValue() );
-    }
+    
+    
+    
+    
+    
+    
     
     
     /**
-     * Test the isValid method
-     * 
-     * The SyntaxChecker does not accept values longer than 5 chars.
+     * Test the constructor with bad AttributeType
      */
-    @Test public void testIsValid() throws NamingException
+    @Test public void testBadConstructor()
     {
-        AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
-        
-        ServerStringValue value = new ServerStringValue( at, "test" );
+        try
+        {
+            new ServerStringValue( null );
+            fail();
+        }
+        catch ( AssertionError ae )
+        {
+            // Expected...
+        }
         
-        assertTrue( value.isValid() );
-
-        value = new ServerStringValue( at, "testlong" );
+        // create a AT without any syntax
+        AttributeType at = new TestServerEntryUtils.AT( "1.1.3.1" );
         
-        assertFalse( value.isValid() );
+        try
+        {
+            new ServerStringValue( at );
+            fail();
+        }
+        catch ( AssertionError ae )
+        {
+            // Expected...
+        }
     }
-    
-    
+
+
     /**
      * Tests to make sure the hashCode method is working properly.
      * @throws Exception on errors
      */
-    @Test public void testHashCodeValidEquals() throws Exception
+    @Test public void testHashCode() throws Exception
     {
-        AttributeType at = TestServerEntryUtils.getCaseIgnoringAttributeNoNumbersType();
-        ServerStringValue v0 = new ServerStringValue( at, "Alex" );
-        ServerStringValue v1 = new ServerStringValue( at, "ALEX" );
-        ServerStringValue v2 = new ServerStringValue( at, "alex" );
-        assertEquals( v0.hashCode(), "alex".hashCode() );
-        assertEquals( v1.hashCode(), "alex".hashCode() );
-        assertEquals( v2.hashCode(), "alex".hashCode() );
+        AttributeType at1 = TestServerEntryUtils.getCaseIgnoringAttributeNoNumbersType();
+        ServerStringValue v0 = new ServerStringValue( at1, "Alex" );
+        ServerStringValue v1 = new ServerStringValue( at1, "ALEX" );
+        ServerStringValue v2 = new ServerStringValue( at1, "alex" );
+        
+        assertEquals( v0.hashCode(), v1.hashCode() );
+        assertEquals( v0.hashCode(), v2.hashCode() );
+        assertEquals( v1.hashCode(), v2.hashCode() );
+        
         assertEquals( v0, v1 );
         assertEquals( v0, v2 );
         assertEquals( v1, v2 );
+        
         assertTrue( v0.isValid() );
         assertTrue( v1.isValid() );
         assertTrue( v2.isValid() );
 
-        ServerStringValue v3 = new ServerStringValue( at, "Timber" );
-        assertFalse( v3.equals( v0 ) );
-        assertFalse( v3.equals( v1 ) );
-        assertFalse( v3.equals( v2 ) );
+        ServerStringValue v3 = new ServerStringValue( at1, "Timber" );
+        
         assertTrue( v3.isValid() );
+        assertNotSame( v0.hashCode(), v3.hashCode() );
+
+        ServerStringValue v4 = new ServerStringValue( at, "Alex" );
+        
+        assertNotSame( v0.hashCode(), v4.hashCode() );
+        
+    }
+    
+    
+    /**
+     * Test the compareTo method
+     */
+    @Test
+    public void testCompareTo()
+    {
+        AttributeType at1 = TestServerEntryUtils.getCaseIgnoringAttributeNoNumbersType();
+        ServerStringValue v0 = new ServerStringValue( at1, "Alex" );
+        ServerStringValue v1 = new ServerStringValue( at1, "ALEX" );
+        
+        assertEquals( 0, v0.compareTo( v1 ) );
+        assertEquals( 0, v1.compareTo( v0 ) );
+
+        ServerStringValue v2 = new ServerStringValue( at1, null );
+        
+        assertEquals( 1, v0.compareTo( v2 ) );
+        assertEquals( -1, v2.compareTo( v0 ) );
+    }
+
 
-        ServerStringValue v4 = new ServerStringValue( at, "Timber123" );
-        assertFalse( v4.isValid() );
+    /**
+     * Test the clone method
+     */
+    @Test
+    public void testClone() throws NamingException
+    {
+        AttributeType at1 = TestServerEntryUtils.getCaseIgnoringAttributeNoNumbersType();
+        ServerStringValue ssv = new ServerStringValue( at1, "Test" );
+        
+        ServerStringValue ssv1 = (ServerStringValue)ssv.clone();
+        
+        assertEquals( ssv, ssv1 );
+        
+        ssv.set( "" );
+        
+        assertNotSame( ssv, ssv1 );
+        assertEquals( "", ssv.get() );
+        
+        ssv.set(  "  This is    a   TEST  " );
+        ssv1 = (ServerStringValue)ssv.clone();
+        
+        assertEquals( ssv, ssv1 );
+        
+        ssv.normalize();
+        
+        assertNotSame( ssv, ssv1 );
     }
+    
 
 
     /**



Mime
View raw message