directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r650022 - in /directory/sandbox/akarasulu/bigbang: apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/ shared/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/
Date Mon, 21 Apr 2008 06:00:04 GMT
Author: akarasulu
Date: Sun Apr 20 23:00:01 2008
New Revision: 650022

URL: http://svn.apache.org/viewvc?rev=650022&view=rev
Log:
100% test coverage for LessEqEvaluator

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java
    directory/sandbox/akarasulu/bigbang/shared/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java?rev=650022&r1=650021&r2=650022&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java
Sun Apr 20 23:00:01 2008
@@ -32,15 +32,24 @@
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.filter.LessEqNode;
+import org.apache.directory.shared.ldap.schema.*;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.After;
 import org.junit.Test;import static org.junit.Assert.assertTrue;import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import javax.naming.directory.Attributes;
+import javax.naming.NamingException;
 import java.io.File;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.Comparator;
+
+import jdbm.helper.StringComparator;
 
 
 /**
@@ -126,34 +135,439 @@
 
 
     @Test
-    public void testEvaluator() throws Exception
+    public void testEvaluatorIndexed() throws Exception
     {
         LessEqNode node = new LessEqNode( SchemaConstants.POSTALCODE_AT_OID, "3" );
         LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
         ForwardIndexEntry<String,Attributes> indexEntry = new ForwardIndexEntry<String,Attributes>();
+        assertEquals( node, evaluator.getExpression() );
+        assertEquals( SchemaConstants.POSTALCODE_AT_OID, evaluator.getAttributeType().getOid()
);
+        assertNotNull( evaluator.getNormalizer() );
+        assertNotNull( evaluator.getComparator() );
+
+        indexEntry.setId( 1L );
+        assertTrue( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 4L );
+        assertTrue( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 5L );
+        assertTrue( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 6L );
+        assertFalse( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 7L );
+        assertFalse( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 8L );
+        assertFalse( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 9L );
+        assertFalse( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
+        indexEntry.setId( 10L );
+        assertFalse( evaluator.evaluate( indexEntry ) );
+    }
+
+
+    @Test
+    public void testEvaluatorWithDescendantValue() throws Exception
+    {
+        LessEqNode node = new LessEqNode( SchemaConstants.STREET_AT_OID, "2" );
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
+        ForwardIndexEntry<String,Attributes> indexEntry = new ForwardIndexEntry<String,Attributes>();
+        assertEquals( node, evaluator.getExpression() );
+        assertEquals( SchemaConstants.STREET_AT_OID, evaluator.getAttributeType().getOid()
);
+        assertNotNull( evaluator.getNormalizer() );
+        assertNotNull( evaluator.getComparator() );
+
+        LdapDN dn = new LdapDN( "cn=jane doe,o=good times co." );
+        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        AttributesImpl attrs = new AttributesImpl( "objectClass", "person", true );
+        attrs.put( "c-street", "1" );
+        attrs.put( "cn", "jane doe" );
+        attrs.put( "sn", "doe" );
+        store.add( dn, attrs );
+
+        indexEntry.setId( 12L );
+        assertTrue( evaluator.evaluate( indexEntry ) );
+    }
+
+
+    @Test
+    public void testEvaluatorWithoutDescendants() throws Exception
+    {
+        LessEqNode node = new LessEqNode( SchemaConstants.C_POSTALCODE_AT_OID, "2" );
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
+        ForwardIndexEntry<String,Attributes> indexEntry = new ForwardIndexEntry<String,Attributes>();
+        assertEquals( node, evaluator.getExpression() );
+        assertEquals( SchemaConstants.C_POSTALCODE_AT_OID, evaluator.getAttributeType().getOid()
);
+        assertNotNull( evaluator.getNormalizer() );
+        assertNotNull( evaluator.getComparator() );
+
+        indexEntry.setId( 1L );
+        assertFalse( evaluator.evaluate( indexEntry ) );
+    }
+
+
+    @Test
+    public void testEvaluatorNotIndexed() throws Exception
+    {
+        LessEqNode node = new LessEqNode( SchemaConstants.POSTOFFICEBOX_AT_OID, "3" );
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
+        ForwardIndexEntry<String,Attributes> indexEntry = new ForwardIndexEntry<String,Attributes>();
+        assertEquals( node, evaluator.getExpression() );
+        assertEquals( SchemaConstants.POSTOFFICEBOX_AT_OID, evaluator.getAttributeType().getOid()
);
+        assertNotNull( evaluator.getNormalizer() );
+        assertNotNull( evaluator.getComparator() );
 
         indexEntry.setId( 1L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 4L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 5L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 6L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 7L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 8L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 9L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
+        indexEntry = new ForwardIndexEntry<String,Attributes>();
         indexEntry.setId( 10L );
         assertFalse( evaluator.evaluate( indexEntry ) );
+    }
+
+
+    @Test ( expected = IllegalStateException.class )
+    public void testEvaluatorAttributeNoMatchingRule() throws Exception
+    {
+        AttributeType at = new AttributeType()
+        {
+
+            public boolean isSingleValue()
+            {
+                return false;
+            }
+
+
+            public boolean isCanUserModify()
+            {
+                return false;
+            }
+
+
+            public boolean isCollective()
+            {
+                return false;
+            }
+
+
+            public UsageEnum getUsage()
+            {
+                return null;
+            }
+
+
+            public AttributeType getSuperior() throws NamingException
+            {
+                return null;
+            }
+
+
+            public Syntax getSyntax() throws NamingException
+            {
+                return null;
+            }
+
+
+            public int getLength()
+            {
+                return 0;
+            }
+
+
+            public MatchingRule getEquality() throws NamingException
+            {
+                return null;
+            }
+
+
+            public MatchingRule getOrdering() throws NamingException
+            {
+                return null;
+            }
+
+
+            public MatchingRule getSubstr() throws NamingException
+            {
+                return null;
+            }
+
+
+            public boolean isAncestorOf( AttributeType descendant ) throws NamingException
+            {
+                return false;
+            }
+
+
+            public boolean isDescentantOf( AttributeType ancestor ) throws NamingException
+            {
+                return false;
+            }
+
+
+            public boolean isObsolete()
+            {
+                return false;
+            }
+
+
+            public String getOid()
+            {
+                return SchemaConstants.ATTRIBUTE_TYPES_AT_OID + ".2000";
+            }
+
+
+            public String[] getNames()
+            {
+                return new String[] { "bogus" };
+            }
+
+
+            public String getName()
+            {
+                return "bogus";
+            }
+
+
+            public String getDescription()
+            {
+                return "";
+            }
+
+
+            public String getSchema()
+            {
+                return "other";
+            }
+
+
+            public void setSchema( String schemaName )
+            {
+            }
+        };
+        registries.getAttributeTypeRegistry().register( at );
+        LessEqNode node = new LessEqNode( at.getOid(), "3" );
+        new LessEqEvaluator( node, store, registries );
+        registries.getAttributeTypeRegistry().unregister( at.getOid() );
+    }
+
+
+    @Test
+    public void testEvaluatorAttributeOrderingMatchingRule() throws Exception
+    {
+        AttributeType at = new AttributeType()
+        {
+
+            public boolean isSingleValue()
+            {
+                return false;
+            }
+
+
+            public boolean isCanUserModify()
+            {
+                return false;
+            }
+
+
+            public boolean isCollective()
+            {
+                return false;
+            }
+
+
+            public UsageEnum getUsage()
+            {
+                return null;
+            }
+
+
+            public AttributeType getSuperior() throws NamingException
+            {
+                return null;
+            }
+
+
+            public Syntax getSyntax() throws NamingException
+            {
+                return null;
+            }
+
+
+            public int getLength()
+            {
+                return 0;
+            }
+
+
+            public MatchingRule getEquality() throws NamingException
+            {
+                return null;
+            }
+
+
+            public MatchingRule getOrdering() throws NamingException
+            {
+                return new MatchingRule()
+                {
+
+                    public Syntax getSyntax() throws NamingException
+                    {
+                        return null;
+                    }
+
+
+                    public Comparator getComparator() throws NamingException
+                    {
+                        return new StringComparator();
+                    }
+
+
+                    public Normalizer getNormalizer() throws NamingException
+                    {
+                        return new NoOpNormalizer();
+                    }
+
+
+                    public boolean isObsolete()
+                    {
+                        return false;
+                    }
+
+
+                    public String getOid()
+                    {
+                        return null;
+                    }
+
+
+                    public String[] getNames()
+                    {
+                        return new String[0];
+                    }
+
+
+                    public String getName()
+                    {
+                        return null;
+                    }
+
+
+                    public String getDescription()
+                    {
+                        return null;
+                    }
+
+
+                    public String getSchema()
+                    {
+                        return null;
+                    }
+
+
+                    public void setSchema( String schemaName )
+                    {
+                    }
+                };
+            }
+
+
+            public MatchingRule getSubstr() throws NamingException
+            {
+                return null;
+            }
+
+
+            public boolean isAncestorOf( AttributeType descendant ) throws NamingException
+            {
+                return false;
+            }
+
+
+            public boolean isDescentantOf( AttributeType ancestor ) throws NamingException
+            {
+                return false;
+            }
+
+
+            public boolean isObsolete()
+            {
+                return false;
+            }
+
+
+            public String getOid()
+            {
+                return SchemaConstants.ATTRIBUTE_TYPES_AT_OID + ".2000";
+            }
+
+
+            public String[] getNames()
+            {
+                return new String[] { "bogus" };
+            }
+
+
+            public String getName()
+            {
+                return "bogus";
+            }
+
+
+            public String getDescription()
+            {
+                return "";
+            }
+
+
+            public String getSchema()
+            {
+                return "other";
+            }
+
+
+            public void setSchema( String schemaName )
+            {
+            }
+        };
+        registries.getAttributeTypeRegistry().register( at );
+        LessEqNode node = new LessEqNode( at.getOid(), "3" );
+        new LessEqEvaluator( node, store, registries );
+        registries.getAttributeTypeRegistry().unregister( at.getOid() );
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java?rev=650022&r1=650021&r2=650022&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
(original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
Sun Apr 20 23:00:01 2008
@@ -157,6 +157,10 @@
     String POSTALCODE_AT = "postalCode";
     String POSTALCODE_AT_OID = "2.5.4.17";
 
+    // PostalCode
+    String C_POSTALCODE_AT = "c-postalCode";
+    String C_POSTALCODE_AT_OID = "2.5.4.17.1";
+
     // PostOfficeBox
     String POSTOFFICEBOX_AT = "postOfficeBox";
     String POSTOFFICEBOX_AT_OID = "2.5.4.18";



Mime
View raw message