directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r602513 - in /directory/apacheds/branches/bigbang: core-integ/src/main/java/org/apache/directory/server/core/integ/ core-integ/src/test/java/org/apache/directory/server/core/ core-integ/src/test/java/org/apache/directory/server/core/trigger...
Date Sat, 08 Dec 2007 17:15:05 GMT
Author: akarasulu
Date: Sat Dec  8 09:15:02 2007
New Revision: 602513

URL: http://svn.apache.org/viewvc?rev=602513&view=rev
Log:
converting the trigger tests

Added:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/
      - copied from r601982, directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/trigger/
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorIT.java   (with props)
Removed:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorITest.java
    directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/trigger/
Modified:
    directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/ListUtilsSP.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/LoggingUtilities.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/sp/StoredProcExecutionManager.java

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=602513&r1=602512&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Sat Dec  8 09:15:02 2007
@@ -25,6 +25,7 @@
 import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
 import org.apache.directory.shared.ldap.ldif.ChangeType;
 import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.slf4j.Logger;
@@ -35,6 +36,7 @@
 import javax.naming.ldap.LdapContext;
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 
 /**
@@ -70,6 +72,27 @@
         if ( wkdir.exists() )
         {
             throw new IOException( "Failed to delete: " + wkdir );
+        }
+    }
+
+
+    /**
+     * Inject an ldif String into the server. DN must be relative to the
+     * root.
+     *
+     * @param service the directory service to use 
+     * @param ldif the ldif containing entries to add to the server.
+     * @throws NamingException if there is a problem adding the entries from the LDIF
+     */
+    public static void injectEntries( DirectoryService service, String ldif ) throws NamingException
+    {
+        LdapContext rootDSE = getRootContext( service );
+        LdifReader reader = new LdifReader();
+        List<Entry> entries = reader.parseLdif( ldif );
+
+        for ( Entry entry : entries )
+        {
+            rootDSE.createSubcontext( new LdapDN( entry.getDn() ), entry.getAttributes() );
         }
     }
 

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java?rev=602513&r1=602512&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java Sat Dec  8 09:15:02 2007
@@ -31,6 +31,8 @@
 import org.apache.directory.server.core.jndi.*;
 import org.apache.directory.server.core.operational.OperationalAttributeServiceIT;
 import org.apache.directory.server.core.prefs.PreferencesIT;
+import org.apache.directory.server.core.trigger.SubentryServiceForTriggersIT;
+import org.apache.directory.server.core.trigger.TriggerInterceptorIT;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
@@ -64,6 +66,8 @@
         UniqueMemberIT.class,
         OperationalAttributeServiceIT.class,
         PreferencesIT.class,
+        TriggerInterceptorIT.class,
+        SubentryServiceForTriggersIT.class,
         PartitionConfigurationIT.class  // Leaves the server in a bad state (partition removal is incomplete)
         } )
 @Scope ( ServiceScope.TESTSUITE )

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java?rev=602513&r1=601982&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java Sat Dec  8 09:15:02 2007
@@ -34,19 +34,23 @@
  */
 public class BackupUtilities
 {
-    private static final Logger log = LoggerFactory.getLogger( BackupUtilities.class );
+    private static final Logger LOG = LoggerFactory.getLogger( BackupUtilities.class );
 
-    public static void backupDeleted( LdapContext ctx, Name deletedEntryName, Name operationPrincipal, Attributes deletedEntry ) throws NamingException
+
+    public static void backupDeleted( LdapContext ctx, Name deletedEntryName,
+                                      Name operationPrincipal, Attributes deletedEntry ) throws NamingException
     {
-        log.info( "User \"" + operationPrincipal + "\" has deleted entry \"" + deletedEntryName + "\"" );
-        log.info( "Entry content was: " + deletedEntry );
+        LOG.info( "User \"" + operationPrincipal + "\" has deleted entry \"" + deletedEntryName + "\"" );
+        LOG.info( "Entry content was: " + deletedEntry );
         LdapContext backupCtx = ( LdapContext ) ctx.lookup( "ou=backupContext,ou=system" );
         String deletedEntryRdn = deletedEntryName.get( deletedEntryName.size() - 1 );
         backupCtx.createSubcontext( deletedEntryRdn, deletedEntry );
-        log.info( "Backed up deleted entry to \"" + ( ( LdapContext ) backupCtx.lookup( deletedEntryRdn ) ).getNameInNamespace() + "\"" );
+        LOG.info( "Backed up deleted entry to \"" +
+                ( ( LdapContext ) backupCtx.lookup( deletedEntryRdn ) ).getNameInNamespace() + "\"" );
     }
     
-    public static void duplicateDeletedEntry( LdapContext ctx, Name deletedEntryName, Name operationPrincipal, Attributes deletedEntry ) throws NamingException
+    public static void duplicateDeletedEntry( LdapContext ctx, Name deletedEntryName, Name operationPrincipal,
+                                              Attributes deletedEntry ) throws NamingException
     {
         LdapContext backupCtx = ( LdapContext ) ctx.lookup( "ou=backupContext,ou=system" );
         String deletedEntryRdn = deletedEntryName.get( deletedEntryName.size() - 1 );

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java?rev=602513&r1=601982&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/BackupUtilitiesSP.java Sat Dec  8 09:15:02 2007
@@ -30,16 +30,18 @@
 
 public class BackupUtilitiesSP
 {
-    private static final Logger log = LoggerFactory.getLogger( BackupUtilitiesSP.class );
+    private static final Logger LOG = LoggerFactory.getLogger( BackupUtilitiesSP.class );
 
 
-    public static void backupDeleted( LdapContext ctx, Name deletedEntryName, Name operationPrincipal, Attributes deletedEntry ) throws NamingException
+    public static void backupDeleted( LdapContext ctx, Name deletedEntryName,
+                                      Name operationPrincipal, Attributes deletedEntry ) throws NamingException
     {
-        log.info( "User \"" + operationPrincipal + "\" has deleted entry \"" + deletedEntryName + "\"" );
-        log.info( "Entry content was: " + deletedEntry );
+        LOG.info( "User \"" + operationPrincipal + "\" has deleted entry \"" + deletedEntryName + "\"" );
+        LOG.info( "Entry content was: " + deletedEntry );
         LdapContext backupCtx = ( LdapContext ) ctx.lookup( "ou=backupContext,ou=system" );
         String deletedEntryRdn = deletedEntryName.get( deletedEntryName.size() - 1 );
         backupCtx.createSubcontext( deletedEntryRdn, deletedEntry );
-        log.info( "Backed up deleted entry to \"" + ( ( LdapContext ) backupCtx.lookup( deletedEntryRdn ) ).getNameInNamespace() + "\"" );
+        LOG.info( "Backed up deleted entry to \"" +
+                ( ( LdapContext ) backupCtx.lookup( deletedEntryRdn ) ).getNameInNamespace() + "\"" );
     }
 }

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/ListUtilsSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/ListUtilsSP.java?rev=602513&r1=601982&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/ListUtilsSP.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/ListUtilsSP.java Sat Dec  8 09:15:02 2007
@@ -32,13 +32,14 @@
 
 public class ListUtilsSP
 {
-    private static final Logger log = LoggerFactory.getLogger( ListUtilsSP.class );
+    private static final Logger LOG = LoggerFactory.getLogger( ListUtilsSP.class );
 
 
     public static void subscribeToGroup( Name addedEntryName, LdapContext groupCtx ) throws NamingException
     {
-        log.info( "User \"" + addedEntryName + "\" will be subscribed to \"" + groupCtx + "\"" );
-        groupCtx.modifyAttributes("", DirContext.ADD_ATTRIBUTE, new BasicAttributes( SchemaConstants.UNIQUE_MEMBER_AT, addedEntryName.toString(), true ) );
-        log.info( "Subscription OK." );
+        LOG.info( "User \"" + addedEntryName + "\" will be subscribed to \"" + groupCtx + "\"" );
+        groupCtx.modifyAttributes("", DirContext.ADD_ATTRIBUTE,
+                new BasicAttributes( SchemaConstants.UNIQUE_MEMBER_AT, addedEntryName.toString(), true ) );
+        LOG.info( "Subscription OK." );
     }
 }

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/LoggingUtilities.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/LoggingUtilities.java?rev=602513&r1=601982&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/LoggingUtilities.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/LoggingUtilities.java Sat Dec  8 09:15:02 2007
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.trigger;
 
+
 import javax.naming.Name;
 import javax.naming.NamingException;
 
@@ -32,10 +33,11 @@
  */
 public class LoggingUtilities
 {
-    private static final Logger log = LoggerFactory.getLogger( LoggingUtilities.class ); 
+    private static final Logger LOG = LoggerFactory.getLogger( LoggingUtilities.class );
     
-    public static void logWarningForDeletedEntry( Name deletedEntryName, Name operationPrincipal ) throws NamingException
+    public static void logWarningForDeletedEntry( Name deletedEntryName,
+                                                  Name operationPrincipal ) throws NamingException
     {
-        log.info( "User \"" + operationPrincipal + "\" is about to delete entry \"" + deletedEntryName + "\"." );
+        LOG.info( "User \"" + operationPrincipal + "\" is about to delete entry \"" + deletedEntryName + "\"." );
     }
 }

Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersIT.java?rev=602513&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersIT.java (added)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersIT.java Sat Dec  8 09:15:02 2007
@@ -0,0 +1,572 @@
+/*
+ *  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.trigger;
+
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapNoSuchAttributeException;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.*;
+import javax.naming.ldap.LdapContext;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Testcases for the SubentryInterceptor for Triggers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$
+ */
+@RunWith ( CiRunner.class )
+@Ignore ( "Reverts are failing to delete marked entries. Fixing this " +
+        "problem in testEntryAdd() will fix it all over." )
+public class SubentryServiceForTriggersIT
+{
+    public static DirectoryService service;
+
+
+    public Attributes getTestEntry( String cn )
+    {
+        Attributes subentry = new AttributesImpl();
+        Attribute objectClass = new AttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "person" );
+        subentry.put( objectClass );
+        subentry.put( "cn", cn );
+        subentry.put( "sn", "testentry" );
+        return subentry;
+    }
+
+
+    public Attributes getTestSubentry()
+    {
+        Attributes subentry = new AttributesImpl();
+        Attribute objectClass = new AttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( SchemaConstants.SUBENTRY_OC );
+        objectClass.add( "triggerExecutionSubentry" );
+        subentry.put( objectClass );
+        subentry.put( "subtreeSpecification", "{ base \"ou=configuration\" }" );
+        subentry.put( "prescriptiveTriggerSpecification", "AFTER Delete CALL \"LogUtils.logDelete\"($name);" );
+        subentry.put( "cn", "testsubentry" );
+        return subentry;
+    }
+    
+    public Attributes getTestSubentryWithExclusion()
+    {
+        Attributes subentry = new AttributesImpl();
+        Attribute objectClass = new AttributeImpl( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( SchemaConstants.SUBENTRY_OC );
+        objectClass.add( "triggerExecutionSubentry" );
+        subentry.put( objectClass );
+        String spec = "{ base \"ou=configuration\", specificExclusions { chopBefore:\"cn=unmarked\" } }";
+        subentry.put( "subtreeSpecification", spec );
+        subentry.put( "prescriptiveTriggerSpecification", "AFTER Delete CALL \"LogUtils.logDelete\"($name);" );
+        subentry.put( "cn", "testsubentry" );
+        return subentry;
+    }
+
+
+    public void addTheAdministrativeRole() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        Attribute attribute = new AttributeImpl( "administrativeRole" );
+        attribute.add( "autonomousArea" );
+        attribute.add( "triggerSpecificArea" );
+        ModificationItemImpl item = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, attribute );
+        sysRoot.modifyAttributes( "", new ModificationItemImpl[] { item } );
+    }
+
+
+    public Map<String, Attributes> getAllEntries() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        Map<String, Attributes> resultMap = new HashMap<String, Attributes>();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        controls.setReturningAttributes( new String[]
+            { "+", "*" } );
+        NamingEnumeration results = sysRoot.search( "", "(objectClass=*)", controls );
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            resultMap.put( result.getName(), result.getAttributes() );
+        }
+        return resultMap;
+    }
+
+
+    @Test
+    public void testEntryAdd() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        addTheAdministrativeRole();        
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+        sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
+        sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
+        Attribute triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes unmarked = results.get( "cn=unmarked,ou=system" );
+        assertNull( "cn=unmarked,ou=system should not be marked", unmarked
+            .get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        // @todo attempts to delete this entry cause an StringIndexOutOfBoundsException
+        sysRoot.destroySubcontext( "cn=marked,ou=configuration" );
+    }
+
+
+    @Test
+    public void testSubentryAdd() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+
+        //noinspection EmptyCatchBlock
+        try
+        {
+            sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+            fail( "should never get here: cannot create subentry under regular entries" );
+        }
+        catch ( LdapNoSuchAttributeException e )
+        {
+        }
+
+        addTheAdministrativeRole();
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+    }
+
+
+    @Test
+    public void testSubentryModify() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        addTheAdministrativeRole();
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        // --------------------------------------------------------------------
+        // Now modify the subentry by introducing an exclusion
+        // --------------------------------------------------------------------
+
+        Attribute subtreeSpecification = new AttributeImpl( "subtreeSpecification" );
+        subtreeSpecification.add( "{ base \"ou=configuration\", specificExclusions { chopBefore:\"ou=interceptors\" } }" );
+        ModificationItemImpl item = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, subtreeSpecification );
+        sysRoot.modifyAttributes( "cn=testsubentry", new ModificationItemImpl[] { item } );
+        results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        configuration = results.get( "ou=configuration,ou=system" );
+        triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        if ( triggerSubentries != null )
+        {
+            assertEquals( "ou=interceptors,ou=configuration,ou=system should not be marked", 0, triggerSubentries.size() );
+        }
+    }
+
+
+    @Test
+    public void testSubentryDelete() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        addTheAdministrativeRole();
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+        sysRoot.destroySubcontext( "cn=testsubentry" );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        if ( triggerSubentries != null )
+        {
+            assertEquals( "ou=configuration,ou=system should not be marked", 0, triggerSubentries.size() );
+        }
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        if ( triggerSubentries != null )
+        {
+            assertEquals( "ou=interceptors,ou=configuration,ou=system should not be marked", 0, triggerSubentries.size() );
+        }
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+    }
+
+
+    @Test
+    public void testSubentryModifyRdn() throws NamingException
+    {
+        addTheAdministrativeRole();
+        LdapContext sysRoot = getSystemContext( service );
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
+        sysRoot.rename( "cn=testsubentry", "cn=newname" );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=newname,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=newname,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+    }
+
+
+    @Test
+    public void testEntryModifyRdn() throws NamingException
+    {
+        addTheAdministrativeRole();
+        LdapContext sysRoot = getSystemContext( service );
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
+        sysRoot.createSubcontext( "cn=unmarked,ou=configuration", getTestEntry( "unmarked" ) );
+        sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
+        triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes unmarked = results.get( "cn=unmarked,ou=configuration,ou=system" );
+        assertNull( "cn=unmarked,ou=configuration,ou=system should not be marked", unmarked
+            .get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        // --------------------------------------------------------------------
+        // Now destry one of the marked/unmarked and rename to deleted entry
+        // --------------------------------------------------------------------
+
+        sysRoot.destroySubcontext( "cn=unmarked,ou=configuration" );
+        sysRoot.rename( "cn=marked,ou=configuration", "cn=unmarked,ou=configuration" );
+        results = getAllEntries();
+
+        unmarked = results.get( "cn=unmarked,ou=configuration,ou=system" );
+        assertNull( "cn=unmarked,ou=configuration,ou=system should not be marked", unmarked
+            .get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+        assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
+
+        // --------------------------------------------------------------------
+        // Now rename unmarked to marked and see that subentry op attr is there
+        // --------------------------------------------------------------------
+
+        sysRoot.rename( "cn=unmarked,ou=configuration", "cn=marked,ou=configuration" );
+        results = getAllEntries();
+        assertNull( results.get( "cn=unmarked,ou=configuration,ou=system" ) );
+        marked = results.get( "cn=marked,ou=configuration,ou=system" );
+        assertNotNull( marked );
+        triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+    }
+
+
+    @Test
+    public void testEntryMoveWithRdnChange() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        addTheAdministrativeRole();
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
+        sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
+        sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
+        triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes unmarked = results.get( "cn=unmarked,ou=system" );
+        assertNull( "cn=unmarked,ou=system should not be marked", unmarked
+            .get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        // --------------------------------------------------------------------
+        // Now destry one of the marked/unmarked and rename to deleted entry
+        // --------------------------------------------------------------------
+
+        sysRoot.destroySubcontext( "cn=unmarked" );
+        sysRoot.rename( "cn=marked,ou=configuration", "cn=unmarked" );
+        results = getAllEntries();
+
+        unmarked = results.get( "cn=unmarked,ou=system" );
+        assertNull( "cn=unmarked,ou=system should not be marked", unmarked
+            .get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+        assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
+
+        // --------------------------------------------------------------------
+        // Now rename unmarked to marked and see that subentry op attr is there
+        // --------------------------------------------------------------------
+
+        sysRoot.rename( "cn=unmarked", "cn=marked,ou=configuration" );
+        results = getAllEntries();
+        assertNull( results.get( "cn=unmarked,ou=system" ) );
+        marked = results.get( "cn=marked,ou=configuration,ou=system" );
+        assertNotNull( marked );
+        triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+    }
+
+
+    @Test
+    public void testEntryMove() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        addTheAdministrativeRole();
+        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
+        sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
+        sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
+        Map<String, Attributes> results = getAllEntries();
+
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+
+        Attributes configuration = results.get( "ou=configuration,ou=system" );
+        Attribute triggerSubentries = configuration.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
+        triggerSubentries = interceptors.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
+        triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+
+        Attributes system = results.get( "ou=system" );
+        assertNull( "ou=system should not be marked", system.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes users = results.get( "ou=users,ou=system" );
+        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        Attributes unmarked = results.get( "cn=unmarked,ou=system" );
+        assertNull( "cn=unmarked,ou=system should not be marked", unmarked
+            .get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT ) );
+
+        // --------------------------------------------------------------------
+        // Now destry one of the marked/unmarked and rename to deleted entry
+        // --------------------------------------------------------------------
+
+        sysRoot.destroySubcontext( "cn=unmarked" );
+        sysRoot.rename( "cn=marked,ou=configuration", "cn=marked,ou=interceptors,ou=configuration" );
+        results = getAllEntries();
+
+        unmarked = results.get( "cn=unmarked,ou=system" );
+        assertNull( "cn=unmarked,ou=system should not be marked", unmarked );
+        assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
+
+        marked = results.get( "cn=marked,ou=interceptors,ou=configuration,ou=system" );
+        assertNotNull( marked );
+        triggerSubentries = marked.get( SchemaConstants.TRIGGER_EXECUTION_SUBENTRIES_AT );
+        assertNotNull( "cn=marked,ou=interceptors,ou=configuration should be marked", triggerSubentries );
+        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", triggerSubentries.get() );
+        assertEquals( 1, triggerSubentries.size() );
+    }
+
+}

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/SubentryServiceForTriggersIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorIT.java?rev=602513&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorIT.java (added)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorIT.java Sat Dec  8 09:15:02 2007
@@ -0,0 +1,248 @@
+/*
+ *  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.trigger;
+
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import static org.apache.directory.server.core.integ.IntegrationUtils.injectEntries;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.sp.JavaStoredProcUtils;
+import org.apache.directory.shared.ldap.trigger.TriggerUtils;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.LdapContext;
+
+
+/**
+ * Integration tests for TriggerInterceptor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$
+ */
+@RunWith ( CiRunner.class )
+public class TriggerInterceptorIT
+{
+    public static DirectoryService service;
+
+    LdapContext spCtx;
+
+
+    /*
+     * @todo replace this with an ldif annotation
+     */
+    public void createData( LdapContext ctx ) throws NamingException
+    {
+        Attributes spContainer = new AttributesImpl( "objectClass", "top", true );
+        spContainer.get( "objectClass" ).add( "organizationalUnit" );
+        spContainer.put( "ou", "Stored Procedures" );
+        spCtx = ( LdapContext ) ctx.createSubcontext( "ou=Stored Procedures", spContainer );
+    }
+    
+
+    @Test
+    public void testAfterDeleteBackupDeletedEntryEntryTrigger() throws NamingException
+    {
+        String ldif  = 
+            "version: 1\n" +
+            "\n" +
+            "dn: ou=backupContext, ou=system\n"+
+            "objectClass: top\n" +
+            "objectClass: organizationalUnit\n" +
+            "ou: backupContext\n" +
+            "\n" +
+            "dn: ou=testEntry, ou=system\n" +
+            "objectClass: top\n" +
+            "objectClass: organizationalUnit\n" +
+            "ou: testEntry\n";
+
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        // Inject the ldif file into the server.
+        injectEntries( service, ldif );
+        
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        JavaStoredProcUtils.loadStoredProcedureClass( spCtx, BackupUtilitiesSP.class );
+        
+        // Create the Entry Trigger Specification.
+        TriggerUtils.defineTriggerExecutionSpecificPoint( sysRoot );
+        LdapContext entry = ( LdapContext ) sysRoot.lookup( "ou=testEntry" );
+        String triggerSpec = "AFTER Delete CALL \"" + BackupUtilitiesSP.class.getName() +
+            ":backupDeleted\" ( $ldapContext \"\", $name, $operationPrincipal, $deletedEntry );";
+        TriggerUtils.loadEntryTriggerSpecification( entry, triggerSpec );
+        
+        // Delete the test entry in order to fire the Trigger.
+        sysRoot.destroySubcontext( "ou=testEntry" );
+        
+        // ------------------------------------------
+        // The trigger should be fired at this point.
+        // ------------------------------------------
+        
+        // Check if the Trigger really worked (backed up the deleted entry).
+        assertNotNull( sysRoot.lookup( "ou=testEntry,ou=backupContext" ) );
+    }
+    
+    
+    public void testAfterDeleteBackupDeletedEntryPrescriptiveTrigger() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        JavaStoredProcUtils.loadStoredProcedureClass( spCtx, BackupUtilitiesSP.class );
+        
+        // Create a container for backing up deleted entries.
+        String ldif  = 
+            "version: 1\n" +
+            "\n" +
+            "dn: ou=backupContext, ou=system\n"+
+            "objectClass: top\n" +
+            "objectClass: organizationalUnit\n" +
+            "ou: backupContext\n";
+        
+        // Inject the ldif file into the server.
+        injectEntries( service, ldif );
+        
+        // Create the Trigger Specification within a Trigger Subentry.
+        TriggerUtils.defineTriggerExecutionSpecificPoint( sysRoot );
+        TriggerUtils.createTriggerExecutionSubentry( sysRoot,
+                                                     "triggerSubentry1",
+                                                     "{}",
+                                                     "AFTER Delete " +
+                                                         "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" +
+            "objectClass: top\n" +
+            "objectClass: organizationalUnit\n" +
+            "ou: testou\n";
+        
+        // Inject the ldif file into the server.
+        injectEntries( service, ldif2 );
+        
+        // Delete the test entry in order to fire the Trigger.
+        sysRoot.destroySubcontext( "ou=testou" );
+        
+        // ------------------------------------------
+        // The trigger should be fired at this point.
+        // ------------------------------------------
+        
+        // Check if the Trigger really worked (backed up the deleted entry).
+        assertNotNull( sysRoot.lookup( "ou=testou,ou=backupContext" ) );
+    }
+    
+    
+    public void testAfterAddSubscribeUserToSomeGroupsPrescriptiveTrigger() throws NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        // Create two groups to be subscribed to : staff and teachers.
+        String ldif  = 
+            "version: 1\n" +
+            "\n" +
+            "dn: cn=staff, ou=system\n"+
+            "objectClass: top\n" +
+            "objectClass: groupOfUniqueNames\n" +
+            "uniqueMember: cn=dummy\n"+
+            "cn: staff\n" +
+            "\n" +
+            "dn: cn=teachers, ou=system\n"+
+            "objectClass: top\n" +
+            "objectClass: groupOfUniqueNames\n" +
+            "uniqueMember: cn=dummy\n"+
+            "cn: teachers\n";
+        
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        JavaStoredProcUtils.loadStoredProcedureClass( spCtx, ListUtilsSP.class );
+
+        // Inject the ldif file into the server
+        injectEntries( service, ldif );
+            
+        // Create the Trigger Specification within a Trigger Subentry.
+        String staffDN = "cn=staff, ou=system";
+        String teachersDN = "cn=teachers, ou=system";
+
+        
+        // Create the Triger Specification within a Trigger Subentry.
+        TriggerUtils.defineTriggerExecutionSpecificPoint( sysRoot );
+        TriggerUtils.createTriggerExecutionSubentry( sysRoot,
+                                                     "triggerSubentry1",
+                                                     "{}",
+                                                     "AFTER Add " +
+                                                         "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" +
+            "\n" +
+            "dn: cn=The Teacher of All Times, ou=system\n"+
+            "objectClass: top\n" +
+            "objectClass: inetOrgPerson\n" +
+            "cn: The Teacher of All Times\n" +
+            "sn: TheTeacher";
+
+        // Inject the entry into the server
+        injectEntries( service, testEntry );
+
+        // ------------------------------------------
+        // The trigger should be fired at this point.
+        // ------------------------------------------
+        
+        // Check if the Trigger really worked (subscribed the user to the groups).
+        Attributes staff = sysRoot.getAttributes( "cn=staff" );
+        Attributes teachers = sysRoot.getAttributes( "cn=teachers" );
+        String testEntryName = ( ( LdapContext )sysRoot.lookup( "cn=The Teacher of All Times" ) ).getNameInNamespace();
+        assertTrue( AttributeUtils.containsValueCaseIgnore( staff.get( "uniqueMember" ), testEntryName ) );
+        assertTrue( AttributeUtils.containsValueCaseIgnore( teachers.get( "uniqueMember" ), testEntryName ) );
+    }
+ 
+}

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/trigger/TriggerInterceptorIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/sp/StoredProcExecutionManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/sp/StoredProcExecutionManager.java?rev=602513&r1=602512&r2=602513&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/sp/StoredProcExecutionManager.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/sp/StoredProcExecutionManager.java Sat Dec  8 09:15:02 2007
@@ -23,7 +23,6 @@
 
 
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.util.AttributeUtils;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -77,8 +76,7 @@
         String spUnitName = StoredProcUtils.extractStoredProcUnitName( fullSPName );
         String filter = "(storedProcUnitName=" + spUnitName + ")";
         NamingEnumeration<SearchResult> results = rootDSE.search( storedProcContainer, filter, controls );
-        Attributes spUnitEntry = results.nextElement().getAttributes();
-        return spUnitEntry;
+        return results.nextElement().getAttributes();
     }
 
 



Mime
View raw message