directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r634438 - 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 22:46:40 GMT
Author: elecharny
Date: Thu Mar  6 14:46:38 2008
New Revision: 634438

URL: http://svn.apache.org/viewvc?rev=634438&view=rev
Log:
Added some more tests for ServerBinaryValues
Fixed some typoes in javadoc

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/TestServerEntryUtils.java
    directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.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=634438&r1=634437&r2=634438&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 14:46:38 2008
@@ -499,6 +499,11 @@
 
         ServerBinaryValue other = ( ServerBinaryValue ) obj;
         
+        if ( !attributeType.equals( other.attributeType ) )
+        {
+            return false;
+        }
+        
         if ( isNull() )
         {
             return other.isNull();

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=634438&r1=634437&r2=634438&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 14:46:38 2008
@@ -364,7 +364,7 @@
             }
             public boolean isValidSyntax( Object value )
             {
-                return ((byte[])value).length < 5 ;
+                return ( value == null ) || ( ((byte[])value).length < 5 );
             }
 
             public void assertSyntax( Object value ) throws NamingException

Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java?rev=634438&r1=634437&r2=634438&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerBinaryValueTest.java
Thu Mar  6 14:46:38 2008
@@ -38,6 +38,7 @@
 import java.util.Arrays;
 
 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;
@@ -63,6 +64,9 @@
     static private TestServerEntryUtils.AT at;
     static private TestServerEntryUtils.MR mr;
     
+    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};
+
     /**
      * Initialize an AttributeType and the associated MatchingRule 
      * and Syntax
@@ -139,7 +143,7 @@
     /**
      * Test the constructor with a null value
      */
-    @Test public void testNullValue()
+    @Test public void testServerBinaryValueNullValue()
     {
         AttributeType at = TestServerEntryUtils.getBytesAttributeType();
         
@@ -151,17 +155,96 @@
     
     
     /**
+     * Test the constructor with an empty value
+     */
+    @Test public void testServerBinaryValueEmptyValue()
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        
+        ServerBinaryValue value = new ServerBinaryValue( at, StringTools.EMPTY_BYTES );
+        
+        assertEquals( StringTools.EMPTY_BYTES, value.getReference() );
+        assertFalse( value.isNull() );
+    }
+    
+    
+    /**
+     * Test the constructor with a value
+     */
+    @Test public void testServerBinaryValueNoValue()
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        byte[] val = new byte[]{0x01};
+        ServerBinaryValue value = new ServerBinaryValue( at );
+        
+        value.set( val );
+        assertTrue( Arrays.equals( val, value.getReference() ) );
+        assertFalse( value.isNull() );
+        assertTrue( Arrays.equals( val, value.getCopy() ) );
+    }
+    
+    
+    /**
+     * Test the constructor with a value
+     */
+    @Test public void testServerBinaryValue()
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        byte[] val = new byte[]{0x01};
+        ServerBinaryValue value = new ServerBinaryValue( at, val );
+        
+        assertTrue( Arrays.equals( val, value.getReference() ) );
+        assertFalse( value.isNull() );
+        assertTrue( Arrays.equals( val, value.getCopy() ) );
+    }
+    
+    
+    /**
+     * Test the clone method
+     */
+    @Test
+    public void testClone() throws NamingException
+    {
+        AttributeType at1 = TestServerEntryUtils.getBytesAttributeType();
+        ServerBinaryValue sbv = new ServerBinaryValue( at1, null );
+        
+        ServerBinaryValue sbv1 = (ServerBinaryValue)sbv.clone();
+        
+        assertEquals( sbv, sbv1 );
+        
+        sbv.set( StringTools.EMPTY_BYTES );
+        
+        assertNotSame( sbv, sbv1 );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, sbv.get() ) );
+        
+        sbv.set(  BYTES2 );
+        sbv1 = (ServerBinaryValue)sbv.clone();
+        
+        assertEquals( sbv, sbv1 );
+        
+        sbv.normalize();
+        
+        // Even if we didn't normalized sbv2, it should be equal to sbv,
+        // as if they have the same AT, and the same value, they are equal.
+        assertEquals( sbv, sbv1 );
+    }
+    
+
+    /**
      * Test the equals method
      */
     @Test public void testEquals()
     {
-        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        AttributeType at1 = TestServerEntryUtils.getBytesAttributeType();
         
-        ServerBinaryValue value1 = new ServerBinaryValue( at, new byte[]{0x01, (byte)0x02}
);
-        ServerBinaryValue value2 = new ServerBinaryValue( at, new byte[]{0x01, (byte)0x02}
);
-        ServerBinaryValue value3 = new ServerBinaryValue( at, new byte[]{0x01, (byte)0x82}
);
-        ServerBinaryValue value4 = new ServerBinaryValue( at, new byte[]{0x01} );
-        ServerBinaryValue value5 = new ServerBinaryValue( at, null );
+        ServerBinaryValue value1 = new ServerBinaryValue( at1, new byte[]{0x01, (byte)0x02}
);
+        ServerBinaryValue value2 = new ServerBinaryValue( at1, new byte[]{0x01, (byte)0x02}
);
+        ServerBinaryValue value3 = new ServerBinaryValue( at1, new byte[]{0x01, (byte)0x82}
);
+        ServerBinaryValue value4 = new ServerBinaryValue( at1, new byte[]{0x01} );
+        ServerBinaryValue value5 = new ServerBinaryValue( at1, null );
+        ServerBinaryValue value6 = new ServerBinaryValue( at, new byte[]{0x01, 0x02} );
+        ServerStringValue value7 = new ServerStringValue( TestServerEntryUtils.getIA5StringAttributeType(),

+            "test" );
         
         assertTrue( value1.equals( value1 ) );
         assertTrue( value1.equals( value2 ) );
@@ -170,30 +253,80 @@
         assertFalse( value1.equals( value5 ) );
         assertFalse( value1.equals( "test" ) );
         assertFalse( value1.equals( null ) );
+        
+        assertFalse( value1.equals( value6 ) );
+        assertFalse( value1.equals( value7 ) );
     }
 
     
     /**
-     * Test the getNormalized method
-     * TODO testNormalized.
-     *
+     * Test the getNormalizedValue method
      */
-    @Test public void testGetNormalized() throws NamingException
+    @Test public void testGetNormalizedValue() throws NamingException
     {
         AttributeType at = TestServerEntryUtils.getBytesAttributeType();
         
-        ServerBinaryValue value = new ServerBinaryValue( at, new byte[]{0x01, (byte)0x82}
);
+        ServerBinaryValue value = new ServerBinaryValue( at, null );
+        assertNull( value.getNormalizedValue() );
+
+        value = new ServerBinaryValue( at, StringTools.EMPTY_BYTES );
+        assertTrue( Arrays.equals(  StringTools.EMPTY_BYTES, value.getNormalizedValue() )
);
+
+        value = new ServerBinaryValue( at, BYTES2 );
+        assertTrue( Arrays.equals( BYTES1, value.getNormalizedValue() ) );
+    }
+    
+    
+    /**
+     * Test the getNormalizedValue method
+     */
+    @Test public void testGetNormalizedValueCopy() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
         
-        assertTrue( Arrays.equals( new byte[]{0x01, (byte)0x02}, value.getNormalizedValueReference()
) );
-        assertTrue( Arrays.equals( new byte[]{0x01, (byte)0x02}, value.getNormalizedValueCopy()
) );
+        ServerBinaryValue value = new ServerBinaryValue( at, null );
+        assertNull( value.getNormalizedValueCopy() );
 
-        value = new ServerBinaryValue( at, null );
+        value = new ServerBinaryValue( at, StringTools.EMPTY_BYTES );
+        assertTrue( Arrays.equals(  StringTools.EMPTY_BYTES, value.getNormalizedValueCopy()
) );
+
+        value = new ServerBinaryValue( at, BYTES2 );
+        assertTrue( Arrays.equals( BYTES1, value.getNormalizedValueCopy() ) );
+    }
+    
+    
+    /**
+     * Test the getNormalizedValue method
+     */
+    @Test public void testGetNormalizedValueReference() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
         
+        ServerBinaryValue value = new ServerBinaryValue( at, null );
         assertNull( value.getNormalizedValueReference() );
+
+        value = new ServerBinaryValue( at, StringTools.EMPTY_BYTES );
+        assertTrue( Arrays.equals(  StringTools.EMPTY_BYTES, value.getNormalizedValueReference()
) );
+
+        value = new ServerBinaryValue( at, BYTES2 );
+        assertTrue( Arrays.equals( BYTES1, value.getNormalizedValueReference() ) );
     }
     
     
     /**
+     * Test the getAttributeType method
+     */
+    @Test
+    public void testgetAttributeType() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        ServerBinaryValue sbv = new ServerBinaryValue( at );
+        
+        assertEquals( at, sbv.getAttributeType() );
+    }    
+
+    
+    /**
      * Test the isValid method
      * 
      * The SyntaxChecker does not accept values longer than 5 chars.
@@ -202,12 +335,16 @@
     {
         AttributeType at = TestServerEntryUtils.getBytesAttributeType();
         
-        ServerBinaryValue value = new ServerBinaryValue( at, new byte[]{0x01, 0x02} );
+        ServerBinaryValue value = new ServerBinaryValue( at, null );
+        assertTrue( value.isValid() );
         
+        value = new ServerBinaryValue( at, StringTools.EMPTY_BYTES );
+        assertTrue( value.isValid() );
+
+        value = new ServerBinaryValue( at, new byte[]{0x01, 0x02} );
         assertTrue( value.isValid() );
 
         value = new ServerBinaryValue( at, new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}
);
-        
         assertFalse( value.isValid() );
     }
     
@@ -216,7 +353,7 @@
      * 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.getBytesAttributeType();
         ServerBinaryValue v0 = new ServerBinaryValue( at, new byte[]{0x01, 0x02} );
@@ -239,6 +376,90 @@
         assertTrue( v3.isValid() );
     }
 
+
+    /**
+     * Test the same method
+     */
+    @Test
+    public void testSame() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        ServerBinaryValue sbv = new ServerBinaryValue( at );
+
+        sbv.normalize();
+        assertTrue( sbv.isSame() );
+        
+        sbv.set( StringTools.EMPTY_BYTES );
+        sbv.normalize();
+        assertTrue( sbv.isSame() );
+
+        sbv.set( BYTES1 );
+        sbv.normalize();
+        assertTrue( sbv.isSame() );
+
+        sbv.set( BYTES2 );
+        sbv.normalize();
+        assertFalse( sbv.isSame() );
+    }
+    
+    
+    /**
+     * Test the instanceOf method
+     */
+    @Test
+    public void testInstanceOf() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        ServerBinaryValue sbv = new ServerBinaryValue( at );
+        
+        assertTrue( sbv.instanceOf( at ) );
+        
+        at = TestServerEntryUtils.getIA5StringAttributeType();
+        
+        assertFalse( sbv.instanceOf( at ) );
+    }    
+    
+
+    /**
+     * Test the normalize method
+     */
+    @Test
+    public void testNormalize() throws NamingException
+    {
+        AttributeType at = TestServerEntryUtils.getBytesAttributeType();
+        ServerBinaryValue sbv = new ServerBinaryValue( at );
+
+        sbv.normalize();
+        assertEquals( null, sbv.getNormalizedValue() );
+        
+        sbv.set( StringTools.EMPTY_BYTES );
+        sbv.normalize();
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, sbv.getNormalizedValue() ) );
+
+        sbv.set( BYTES2 );
+        sbv.normalize();
+        assertTrue( Arrays.equals( BYTES1, sbv.getNormalizedValue() ) );
+    }
+    
+
+    /**
+     * Test the compareTo method
+     */
+    @Test
+    public void testCompareTo()
+    {
+        AttributeType at1 = TestServerEntryUtils.getBytesAttributeType();
+        ServerBinaryValue v0 = new ServerBinaryValue( at1, BYTES1 );
+        ServerBinaryValue v1 = new ServerBinaryValue( at1, BYTES2 );
+        
+        assertEquals( 0, v0.compareTo( v1 ) );
+        assertEquals( 0, v1.compareTo( v0 ) );
+
+        ServerBinaryValue v2 = new ServerBinaryValue( at1, null );
+        
+        assertEquals( 1, v0.compareTo( v2 ) );
+        assertEquals( -1, v2.compareTo( v0 ) );
+    }
 
 
     /**

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=634438&r1=634437&r2=634438&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 14:46:38 2008
@@ -21,7 +21,6 @@
 
 
 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;
@@ -306,7 +305,6 @@
         ServerStringValue v4 = new ServerStringValue( at, "Alex" );
         
         assertNotSame( v0.hashCode(), v4.hashCode() );
-        
     }
     
     
@@ -355,10 +353,9 @@
         
         ssv.normalize();
         
-        assertNotSame( ssv, ssv1 );
+        assertEquals( ssv, ssv1 );
     }
     
-
 
     /**
      * Presumes an attribute which constrains it's values to some constant



Mime
View raw message