directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1053703 - in /directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree: AbstractSubentryUnitTest.java SubentryAddOperationIT.java SubentryDeleteOperationIT.java
Date Wed, 29 Dec 2010 19:03:24 GMT
Author: elecharny
Date: Wed Dec 29 19:03:24 2010
New Revision: 1053703

URL: http://svn.apache.org/viewvc?rev=1053703&view=rev
Log:
 o Added a helper class for tests
 o Added some tests for the Add operation

Added:
    directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/AbstractSubentryUnitTest.java
Modified:
    directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryAddOperationIT.java
    directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryDeleteOperationIT.java

Added: directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/AbstractSubentryUnitTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/AbstractSubentryUnitTest.java?rev=1053703&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/AbstractSubentryUnitTest.java
(added)
+++ directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/AbstractSubentryUnitTest.java
Wed Dec 29 19:03:24 2010
@@ -0,0 +1,121 @@
+/*
+ *  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.subtree;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * Common class for the subentry operation tests
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbstractSubentryUnitTest extends AbstractLdapTestUnit
+{
+    // The shared LDAP admin connection
+    protected static LdapConnection adminConnection;
+
+    // The shared LDAP user connection
+    protected static LdapConnection userConnection;
+
+
+    @Before
+    public void init() throws Exception
+    {
+        adminConnection = IntegrationUtils.getAdminConnection( service );
+        userConnection = IntegrationUtils.getConnectionAs( service, "cn=test,ou=system",
"test" );
+    }
+
+
+    @After
+    public void shutdown() throws Exception
+    {
+        adminConnection.close();
+        userConnection.close();
+    }
+
+
+    /**
+     * Helper methods
+     */
+    protected Entry getAdminRole( String dn ) throws Exception
+    {
+        Entry lookup = adminConnection.lookup( dn, "administrativeRole" );
+
+        assertNotNull( lookup );
+
+        return lookup;
+    }
+    
+    
+    protected long getACSeqNumber( String apDn ) throws LdapException
+    {
+        Entry entry = adminConnection.lookup( apDn, "AccessControlSeqNumber" );
+        
+        EntryAttribute attribute = entry.get( ApacheSchemaConstants.ACCESS_CONTROL_SEQ_NUMBER_AT
);
+        
+        if ( attribute == null )
+        {
+            return Long.MIN_VALUE;
+        }
+        
+        return Long.parseLong( attribute.getString() );
+    }
+
+    
+    protected long getCASeqNumber( String apDn ) throws LdapException
+    {
+        Entry entry = adminConnection.lookup( apDn, "CollectiveAttributeSeqNumber" );
+        
+        EntryAttribute attribute = entry.get( ApacheSchemaConstants.COLLECTIVE_ATTRIBUTE_SEQ_NUMBER_AT
);
+        
+        if ( attribute == null )
+        {
+            return Long.MIN_VALUE;
+        }
+        
+        return Long.parseLong( attribute.getString() );
+    }
+    
+
+    protected boolean checkIsAbsent( String dn ) throws LdapException
+    {
+        Entry entry = adminConnection.lookup( dn );
+        
+        return entry == null;
+    }
+
+    
+    protected boolean checkIsPresent( String dn ) throws LdapException
+    {
+        Entry entry = adminConnection.lookup( dn );
+        
+        return entry != null;
+    }
+}

Modified: directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryAddOperationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryAddOperationIT.java?rev=1053703&r1=1053702&r2=1053703&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryAddOperationIT.java
(original)
+++ directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryAddOperationIT.java
Wed Dec 29 19:03:24 2010
@@ -25,22 +25,17 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.core.administrative.AdministrativePoint;
 import org.apache.directory.server.core.administrative.Subentry;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 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.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.message.AddResponse;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.DN;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -62,41 +57,8 @@ import org.junit.runner.RunWith;
         "sn: test",
         "userpassword: test"
     })
-public class SubentryAddOperationIT extends AbstractLdapTestUnit
+public class SubentryAddOperationIT extends AbstractSubentryUnitTest
 {
-    // The shared LDAP admin connection
-    private static LdapConnection adminConnection;
-
-    // The shared LDAP user connection
-    private static LdapConnection userConnection;
-
-
-    @Before
-    public void init() throws Exception
-    {
-        adminConnection = IntegrationUtils.getAdminConnection( service );
-        userConnection = IntegrationUtils.getConnectionAs( service, "cn=test,ou=system",
"test" );
-    }
-
-
-    @After
-    public void shutdown() throws Exception
-    {
-        adminConnection.close();
-        userConnection.close();
-    }
-
-
-    private Entry getAdminRole( String dn ) throws Exception
-    {
-        Entry lookup = adminConnection.lookup( dn, "administrativeRole" );
-
-        assertNotNull( lookup );
-
-        return lookup;
-    }
-
-
     // ===================================================================
     // Test the Add operation for APs
     // -------------------------------------------------------------------
@@ -876,4 +838,81 @@ public class SubentryAddOperationIT exte
     // -------------------------------------------------------------------
     // Success expected
     // -------------------------------------------------------------------
+    /**
+     * Test the addition of a SAP, SE and 2 entries
+     */
+    @Test
+    public void testAdd2Entries() throws Exception
+    {
+        // First add an SAP
+        Entry sap = LdifUtils.createEntry( 
+            "ou=SAP,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: organizationalUnit", 
+            "ou: SAP", 
+            "administrativeRole: collectiveAttributeSpecificArea" );
+
+        AddResponse response = adminConnection.add( sap );
+        assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );
+        assertEquals( -1L, getCASeqNumber( "ou=SAP,ou=system" ) );
+        
+        // Create a first entry
+        Entry e1 = LdifUtils.createEntry( 
+            "cn=e1,ou=SAP,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: person", 
+            "cn: e1", 
+            "sn: entry 1" );
+        
+        response = adminConnection.add( e1 );
+
+        assertEquals( -1L, getCASeqNumber( "cn=e1,ou=SAP,ou=system" ) );
+        
+        // Create a second entry
+        Entry e2 = LdifUtils.createEntry( 
+            "cn=e2,ou=SAP,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: person", 
+            "cn: e2", 
+            "sn: entry 2" );
+
+        response = adminConnection.add( e2 );
+
+        assertEquals( -1L, getCASeqNumber( "cn=e2,ou=SAP,ou=system" ) );
+
+        // Add a subentry now
+        Entry subentry = LdifUtils.createEntry( 
+            "cn=test,ou=SAP,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: subentry", 
+            "ObjectClass: collectiveAttributeSubentry",
+            "cn: test",
+            "subtreeSpecification: {}", 
+            "c-o: Test Org" );
+
+        response = adminConnection.add( subentry );
+        assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );
+        
+        // Get back the CA SeqNumber
+        long caSeqNumber = getCASeqNumber( "ou=SAP,ou=system" );
+        
+        assertTrue( caSeqNumber > -1L );
+        
+        // Create a third entry
+        Entry e3 = LdifUtils.createEntry( 
+            "cn=e3,ou=SAP,ou=system", 
+            "ObjectClass: top",
+            "ObjectClass: person", 
+            "cn: e3", 
+            "sn: entry 3" );
+
+        response = adminConnection.add( e3 );
+
+        // The CASeqNumber for this entry must be the same than it's AP
+        assertEquals( caSeqNumber, getCASeqNumber( "cn=e3,ou=SAP,ou=system" ) );
+
+        // Now, check that when we read the other entries, their CA seqNumber is also updated
+        assertEquals( caSeqNumber, getCASeqNumber( "cn=e1,ou=SAP,ou=system" ) );
+        assertEquals( caSeqNumber, getCASeqNumber( "cn=e2,ou=SAP,ou=system" ) );
+    }
 }

Modified: directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryDeleteOperationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryDeleteOperationIT.java?rev=1053703&r1=1053702&r2=1053703&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryDeleteOperationIT.java
(original)
+++ directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryDeleteOperationIT.java
Wed Dec 29 19:03:24 2010
@@ -24,22 +24,14 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 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.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.message.AddResponse;
 import org.apache.directory.shared.ldap.message.DeleteResponse;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -61,77 +53,8 @@ import org.junit.runner.RunWith;
         "sn: test",
         "userpassword: test"
     })
-public class SubentryDeleteOperationIT extends AbstractLdapTestUnit
+public class SubentryDeleteOperationIT extends AbstractSubentryUnitTest
 {
-    // The shared LDAP admin connection
-    private static LdapConnection adminConnection;
-
-    // The shared LDAP user connection
-    private static LdapConnection userConnection;
-
-
-    @Before
-    public void init() throws Exception
-    {
-        adminConnection = IntegrationUtils.getAdminConnection( service );
-        userConnection = IntegrationUtils.getConnectionAs( service, "cn=test,ou=system",
"test" );
-    }
-
-
-    @After
-    public void shutdown() throws Exception
-    {
-        adminConnection.close();
-        userConnection.close();
-    }
-
-
-    private long getACSeqNumber( String apDn ) throws LdapException
-    {
-        Entry entry = adminConnection.lookup( apDn, "AccessControlSeqNumber" );
-        
-        EntryAttribute attribute = entry.get( ApacheSchemaConstants.ACCESS_CONTROL_SEQ_NUMBER_AT
);
-        
-        if ( attribute == null )
-        {
-            return Long.MIN_VALUE;
-        }
-        
-        return Long.parseLong( attribute.getString() );
-    }
-
-    
-    private long getCASeqNumber( String apDn ) throws LdapException
-    {
-        Entry entry = adminConnection.lookup( apDn, "CollectiveAttributeSeqNumber" );
-        
-        EntryAttribute attribute = entry.get( ApacheSchemaConstants.COLLECTIVE_ATTRIBUTE_SEQ_NUMBER_AT
);
-        
-        if ( attribute == null )
-        {
-            return Long.MIN_VALUE;
-        }
-        
-        return Long.parseLong( attribute.getString() );
-    }
-    
-
-    private boolean checkIsAbsent( String dn ) throws LdapException
-    {
-        Entry entry = adminConnection.lookup( dn );
-        
-        return entry == null;
-    }
-
-    
-    private boolean checkIsPresent( String dn ) throws LdapException
-    {
-        Entry entry = adminConnection.lookup( dn );
-        
-        return entry != null;
-    }
-
-    
     // ===================================================================
     // Test the Delete operation on APs
     // -------------------------------------------------------------------



Mime
View raw message