directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r824946 - /directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
Date Tue, 13 Oct 2009 22:03:00 GMT
Author: elecharny
Date: Tue Oct 13 22:02:59 2009
New Revision: 824946

URL: http://svn.apache.org/viewvc?rev=824946&view=rev
Log:
o Added a @Before method
o Used the new AttributeUtils.createAttribute() method

Modified:
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java?rev=824946&r1=824945&r2=824946&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
Tue Oct 13 22:02:59 2009
@@ -38,7 +38,6 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.InvalidSearchFilterException;
 import javax.naming.directory.ModificationItem;
@@ -53,6 +52,8 @@
 import org.apache.directory.shared.ldap.exception.LdapSizeLimitExceededException;
 import org.apache.directory.shared.ldap.exception.LdapTimeLimitExceededException;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -150,14 +151,18 @@
     private static final String FILTER = "(objectclass=*)";
 
     public static DirectoryService service;
+    public static LdapContext sysRoot;
 
     
     /**
      * @param sysRoot the system root to add entries to
      * @throws NamingException on errors
      */
-    protected void createData( LdapContext sysRoot ) throws Exception
+    @Before
+    public void createData() throws Exception
     {
+        sysRoot = getSystemContext( service ); 
+            
         /*
          * Check ou=testing00,ou=system
          */
@@ -258,12 +263,14 @@
     /**
      * Create a NIS group
      */
-    private DirContext addNisPosixGroup( String name, int gid ) throws Exception
+    private static DirContext addNisPosixGroup( String name, int gid ) throws Exception
     {
-        Attributes attrs = new BasicAttributes( "objectClass", "top", true );
-        attrs.get( "objectClass" ).add( "posixGroup" );
-        attrs.put( "cn", name );
-        attrs.put( "gidNumber", String.valueOf( gid ) );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top", 
+            "objectClass: posixGroup",
+            "cn", name,
+            "gidNumber", String.valueOf( gid ) );
+        
         return getSystemContext( service ).createSubcontext( "cn="+name+",ou=groups", attrs
);
     }
 
@@ -271,9 +278,6 @@
     @Test
     public void testSearchOneLevel() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -299,9 +303,6 @@
     @Test
     public void testSearchSubTreeLevel() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -329,9 +330,6 @@
     @Test
     public void testSearchSubTreeLevelNoAttributes() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -360,9 +358,6 @@
     @Test
     public void testSearchSubstringSubTreeLevel() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -406,7 +401,6 @@
         boolean oldSetAllowAnnonymousAccess = service.isAllowAnonymousAccess();
         service.setAllowAnonymousAccess( true );
 
-        LdapContext sysRoot = getSystemContext( service );
         SearchControls cons = new SearchControls();
         NamingEnumeration<SearchResult> e = sysRoot.search( "", "(bogusAttribute=abc123)",
cons );
         assertNotNull( e );
@@ -437,9 +431,6 @@
     @Test
     public void testSearchFilterArgs() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -466,9 +457,6 @@
     @Ignore ( "TODO - fix me" )
     public void testSearchSizeLimit() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -500,9 +488,6 @@
     @Ignore ( "TODO - fix me" )
     public void testSearchTimeLimit() throws Exception, InterruptedException
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -537,9 +522,6 @@
     @Test
     public void testFilterExpansion0() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -563,9 +545,6 @@
     @Test
     public void testFilterExpansion1() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -601,9 +580,6 @@
     @Test
     public void testFilterExpansion2() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -628,9 +604,6 @@
     @Test
     public void testFilterExpansion4() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -659,9 +632,6 @@
     @Test
     public void testFilterExpansion5() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -695,9 +665,6 @@
     @Test
     public void testOpAttrDenormalizationOff() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -725,9 +692,6 @@
     @Test
     public void testOpAttrDenormalizationOn() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         service.setDenormalizeOpAttrsEnabled( true );
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
@@ -760,15 +724,14 @@
      * @param sn the surName of the person
      * @return the attributes of a new person entry
      */
-    protected Attributes getPersonAttributes( String sn, String cn )
+    protected Attributes getPersonAttributes( String sn, String cn ) throws NamingException
     {
-        Attributes attributes = new BasicAttributes( true );
-        Attribute attribute = new BasicAttribute( "objectClass" );
-        attribute.add( "top" );
-        attribute.add( "person" );
-        attributes.put( attribute );
-        attributes.put( "cn", cn );
-        attributes.put( "sn", sn );
+        Attributes attributes = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: top",
+            "objectClass: person",
+            "cn", cn,
+            "sn", sn );
 
         return attributes;
     }
@@ -777,9 +740,6 @@
     @Test
     public void testBinaryAttributesInFilter() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         byte[] certData = new byte[] { 0x34, 0x56, 0x4e, 0x5f };
         
         // First let's add a some binary data representing a userCertificate
@@ -813,9 +773,6 @@
     @Test
     public void testSearchOperationalAttr() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -846,9 +803,6 @@
     @Test
     public void testSearchUserAttr() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -879,9 +833,6 @@
     @Test
     public void testSearchUserAttrAndOpAttr() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -912,9 +863,6 @@
     @Test
     public void testSearchUserAttrAndNoAttr() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -945,9 +893,6 @@
     @Test
     public void testSearchNoAttr() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -978,9 +923,6 @@
     @Test
     public void testSearchAllAttr() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -1016,9 +958,6 @@
     @Test
     public void testSearchFetchNonExistingAttributeOption() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls ctls = new SearchControls();
         ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
         ctls.setReturningAttributes( new String[]
@@ -1054,9 +993,6 @@
     @Test
     public void testSearchFetchTwiceSameAttribute() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls ctls = new SearchControls();
         ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
         ctls.setReturningAttributes( new String[]
@@ -1216,9 +1152,6 @@
     @Test
     public void testSetup() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         Set<String> results = searchGroups( "(objectClass=posixGroup)" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
@@ -1232,9 +1165,6 @@
     @Test
     public void testLessThanSearch() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         Set<String> results = searchGroups( "(gidNumber<=5)" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
@@ -1280,9 +1210,6 @@
     @Test
     public void testGreaterThanSearch() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         Set<String> results = searchGroups( "(gidNumber>=0)" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
@@ -1320,9 +1247,6 @@
     @Test
     public void testNotOperator() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         Set<String> results = searchGroups( "(!(gidNumber=4))" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
@@ -1336,9 +1260,6 @@
     @Test
     public void testNotOperatorSubtree() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
 
@@ -1355,17 +1276,14 @@
     @Test
     public void testSearchWithEscapedCharsInFilter() throws Exception
     {
-        // Create an entry with special chars in the description attribute
-        LdapContext sysRoot = getSystemContext( service );
         // Create entry cn=Sid Vicious, ou=system
-        Attributes vicious = new BasicAttributes( true );
-        Attribute ocls = new BasicAttribute( "objectClass" );
-        ocls.add( "top" );
-        ocls.add( "person" );
-        vicious.put( ocls );
-        vicious.put( "cn", "Sid Vicious" );
-        vicious.put( "sn", "Vicious" );
-        vicious.put( "description", "(sex*pis\\tols)" );
+        Attributes vicious = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: person",
+            "cn", "Sid Vicious",
+            "sn", "Vicious",
+            "description", "(sex*pis\\tols)" );
+
         DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
         assertNotNull( ctx );
 
@@ -1408,17 +1326,14 @@
     @Test
     public void testSubstringSearchWithEscapedCharsInFilter() throws Exception
     {
-        // Create an entry with special chars in the description attribute
-        LdapContext sysRoot = getSystemContext( service );
         // Create entry cn=Sid Vicious, ou=system
-        Attributes vicious = new BasicAttributes( true );
-        Attribute ocls = new BasicAttribute( "objectClass" );
-        ocls.add( "top" );
-        ocls.add( "person" );
-        vicious.put( ocls );
-        vicious.put( "cn", "Sid Vicious" );
-        vicious.put( "sn", "Vicious" );
-        vicious.put( "description", "(sex*pis\\tols)" );
+        Attributes vicious = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: person",
+            "cn", "Sid Vicious",
+            "sn", "Vicious",
+            "description", "(sex*pis\\tols)" );
+
         DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
         assertNotNull( ctx );
 
@@ -1464,15 +1379,13 @@
     @Test
     public void testSubstringSearchWithEscapedAsterisksInFilter_DIRSERVER_1181() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
+        Attributes vicious = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: person",
+            "cn", "x*y*z*",
+            "sn", "x*y*z*",
+            "description", "(sex*pis\\tols)" );
 
-        Attributes vicious = new BasicAttributes( true );
-        Attribute ocls = new BasicAttribute( "objectClass" );
-        ocls.add( "top" );
-        ocls.add( "person" );
-        vicious.put( ocls );
-        vicious.put( "cn", "x*y*z*" );
-        vicious.put( "sn", "x*y*z*" );
         sysRoot.createSubcontext( "cn=x*y*z*", vicious );
 
         SearchControls controls = new SearchControls();
@@ -1500,9 +1413,6 @@
     @Test
     public void testBadFilter() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        createData( sysRoot );
-
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         controls.setDerefLinkFlag( false );
@@ -1569,9 +1479,6 @@
     */
    @Test
    public void testIntegerComparison() throws Exception {
-       LdapContext sysRoot = getSystemContext(service);
-       createData(sysRoot);
-       
        Set<String> results = searchUnits("(&(objectClass=organizationalUnit)(integerAttribute<=2))",null);
        assertTrue(results.contains("ou=testing00,ou=system"));
        assertTrue(results.contains("ou=testing01,ou=system"));
@@ -1591,8 +1498,6 @@
     */
    @Test
    public void testIntegerComparison2() throws Exception {
-       LdapContext sysRoot = getSystemContext(service);
-       createData(sysRoot);
        Set<String> results = searchUnits("(&(objectClass=organizationalUnit)(integerAttribute>=3))",null);
        assertFalse(results.contains("ou=testing00,ou=system"));
        assertFalse(results.contains("ou=testing01,ou=system"));
@@ -1612,9 +1517,6 @@
     */
    @Test
    public void testIntegerComparison3() throws Exception {
-       LdapContext sysRoot = getSystemContext(service);
-       createData(sysRoot);
-       
        Set<String> results = searchUnits("(&(objectClass=organizationalUnit)(integerAttribute<=42))",null);
        assertTrue(results.contains("ou=testing00,ou=system"));
        assertTrue(results.contains("ou=testing01,ou=system"));
@@ -1633,9 +1535,6 @@
     */
    @Test
    public void testIntegerComparison4() throws Exception {
-       LdapContext sysRoot = getSystemContext(service);
-       createData(sysRoot);
-       
        Set<String> results = searchUnits("(&(objectClass=organizationalUnit)(|(integerAttribute<=1)(integerAttribute>=5)))",null);
        assertTrue(results.contains("ou=testing00,ou=system"));
        assertTrue(results.contains("ou=testing01,ou=system"));
@@ -1649,9 +1548,6 @@
    @Test
    public void testSearchTelephoneNumber() throws Exception
    {
-       LdapContext sysRoot = getSystemContext( service );
-       createData( sysRoot );
-
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
 
@@ -1673,9 +1569,6 @@
    @Test
    public void testSearchDN() throws Exception
    {
-       LdapContext sysRoot = getSystemContext( service );
-       createData( sysRoot );
-
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        controls.setDerefLinkFlag( false );
@@ -1700,9 +1593,6 @@
    @Test
    public void testComplexFilter() throws Exception
    {
-       LdapContext sysRoot = getSystemContext( service );
-       createData( sysRoot );
-
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        controls.setDerefLinkFlag( false );
@@ -1710,10 +1600,12 @@
                AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() );
        
        // Create an entry which does not match
-       Attributes attrs = new BasicAttributes( "objectClass", "top", true );
-       attrs.get( "objectClass" ).add( "groupOfUniqueNames" );
-       attrs.put( "cn", "testGroup3" );
-       attrs.put( "uniqueMember", "uid=admin,ou=system" );
+       Attributes attrs = AttributeUtils.createAttributes( 
+           "objectClass: top",
+           "objectClass: groupOfUniqueNames",
+           "cn", "testGroup3",
+           "uniqueMember", "uid=admin,ou=system" );
+
        getSystemContext( service ).createSubcontext( "cn=testGroup3,ou=groups", attrs );
        
        



Mime
View raw message