directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r415006 - in /directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger: BackupUtilities.java DefaulTriggerServiceTest.java
Date Sat, 17 Jun 2006 08:20:27 GMT
Author: ersiner
Date: Sat Jun 17 01:20:27 2006
New Revision: 415006

URL: http://svn.apache.org/viewvc?rev=415006&view=rev
Log:
Replaced Trigger Service tests with a one which make more sense.
We have AFTER DELETE Triggers and Stored Procedures working now!

Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/DefaulTriggerServiceTest.java

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java?rev=415006&r1=415005&r2=415006&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/BackupUtilities.java
Sat Jun 17 01:20:27 2006
@@ -1,14 +1,19 @@
 package org.apache.directory.server.core.trigger;
 
 import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
 
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 
 
 public class BackupUtilities
 {
-    public static void backupDeleted( ServerLdapContext ctx, Name name )
+    public static void backupDeleted( ServerLdapContext ctx, Name deletedEntryName, Attributes
deletedEntry ) throws NamingException
     {
-        System.out.println( "Backing up: " + name );
+        System.out.println( "Backing up deleted entry: " + deletedEntryName );
+        System.out.println( "Entry content is: " + deletedEntry );
+        ServerLdapContext backupCtx = ( ServerLdapContext ) ctx.lookup( "ou=backupContext,ou=system"
);
+        backupCtx.createSubcontext( deletedEntryName.get( 1 ), deletedEntry );
     }
 }

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/DefaulTriggerServiceTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/DefaulTriggerServiceTest.java?rev=415006&r1=415005&r2=415006&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/DefaulTriggerServiceTest.java
(original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/directory/server/core/trigger/DefaulTriggerServiceTest.java
Sat Jun 17 01:20:27 2006
@@ -29,87 +29,74 @@
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
 
-import org.apache.directory.shared.ldap.name.LdapDN;
-
 
 /**
- * Unit tests for TriggerService.
+ * Integration tests for TriggerService.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev:$
  */
 public class DefaulTriggerServiceTest extends AbstractTriggerServiceTest
 {
-    public void testOne() throws NamingException
+    private void loadStoredProcedure( String spClass ) throws NamingException
     {
+        URL url = getClass().getResource( spClass + ".class" );
+        InputStream in = getClass().getResourceAsStream( spClass + ".class" );
+        File file = new File( url.getFile() );
+        int size = ( int ) file.length();
+        byte[] buf = new byte[size];
+        try
+        {
+            in.read( buf );
+            in.close();
+        }
+        catch ( IOException e )
+        {
+            NamingException ne = new NamingException();
+            ne.setRootCause( e );
+            throw ne;
+        }
         
-        createTriggerSubentry( "triggerSubentry1", "BEFORE delete CALL \"" +
-                "org.apache.directory.server.core.trigger.BackupUtilities.backupDeleted\"
( $deletedEntry )" );
-        createTriggerSubentry( "triggerSubentry2", "AFTER delete CALL \"" +
-                "org.apache.directory.server.core.trigger.Logger.logDelete\" { language \"Java\"
} ( $name )" );
+        String fullClassName = getClass().getPackage() + "." + spClass;
         
-        Attributes testEntry = new BasicAttributes( "ou", "testou", true );
-        Attribute objectClass = new BasicAttribute( "objectClass" );
-        testEntry.put( objectClass );
-        objectClass.add( "top" );
-        objectClass.add( "organizationalUnit" );
-        sysRoot.createSubcontext( "ou=testou", testEntry );
-        
-        addEntryTrigger( new LdapDN( "ou=testou" ), "AFTER delete CALL \"" +
-                "org.apache.directory.server.core.trigger.Audit.userDeletedAnEntry\" ( $deletedEntry,
$operationPrincipal )" );
+        Attributes attributes = new BasicAttributes( "objectClass", "top", true );
+        attributes.get( "objectClass" ).add( "javaClass" );
+        attributes.put( "fullyQualifiedClassName", fullClassName );
+        attributes.put( "byteCode", buf );
         
-        sysRoot.destroySubcontext( "ou=testou" );
-
+        sysRoot.createSubcontext( "fullyQualifiedClassName=" + fullClassName, attributes
);
     }
     
-    
-    public void testTwo() throws NamingException
+    public void testAfterDeleteBackupDeletedEntry() throws NamingException
     {
+        // Load the stored procedure to be triggered.
+        loadStoredProcedure( "BackupUtilities" );
         
-        createTriggerSubentry( "myTriggerSubentry1", "AFTER delete CALL \"" +
-                "org.apache.directory.server.core.trigger.Logger.logDelete\" { language \"Java\"
} ( $name )" );
-        createTriggerSubentry( "myTriggerSubentry2", "INSTEADOF delete CALL \"" +
-                "org.apache.directory.server.core.trigger.Restrictions.noDelete\" ( $deletedEntry
)" );
-        createTriggerSubentry( "myTriggerSubentry3", "INSTEADOF add CALL \"" +
-                "org.apache.directory.server.core.trigger.Restrictions.noAdd\" ( $entry )"
);
-        
-        Attributes testEntry = new BasicAttributes( "ou", "testou", true );
+        // Create a container for backing up deleted entries.
+        Attributes backupContext = new BasicAttributes( "ou", "backupContext", true );
         Attribute objectClass = new BasicAttribute( "objectClass" );
-        testEntry.put( objectClass );
+        backupContext.put( objectClass );
         objectClass.add( "top" );
         objectClass.add( "organizationalUnit" );
-        sysRoot.createSubcontext( "ou=testou", testEntry );
+        sysRoot.createSubcontext( "ou=backupContext", backupContext );
         
-        sysRoot.destroySubcontext( "ou=testou" );
-    }
-    
-    
-    public void testThree() throws NamingException, IOException
-    {
-        URL url = getClass().getResource( "HelloWorldProcedure.class" );
-        InputStream in = getClass().getResourceAsStream( "HelloWorldProcedure.class" );
-        File file = new File( url.getFile() );
-        int size = ( int ) file.length();
-        byte[] buf = new byte[size];
-        in.read( buf );
-        in.close();
-        
-        Attributes attributes = new BasicAttributes( "objectClass", "top", true );
-        attributes.get( "objectClass" ).add( "javaClass" );
-        attributes.put( "fullyQualifiedClassName", HelloWorldProcedure.class.getName() );
-        attributes.put( "byteCode", buf );
-        sysRoot.createSubcontext( "fullyQualifiedClassName=" + HelloWorldProcedure.class.getName(),
attributes );
-        
-        createTriggerSubentry( "myTriggerSubentry1", "AFTER delete CALL \"" + HelloWorldProcedure.class.getName()
+ ".logDeleted" + "\" ( $name )" );
+        // Create the Triger Specification via the Trigger Subentry.
+        createTriggerSubentry( "triggerSubentry1", "AFTER delete CALL \"" +
+            "org.apache.directory.server.core.trigger.BackupUtilities.backupDeleted\" ( $name,
$deletedEntry )" );
         
+        // Create a test entry which is selected by the Trigger Subentry.
         Attributes testEntry = new BasicAttributes( "ou", "testou", true );
-        Attribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass = new BasicAttribute( "objectClass" );
         testEntry.put( objectClass );
         objectClass.add( "top" );
         objectClass.add( "organizationalUnit" );
         sysRoot.createSubcontext( "ou=testou", testEntry );
         
+        // Delete the test entry in order to fire the Trigger!
         sysRoot.destroySubcontext( "ou=testou" );
-
+        
+        // Check if the Trigger really worked (backed up the deleted entry).
+        assertNotNull( sysRoot.lookup( "ou=testou," + "ou=backupContext" ) );
     }
+    
 }



Mime
View raw message