directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1073323 - in /directory/shared/trunk: integ/src/test/java/org/apache/directory/shared/ldap/name/ ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/ ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/ ldap-mo...
Date Tue, 22 Feb 2011 13:44:08 GMT
Author: elecharny
Date: Tue Feb 22 13:44:07 2011
New Revision: 1073323

URL: http://svn.apache.org/viewvc?rev=1073323&view=rev
Log:
o Injected the SchemaManager into the AV class
o Added some tests for schema aware AVAs
o Made the Ava class final
o Modified the Ava constructor to be package visible only when they are not schema aware
o The Ava.toString() method returns the UP form instead of the norm form

Added:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
Modified:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/MultiThreadedTest.java
    directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
    directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
    directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java

Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java?rev=1073323&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
(added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/AvaTest.java
Tue Feb 22 13:44:07 2011
@@ -0,0 +1,420 @@
+/*
+ *  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.name;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.name.Ava;
+import org.apache.directory.shared.ldap.model.name.AvaSerializer;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.util.Strings;
+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;
+
+
+/**
+ * Test the class AttributeTypeAndValue
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class AvaTest
+{
+
+    private static SchemaManager schemaManager;
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+    
+    /**
+     * Test a null AttributeTypeAndValue
+     */
+    @Test
+    public void testAttributeTypeAndValueNull()
+    {
+        Ava atav = new Ava( schemaManager );
+        assertEquals( "", atav.toString() );
+        assertEquals( "", atav.getUpName() );
+    }
+
+
+    /**
+     * Test a null type for an AttributeTypeAndValue
+     */
+    @Test
+    public void testAttributeTypeAndValueNullType() throws LdapException
+    {
+        try
+        {
+            new Ava( schemaManager, null, (String)null );
+            fail();
+        }
+        catch ( LdapException ine )
+        {
+            assertTrue( true );
+        }
+
+    }
+
+    /**
+     * Test an invalid type for an AttributeTypeAndValue
+     */
+    @Test
+    public void testAttributeTypeAndValueInvalidType() throws LdapException
+    {
+        try
+        {
+            new Ava( schemaManager, "  ", (String)null );
+            fail();
+        }
+        catch ( LdapException ine )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test a valid type for an AttributeTypeAndValue
+     */
+    @Test
+    public void testAttributeTypeAndValueValidType() throws LdapException
+    {
+        Ava atav = new Ava( schemaManager, "CN", (String)null );
+        assertEquals( "CN=", atav.toString() );
+        assertEquals( "2.5.4.3=", atav.getNormName() );
+        assertEquals( "CN=", atav.getUpName() );
+        
+        atav = new Ava( schemaManager, "  CN  ", (String)null );
+        assertEquals( "  CN  =", atav.toString() );
+        assertEquals( "2.5.4.3=", atav.getNormName() );
+        assertEquals( "  CN  =", atav.getUpName() );
+
+        atav = new Ava( schemaManager, "cn", (String)null );
+        assertEquals( "cn=", atav.toString() );
+        assertEquals( "2.5.4.3=", atav.getNormName() );
+        assertEquals( "cn=", atav.getUpName() );
+        
+        atav = new Ava( schemaManager, "  cn  ", (String)null );
+        assertEquals( "  cn  =", atav.toString() );
+        assertEquals( "2.5.4.3=", atav.getNormName() );
+        assertEquals( "  cn  =", atav.getUpName() );
+    }
+
+    /**
+     * test an empty AttributeTypeAndValue
+     */
+    @Test
+    public void testLdapRDNEmpty()
+    {
+        try
+        {
+            new Ava( schemaManager, "", "" );
+            fail( "Should not occurs ... " );
+        }
+        catch ( LdapException ine )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * test a simple AttributeTypeAndValue : a = b
+     */
+    @Test
+    public void testLdapRDNSimple() throws LdapException
+    {
+        Ava atav = new Ava( schemaManager, "cn", "b" );
+        assertEquals( "cn=b", atav.toString() );
+        assertEquals( "2.5.4.3=b", atav.getNormName() );
+        assertEquals( "cn=b", atav.getUpName() );
+    }
+
+
+    /**
+     * Compares two equals atavs
+     */
+    @Test
+    public void testCompareToEquals() throws LdapException
+    {
+        Ava atav1 = new Ava( schemaManager, "cn", "b" );
+        Ava atav2 = new Ava( schemaManager, "cn", "b" );
+
+        assertEquals( 0, atav1.compareTo( atav2 ) );
+    }
+
+
+    /**
+     * Compares two equals atavs but with a type in different case
+     */
+    @Test
+    public void testCompareToEqualsCase() throws LdapException
+    {
+        Ava atav1 = new Ava( schemaManager, "cn", "b" );
+        Ava atav2 = new Ava( schemaManager, "CN", "b" );
+
+        assertEquals( 0, atav1.compareTo( atav2 ) );
+    }
+
+
+    /** Serialization tests ------------------------------------------------- */
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testStringAtavSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "CN", "Test" );
+
+        atav.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        out.writeObject( atav );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = (Ava)in.readObject();
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    @Test
+    public void testBinaryAtavSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        byte[] normValue = Strings.getBytesUtf8("Test");
+
+        Ava atav = new Ava( schemaManager, "JpegPhoto", normValue );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        out.writeObject( atav );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = (Ava)in.readObject();
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testNullAtavSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            out.writeObject( atav );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test
+    public void testNullUpValueSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "uid", (String)null );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            out.writeObject( atav );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            String message = ioe.getMessage();
+            assertEquals( "Cannot serialize an wrong ATAV, the upValue should not be null",
message );
+        }
+    }
+
+
+    @Test
+    public void testEmptyNormValueSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "CN", "" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        out.writeObject( atav );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = (Ava)in.readObject();
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testStringAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "CN", "Test" );
+
+        atav.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        AvaSerializer.serialize(atav, out);
+        out.flush();
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = AvaSerializer.deserialize(in);
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    @Test
+    public void testBinaryAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        byte[] upValue = Strings.getBytesUtf8("  Test  ");
+
+        Ava atav = new Ava( schemaManager, "JpegPhoto", upValue );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        AvaSerializer.serialize( atav, out );
+        out.flush();
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = AvaSerializer.deserialize(in);
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test static serialization of a simple ATAV
+     */
+    @Test
+    public void testNullAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            AvaSerializer.serialize(atav, out);
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test( expected = IOException.class )
+    public void testNullNormValueStaticSerialization() throws LdapException, IOException,
ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "UID", (String)null );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        AvaSerializer.serialize(atav, out);
+        fail();
+    }
+
+
+    @Test
+    public void testEmptyNormValueStaticSerialization() throws LdapException, IOException,
ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "UID", (String)"" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        AvaSerializer.serialize(atav, out);
+        out.flush();
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = AvaSerializer.deserialize(in);
+
+        assertEquals( atav, atav2 );
+    }
+}

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/MultiThreadedTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/MultiThreadedTest.java?rev=1073323&r1=1073322&r2=1073323&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/MultiThreadedTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/name/MultiThreadedTest.java
Tue Feb 22 13:44:07 2011
@@ -74,9 +74,8 @@ public class MultiThreadedTest
         sharedRdn = new Rdn( "ou=system" );
         sharedRdn.normalize( schemaManager );
 
-        referenceAva = new Ava( "ou", "2.5.4.11", "System", "system" );
-        referenceAva.normalize();
-        sharedAva = new Ava( "ou", "2.5.4.11", "System", "system" );
+        referenceAva = new Ava( schemaManager, "ou", "System" );
+        sharedAva = new Ava( schemaManager, "ou", "System" );
         sharedAva.normalize();
     }
 

Modified: directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java?rev=1073323&r1=1073322&r2=1073323&view=diff
==============================================================================
--- directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
(original)
+++ directory/shared/trunk/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/LdapEncoder.java
Tue Feb 22 13:44:07 2011
@@ -364,6 +364,4 @@ public class LdapEncoder
             return 0;
         }
     }
-
-
 }

Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java?rev=1073323&r1=1073322&r2=1073323&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
Tue Feb 22 13:44:07 2011
@@ -30,8 +30,12 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.model.entry.BinaryValue;
 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;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 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.MatchingRule;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Strings;
 import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
@@ -53,7 +57,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class Ava implements Cloneable, Comparable<Object>, Externalizable
+public final class Ava implements Cloneable, Comparable<Object>, Externalizable
 {
     /**
      * Declares the Serial Version Uid.
@@ -88,9 +92,11 @@ public class Ava implements Cloneable, C
     /** Two values used for comparison, case insensitive */
     private static final boolean CASE_INSENSITIVE = false;
 
+    /** the schema manager */
+    private transient SchemaManager schemaManager;
 
     /**
-     * Construct an empty Ava
+     * Constructs an empty Ava
      */
     public Ava()
     {
@@ -103,6 +109,20 @@ public class Ava implements Cloneable, C
 
     
     /**
+     * Constructs an empty schema aware Ava
+     */
+    public Ava( SchemaManager schemaManager )
+    {
+        normType = null;
+        upType = null;
+        normValue = null;
+        upValue = null;
+        upName = "";
+        this.schemaManager = schemaManager;
+    }
+
+    
+    /**
      * Construct an Ava. The type and value are normalized :
      * <li> the type is trimmed and lowercased </li>
      * <li> the value is trimmed </li>
@@ -115,12 +135,105 @@ public class Ava implements Cloneable, C
      * @param upValue The User Provided value
      * @param normValue The normalized value
      */
-    public Ava(String upType, String normType, String upValue, String normValue) throws LdapInvalidDnException
+    public Ava( SchemaManager schemaManager, String upType, byte[] upValue ) throws LdapInvalidDnException
     {
-        this( upType, normType, new StringValue( upValue ), new StringValue( normValue )
);
+        this( schemaManager, upType, new BinaryValue( upValue ) );
     }
 
+    
+    /**
+     * Construct an Ava. The type and value are normalized :
+     * <li> the type is trimmed and lowercased </li>
+     * <li> the value is trimmed </li>
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The User Provided type
+     * @param normType The normalized type
+     * @param upValue The User Provided value
+     * @param normValue The normalized value
+     */
+    public Ava( SchemaManager schemaManager, String upType, String upValue ) throws LdapInvalidDnException
+    {
+        this( schemaManager, upType, new StringValue( upValue ) );
+    }
+
+    
+    /**
+     * Construct an Ava. The type and value are normalized :
+     * <li> the type is trimmed and lowercased </li>
+     * <li> the value is trimmed </li>
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The User Provided type
+     * @param normType The normalized type
+     * @param upValue The User Provided value
+     * @param normValue The normalized value
+     */
+    public Ava( SchemaManager schemaManager, String upType, Value<?> upValue ) throws
LdapInvalidDnException
+    {
+        AttributeType attributeType = null;
+        
+        try
+        {
+            attributeType = schemaManager.lookupAttributeTypeRegistry( upType );
+        }
+        catch ( LdapException le )
+        {
+            String message =  I18n.err( I18n.ERR_04188 );
+            LOG.error( message );
+            throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message );
+        }
+        
+        normType = attributeType.getOid();
+        this.upType = upType;
+            
+        try
+        {
+            MatchingRule equalityMatchingRule = attributeType.getEquality();
+            
+            if ( equalityMatchingRule != null )
+            {
+                this.normValue = equalityMatchingRule.getNormalizer().normalize( upValue
);
+            }
+            else
+            {
+                this.normValue = upValue;
+            }
+        }
+        catch ( LdapException le )
+        {
+            String message =  I18n.err( I18n.ERR_04188 );
+            LOG.error( message );
+            throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message );
+        }
+
+        this.upValue = upValue;
+        
+        upName = this.upType + '=' + ( this.upValue == null ? "" : this.upValue.getString()
);
+    }
 
+    
+    /**
+     * Construct an Ava. The type and value are normalized :
+     * <li> the type is trimmed and lowercased </li>
+     * <li> the value is trimmed </li>
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The User Provided type
+     * @param normType The normalized type
+     * @param upValue The User Provided value
+     * @param normValue The normalized value
+     */
+    /* No qualifier */ Ava( String upType, String normType, String upValue, String normValue
) throws LdapInvalidDnException
+    {
+        this( upType, normType, new StringValue( upValue ), new StringValue( normValue )
);
+    }
 
     
     /**
@@ -136,7 +249,7 @@ public class Ava implements Cloneable, C
      * @param upValue The User Provided value
      * @param normValue The normalized value
      */
-    public Ava(String upType, String normType, byte[] upValue, byte[] normValue) throws LdapInvalidDnException
+    /* No qualifier */ Ava( String upType, String normType, byte[] upValue, byte[] normValue
) throws LdapInvalidDnException
     {
         this( upType, normType, new BinaryValue( upValue ), new BinaryValue( normValue )
);
     }
@@ -155,7 +268,7 @@ public class Ava implements Cloneable, C
      * @param upValue The User Provided value
      * @param normValue The normalized value
      */
-    public Ava(String upType, String normType, Value<?> upValue, Value<?> normValue)
throws LdapInvalidDnException
+    /* No qualifier */ Ava(String upType, String normType, Value<?> upValue, Value<?>
normValue) throws LdapInvalidDnException
     {
         String upTypeTrimmed = Strings.trim(upType);
         String normTypeTrimmed = Strings.trim(normType);
@@ -209,7 +322,7 @@ public class Ava implements Cloneable, C
      * @param normValue The normalized value
      * @param upName The User Provided name (may be escaped)
      */
-    public Ava(String upType, String normType, Value<?> upValue, Value<?> normValue,
String upName)
+    /* No qualifier */ Ava(String upType, String normType, Value<?> upValue, Value<?>
normValue, String upName)
         throws LdapInvalidDnException
     {
         String upTypeTrimmed = Strings.trim(upType);
@@ -802,6 +915,17 @@ public class Ava implements Cloneable, C
     
     
     /**
+     * Get the associated SchemaManager if any.
+     * 
+     * @return The SchemaManager
+     */
+    public SchemaManager getSchemaManager()
+    {
+        return schemaManager;
+    }
+    
+    
+    /**
      * A String representation of a Ava.
      *
      * @return A string representing a Ava
@@ -810,16 +934,16 @@ public class Ava implements Cloneable, C
     {
         StringBuffer sb = new StringBuffer();
 
-        if ( Strings.isEmpty(normType) || Strings.isEmpty(normType.trim()) )
+        if ( Strings.isEmpty( normType) || Strings.isEmpty(normType.trim()) )
         {
             return "";
         }
 
-        sb.append( normType ).append( "=" );
+        sb.append( upType ).append( "=" );
 
-        if ( normValue != null )
+        if ( upValue != null )
         {
-            sb.append( normValue.getString() );
+            sb.append( upValue.getString() );
         }
 
         return sb.toString();

Modified: directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java?rev=1073323&r1=1073322&r2=1073323&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
(original)
+++ directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
Tue Feb 22 13:44:07 2011
@@ -105,18 +105,22 @@ public class AvaTest
     public void testAttributeTypeAndValueValidType() throws LdapException
     {
         Ava atav = new Ava( "A", "a", (String)null, (String)null );
-        assertEquals( "a=", atav.toString() );
+        assertEquals( "A=", atav.toString() );
+        assertEquals( "a=", atav.getNormName() );
         assertEquals( "A=", atav.getUpName() );
         
         atav = new Ava( "  A  ", "a", (String)null, (String)null );
-        assertEquals( "a=", atav.toString() );
+        assertEquals( "a=", atav.getNormName() );
+        assertEquals( "  A  =", atav.toString() );
         assertEquals( "  A  =", atav.getUpName() );
         
         atav = new Ava( "  A  ", null, (String)null, (String)null );
-        assertEquals( "a=", atav.toString() );
+        assertEquals( "a=", atav.getNormName() );
+        assertEquals( "  A  =", atav.toString() );
         assertEquals( "  A  =", atav.getUpName() );
         
         atav = new Ava( null, "a", (String)null, (String)null );
+        assertEquals( "a=", atav.getNormName() );
         assertEquals( "a=", atav.toString() );
         assertEquals( "a=", atav.getUpName() );
         



Mime
View raw message