directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r546311 - in /directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server: DITUtilitiesSP.java StoredProcedureTest.java TriggerServiceTest.java
Date Mon, 11 Jun 2007 22:55:13 GMT
Author: ersiner
Date: Mon Jun 11 15:55:12 2007
New Revision: 546311

URL: http://svn.apache.org/viewvc?view=rev&rev=546311
Log:
Minor cleanup for SP and Trigger code.
Added one more test for SP: deltree for LDAP.

Added:
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
Modified:
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/TriggerServiceTest.java

Added: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java?view=auto&rev=546311
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
(added)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DITUtilitiesSP.java
Mon Jun 11 15:55:12 2007
@@ -0,0 +1,64 @@
+/*
+ *  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;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DITUtilitiesSP
+{
+	private static final Logger log = LoggerFactory.getLogger( DITUtilitiesSP.class );
+	
+	/**
+     * Recursively deletes a subtree including the apex given.
+     * 
+     * If you do not want to wait for the developers to implement the
+     * following RFC
+     * http://kahuna.telstra.net/ietf/all-ids/draft-armijo-ldap-treedelete-02.txt
+     * you can do it yourself!
+     * 
+     * @param ctx an LDAP context to perform operations on
+     * @param rdn ctx relative name of the entry which is root of
+     *        the subtree to be deleted
+     * @throws NamingException
+     */
+    public static void deleteSubtree( LdapContext ctx, Name rdn ) throws NamingException
+    {
+        NamingEnumeration results = ctx.search( rdn, "(objectClass=*)", new SearchControls()
);
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            Name childRdn = new LdapDN( result.getName() );
+            childRdn.remove( 0 );
+            deleteSubtree( ctx, childRdn );
+        }
+        ctx.destroySubcontext( rdn );
+        log.info( "Deleted: " + rdn );
+    }
+}

Modified: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java?view=diff&rev=546311&r1=546310&r2=546311
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
(original)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
Mon Jun 11 15:55:12 2007
@@ -25,14 +25,18 @@
 import java.util.Hashtable;
 import java.util.Set;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.server.ldap.ExtendedOperationHandler;
 import org.apache.directory.server.ldap.LdapConfiguration;
 import org.apache.directory.server.ldap.support.extended.StoredProcedureExtendedOperationHandler;
 import org.apache.directory.server.unit.AbstractServerTest;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.sp.JavaStoredProcedureUtils;
+import org.apache.directory.shared.ldap.sp.LdapContextParameter;
 
 
 /**
@@ -46,8 +50,11 @@
     
     public void setUp() throws Exception
     {
+        /////////////////////////////////////////////////////////
+        // Enable the Stored Procedure Extended Operation Handler
+        /////////////////////////////////////////////////////////
         LdapConfiguration ldapCfg = super.configuration.getLdapConfiguration();
-        Set handlers = new HashSet( ldapCfg.getExtendedOperationHandlers() );
+        Set<ExtendedOperationHandler> handlers = new HashSet<ExtendedOperationHandler>(
ldapCfg.getExtendedOperationHandlers() );
         handlers.add( new StoredProcedureExtendedOperationHandler() );
         ldapCfg.setExtendedOperationHandlers( handlers );
 
@@ -60,8 +67,6 @@
         env.put( "java.naming.security.credentials", "secret" );
         env.put( "java.naming.security.authentication", "simple" );
         ctx = new InitialLdapContext( env, null );
-
-        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, HelloWorldProcedure.class
);
     }
 
 
@@ -74,23 +79,71 @@
     }
     
 
-    public void testExecuteProcedure() throws NamingException
+    public void testExecuteProcedureWithReturnValue() throws NamingException
     {
         String procedureName = HelloWorldProcedure.class.getName() + ".sayHello";
         
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, HelloWorldProcedure.class
);
+        
         Object response = JavaStoredProcedureUtils.callStoredProcedure( ctx, procedureName,
new Object[] { } );
         
         assertEquals( "Hello World!", response );
     }
     
 
-    public void testExecuteProcedureWithParameters() throws NamingException, IOException
+    public void testExecuteProcedureWithParametersAndReturnValue() throws NamingException,
IOException
     {
         String procedureName = HelloWorldProcedure.class.getName() + ".sayHelloTo";
         
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, HelloWorldProcedure.class
);
+        
         Object response = JavaStoredProcedureUtils.callStoredProcedure( ctx, procedureName,
new Object[] { "Ersin" } );
         
         assertEquals( "Hello Ersin!", response );
     }
     
+    
+    public void testSPDeleteSubtree() throws NamingException
+    {
+        String ldif =
+            "version: 1\n" +
+            "\n" +
+            "dn: ou=People,ou=system\n" +
+            "ou: People\n" +
+            "objectclass: organizationalUnit\n" +
+            "objectclass: top\n" +
+            "\n" + 
+            "dn: cn=John,ou=People,ou=system\n" +
+            "objectclass: person\n" +
+            "objectclass: top\n" +
+            "sn: John\n" +
+            "cn: John\n" +
+            "\n" +
+            "dn: cn=Jane,ou=People,ou=system\n" +
+            "objectclass: person\n" +
+            "objectclass: top\n" +
+            "sn: Jane\n" +
+            "cn: Jane\n";
+        
+        injectEntries( ldif );
+        
+        String spName = DITUtilitiesSP.class.getName() + ".deleteSubtree";
+        Object[] params = new Object[] { new LdapContextParameter( "ou=system" ),
+                                         new LdapDN( "ou=People" ) };
+        
+        JavaStoredProcedureUtils.callStoredProcedure( ctx, spName, params );
+        
+        try
+        {
+            sysRoot.lookup( "cn=Jane,ou=People" );
+            sysRoot.lookup( "cn=John,ou=People" );
+            sysRoot.lookup( "ou=People" );
+            fail( "We should not have come here." );
+        }
+        catch ( NameNotFoundException e )
+        {
+            // Expected
+        }
+    }
+     
 }

Modified: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/TriggerServiceTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/TriggerServiceTest.java?view=diff&rev=546311&r1=546310&r2=546311
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/TriggerServiceTest.java
(original)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/TriggerServiceTest.java
Mon Jun 11 15:55:12 2007
@@ -40,7 +40,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev:$
  */
-public class TriggerServiceTest extends AbstractServerTest // AbstractServerTriggerServiceTest
+public class TriggerServiceTest extends AbstractServerTest
 {
     private LdapContext ctx;
     
@@ -89,7 +89,7 @@
         // Inject the ldif file into the server
         injectEntries( ldif );
             
-        // Create the Triger Specification within a Trigger Subentry.
+        // Create the Trigger Specification within a Trigger Subentry.
         String staffDN = "cn=staff, ou=system";
         String teachersDN = "cn=teachers, ou=system";
 
@@ -103,6 +103,16 @@
                                                          "CALL \"" + ListUtilsSP.class.getName()
+ ".subscribeToGroup\" ( $entry , $ldapContext \"" + staffDN + "\" ); " +
                                                          "CALL \"" + ListUtilsSP.class.getName()
+ ".subscribeToGroup\" ( $entry , $ldapContext \"" + teachersDN + "\" );" );
         
+        /**
+         * The Trigger Specification without Java clutter:
+         * 
+         * AFTER Add
+         *     CALL "ListUtilsSP.subscribeToGroup" ( $entry , $ldapContext "cn=staff, ou=system"
);
+         *     CALL "ListUtilsSP.subscribeToGroup" ( $entry , $ldapContext "cn=teachers,
ou=system" );
+         * 
+         */
+        
+        
         // Create a test entry which is selected by the Trigger Subentry.
         String testEntry  = 
             "version: 1\n" +
@@ -142,10 +152,10 @@
             "objectClass: organizationalUnit\n" +
             "ou: backupContext\n";
         
-        // Inject the ldif file into the server
+        // Inject the ldif file into the server.
         injectEntries( ldif );
         
-        // Create the Triger Specification within a Trigger Subentry.
+        // Create the Trigger Specification within a Trigger Subentry.
         TriggerUtils.defineTriggerExecutionSpecificPoint( ctx );
         TriggerUtils.createTriggerExecutionSubentry( ctx,
                                                      "triggerSubentry1",
@@ -154,16 +164,26 @@
                                                          "CALL \"" + BackupUtilitiesSP.class.getName()
+ ".backupDeleted\" " +
                                                              " ( $ldapContext \"\", $name,
$operationPrincipal, $deletedEntry );" );        
 
+        
+        /**
+         * The Trigger Specification without Java clutter:
+         * 
+         * AFTER Delete
+         *     CALL "BackupUtilitiesSP.backupDeleted" ( $ldapContext "", $name, $operationPrincipal,
$deletedEntry );
+         * 
+         */
+        
+        
         // Create a test entry which is selected by the Trigger Subentry.
         String ldif2  = 
             "version: 1\n" +
             "\n" +
-            "dn: ou=testou, ou=system\n"+
+            "dn: ou=testou, ou=system\n" +
             "objectClass: top\n" +
             "objectClass: organizationalUnit\n" +
             "ou: testou\n";
         
-        // Inject the ldif file into the server
+        // Inject the ldif file into the server.
         injectEntries( ldif2 );
         
         // Delete the test entry in order to fire the Trigger.



Mime
View raw message