directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1395188 - in /directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core: jndi/ operations/add/ suites/
Date Sat, 06 Oct 2012 23:20:40 GMT
Author: elecharny
Date: Sat Oct  6 23:20:39 2012
New Revision: 1395188

URL: http://svn.apache.org/viewvc?rev=1395188&view=rev
Log:
Migrated some tests from JNDI to API

Added:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/AddJndiIT.java
  (with props)
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/add/DIRSERVER783IT.java
      - copied, changed from r1394453, directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER783IT.java
Removed:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER783IT.java
Modified:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169IT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/AddJndiIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/AddJndiIT.java?rev=1395188&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/AddJndiIT.java
(added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/AddJndiIT.java
Sat Oct  6 23:20:39 2012
@@ -0,0 +1,211 @@
+/*
+ *  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.server.core.jndi;
+
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+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.ldap.LdapContext;
+
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Contributed by Luke Taylor to fix DIRSERVER-169.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(FrameworkRunner.class)
+@CreateDS(name = "AddIT")
+public class AddJndiIT extends AbstractLdapTestUnit
+{
+    /**
+     * Test that attribute name case is preserved after adding an entry
+     * in the case the user added them.  This is to test DIRSERVER-832.
+     */
+    @Test
+    public void testAddCasePreservedOnAttributeNames() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( getService() );
+        
+        Attributes attrs = new BasicAttributes( true );
+        Attribute oc = new BasicAttribute( "ObjectClass", "top" );
+        oc.add( "PERSON" );
+        oc.add( "organizationalPerson" );
+        oc.add( "inetORGperson" );
+        Attribute cn = new BasicAttribute( "Cn", "Kevin Spacey" );
+        Attribute dc = new BasicAttribute( "sN", "Spacey" );
+        attrs.put( oc );
+        attrs.put( cn );
+        attrs.put( dc);
+        sysRoot.createSubcontext( "uID=kevin", attrs );
+        Attributes returned = sysRoot.getAttributes( "UID=kevin" );
+        
+        NamingEnumeration<? extends Attribute> attrList = returned.getAll();
+        
+        while( attrList.hasMore() )
+        {
+            Attribute attr = attrList.next();
+            
+            if ( attr.getID().equalsIgnoreCase( "uid" ) )
+            {
+                assertEquals( "uid", attr.getID() );
+            }
+            
+            if ( attr.getID().equalsIgnoreCase( "objectClass" ) )
+            {
+                assertEquals( "objectClass", attr.getID() );
+            }
+            
+            if ( attr.getID().equalsIgnoreCase( "sn" ) )
+            {
+                assertEquals( "sn", attr.getID() );
+            }
+            
+            if ( attr.getID().equalsIgnoreCase( "cn" ) )
+            {
+                assertEquals( "cn", attr.getID() );
+            }
+        }
+    }
+
+    /**
+     * Test that we can't add an entry with an attribute type not within
+     * any of the MUST or MAY of any of its objectClasses
+     * 
+     * @throws Exception on error
+     */
+    @Test
+    public void testAddAttributesNotInObjectClasses() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( getService() );
+
+        Attributes attrs = LdifUtils.createJndiAttributes(
+            "ObjectClass: top",
+            "cn: kevin Spacey",
+            "dc: ke" );
+
+        String base = "uid=kevin";
+
+        //create subcontext
+        try
+        {
+            sysRoot.createSubcontext( base, attrs );
+            fail( "Should not reach this state" );
+        }
+        catch ( NamingException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test that we can't add an entry with an attribute with a bad syntax
+     *
+     * @throws Exception on error
+     */
+    @Test
+    public void testAddAttributesBadSyntax() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( getService() );
+
+        Attributes attrs = LdifUtils.createJndiAttributes(
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "cn: kevin Spacey",
+            "sn: ke",
+            "telephoneNumber: 0123456abc" );
+
+        String base = "sn=kevin";
+
+        // create subcontext
+        try
+        {
+            sysRoot.createSubcontext( base, attrs );
+            fail( "Should not reach this state" );
+        }
+        catch ( NamingException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * test case for DIRSERVER-1442
+     */
+    @Test
+    public void testAddAttributeWithEscapedPlusCharacter() throws Exception
+    {
+        Attributes entry = LdifUtils.createJndiAttributes(
+            "ObjectClass: top",
+            "ObjectClass: inetorgperson",
+            "cn: John+Doe",
+            "sn: +Name+" );
+
+        LdapContext sysRoot = getSystemContext( getService() );
+        DirContext dc = sysRoot.createSubcontext( "cn=John\\+Doe", entry );
+
+        ServerLdapContext sc = ( ServerLdapContext ) dc;
+
+        assertTrue( sc.getDn().toString().contains( "+" ) );
+
+        try
+        {
+            Object obj = sysRoot.lookup( "cn=John\\+Doe" );
+            assertNotNull( obj );
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        try
+        {
+            Attributes result = sysRoot.getAttributes( "cn=John\\+Doe" );
+            assertNotNull( result );
+
+            Attribute cn = result.get( "cn" );
+            assertNotNull( cn );
+            assertEquals( 1, cn.size() );
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+    }
+}

Propchange: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/AddJndiIT.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169IT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169IT.java?rev=1395188&r1=1395187&r2=1395188&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169IT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER169IT.java
Sat Oct  6 23:20:39 2012
@@ -43,6 +43,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -66,26 +67,25 @@ public class DIRSERVER169IT extends Abst
     {
         LdapContext sysRoot = getSystemContext( getService() );
 
-        Attributes people = new BasicAttributes( true );
-        Attribute attribute = new BasicAttribute( "objectClass" );
-        attribute.add( "top" );
-        attribute.add( "organizationalUnit" );
-        people.put( attribute );
-        people.put( "ou", "people" );
+        Attributes people = LdifUtils.getJndiAttributesFromLdif(
+            "objectClass: top\n" +
+            "objectClass: organizationalUnit\n" +
+            "ou: people" );
+        
         sysRoot.createSubcontext( "ou=people", people );
 
-        Attributes user = new BasicAttributes( "uid", "bob", true );
-        user.put( "cn", "Bob Hamilton" );
-        user.put( "userPassword", "bobspassword" );
-
-        Attribute objectClass = new BasicAttribute( "objectClass" );
-        user.put( objectClass );
-        objectClass.add( "top" );
-        objectClass.add( "person" );
-        objectClass.add( "organizationalPerson" );
-        objectClass.add( "inetOrgPerson" );
-        user.put( "sn", "Hamilton" );
-
+        Attributes user = LdifUtils.getJndiAttributesFromLdif(
+            "objectClass: top\n" +
+            "objectClass: person\n" +
+            "objectClass: organizationalPerson\n" +
+            "objectClass: inetOrgPerson\n" +
+            "ou: people\n" +
+            "uid: bob\n" +
+            "cn: Bob Hamilton\n" +
+            "userPassword: bobspassword\n" +
+            "sn: Hamilton"
+            );
+        
         sysRoot.createSubcontext( "uid=bob,ou=people", user );
     }
 
@@ -93,7 +93,6 @@ public class DIRSERVER169IT extends Abst
     @Test
     public void testSearchResultNameIsRelativeToSearchContext() throws Exception
     {
-        // @todo replace with ldif tags
         createData();
 
         LdapContext sysRoot = getSystemContext( getService() );
@@ -140,7 +139,6 @@ public class DIRSERVER169IT extends Abst
     @Test
     public void testPasswordComparisonSucceeds() throws Exception
     {
-        // @todo replace with ldif tags
         createData();
 
         Hashtable<String, Object> env = new Hashtable<String, Object>();

Copied: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/add/DIRSERVER783IT.java
(from r1394453, directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER783IT.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/add/DIRSERVER783IT.java?p2=directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/add/DIRSERVER783IT.java&p1=directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER783IT.java&r1=1394453&r2=1395188&rev=1395188&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/DIRSERVER783IT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/add/DIRSERVER783IT.java
Sat Oct  6 23:20:39 2012
@@ -17,32 +17,23 @@
  *  under the License.
  *
  */
-package org.apache.directory.server.core.jndi;
+package org.apache.directory.server.core.operations.add;
 
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getAdminConnection;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-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.InitialDirContext;
-import javax.naming.directory.ModificationItem;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.core.annotations.CreateDS;
-import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -57,81 +48,59 @@ import org.junit.runner.RunWith;
 @CreateDS(allowAnonAccess = true, name = "DIRSERVER783IT")
 public class DIRSERVER783IT extends AbstractLdapTestUnit
 {
-
     /**
      * Try to add entry with required attribute missing.
      * 
      * @throws NamingException if there are errors
      */
     @Test
-    public void testAddAnotherValueToAnAttribute() throws NamingException
+    public void testAddAnotherValueToAnAttribute() throws Exception
     {
-        // create a person without sn
-        Attributes attrs = new BasicAttributes( true );
-        Attribute ocls = new BasicAttribute( "objectClass" );
-
-        ocls.add( "top" );
-        ocls.add( "person" );
-        attrs.put( ocls );
-        attrs.put( "cn", "Fiona Apple" );
-        attrs.put( "sn", "Apple" );
+        LdapConnection sysRoot = getAdminConnection( getService() );
 
-        String rdn = "cn=Fiona Apple";
-
-        Hashtable<String, Object> env = new Hashtable<String, Object>();
-        env.put( DirectoryService.JNDI_KEY, getService() );
-        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
-        env.put( Context.PROVIDER_URL, "ou=system" );
-
-        DirContext ctx = new InitialDirContext( env );
-
-        ctx.createSubcontext( rdn, attrs );
+        String dn = "cn=Fiona Apple, ou=system";
+        
+        // create a person without sn
+        Entry entry = new DefaultEntry( dn,
+            "objectClass: top",
+            "objectClass: person",
+            "cn: Fiona Apple",
+            "sn: Apple" );
+        
+        sysRoot.add( entry );
 
         // Add the first value for description
         String description1 = "an American singer-songwriter";
-        Attribute firstDescr = new BasicAttribute( "description", description1 );
-        ModificationItem modification = new ModificationItem( DirContext.ADD_ATTRIBUTE, firstDescr
);
-        ctx.modifyAttributes( rdn, new ModificationItem[]
-            { modification } );
+        Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE,
"description", description1 );
+        
+        sysRoot.modify( dn, modification );
+        
 
         // Add a second value to description
         String description2 = "Grammy award winning";
-        Attribute otherDescr = new BasicAttribute( "description", description2 );
+        modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "description",
description2 );
 
-        modification = new ModificationItem( DirContext.ADD_ATTRIBUTE, otherDescr );
-        ctx.modifyAttributes( rdn, new ModificationItem[]
-            { modification } );
+        sysRoot.modify( dn, modification );
 
         // Add a third value to description
         String description3 = "MTV Music Award winning";
-        Attribute thirdDescr = new BasicAttribute( "description", description3 );
+        modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "description",
description3 );
 
-        modification = new ModificationItem( DirContext.ADD_ATTRIBUTE, thirdDescr );
-        ctx.modifyAttributes( rdn, new ModificationItem[]
-            { modification } );
+        sysRoot.modify( dn, modification );
 
         // Search Entry
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        String filter = '(' + rdn + ')';
-        String base = "";
-
-        // Check entry
-        NamingEnumeration<SearchResult> enm = ctx.search( base, filter, sctls );
-        assertTrue( enm.hasMore() );
+        EntryCursor cursor = sysRoot.search( dn, "(cn=Fiona Apple)",
+            SearchScope.ONELEVEL, "*" );
 
-        while ( enm.hasMore() )
+        while ( cursor.next() )
         {
-            SearchResult sr = enm.next();
-            Attribute desc = sr.getAttributes().get( "description" );
-            assertNotNull( desc );
-            assertTrue( desc.contains( description1 ) );
-            assertTrue( desc.contains( description2 ) );
-            assertTrue( desc.contains( description3 ) );
-            assertEquals( 3, desc.size() );
+            Entry result = cursor.get();
+            assertTrue( result.contains( "description", description1, description2, description3
) );
         }
 
+        cursor.close();
+
         // Remove the person entry
-        ctx.destroySubcontext( rdn );
+        sysRoot.delete( dn );
     }
 }

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java?rev=1395188&r1=1395187&r2=1395188&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/MigratedStockCoreISuite.java
Sat Oct  6 23:20:39 2012
@@ -40,6 +40,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.exception.ExceptionServiceIT;
 import org.apache.directory.server.core.integ.FrameworkSuite;
 import org.apache.directory.server.core.operations.add.AddIT;
+import org.apache.directory.server.core.operations.add.DIRSERVER783IT;
 import org.apache.directory.server.core.operations.add.PasswordHashingInterceptorTest;
 import org.apache.directory.server.core.operations.move.MoveIT;
 import org.junit.runner.RunWith;
@@ -87,9 +88,10 @@ import org.junit.runners.Suite;
         // exception
         ExceptionServiceIT.class,
         
-        // jndi
+        // Operations
         AddIT.class,
-        
+        DIRSERVER783IT.class,
+
         // Operations
         MoveIT.class
 })

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java?rev=1395188&r1=1395187&r2=1395188&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/suites/StockCoreISuite.java
Sat Oct  6 23:20:39 2012
@@ -21,9 +21,9 @@ package org.apache.directory.server.core
 
 import org.apache.directory.server.core.configuration.PartitionConfigurationIT;
 import org.apache.directory.server.core.integ.FrameworkSuite;
+import org.apache.directory.server.core.jndi.AddJndiIT;
 import org.apache.directory.server.core.jndi.CreateContextIT;
 import org.apache.directory.server.core.jndi.DIRSERVER169IT;
-import org.apache.directory.server.core.jndi.DIRSERVER783IT;
 import org.apache.directory.server.core.jndi.DIRSERVER791IT;
 import org.apache.directory.server.core.jndi.DestroyContextIT;
 import org.apache.directory.server.core.jndi.ExtensibleObjectIT;
@@ -99,11 +99,11 @@ import org.junit.runners.Suite;
         // configuration
         PartitionConfigurationIT.class,
 
-        // jndi
+        // jndi Operations
+        AddJndiIT.class,
         CreateContextIT.class,
         DestroyContextIT.class,
         DIRSERVER169IT.class,
-        DIRSERVER783IT.class,
         DIRSERVER791IT.class,
         ExtensibleObjectIT.class,
         ListIT.class,



Mime
View raw message