directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r546317 - /directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/TriggerServiceTest.java
Date Mon, 11 Jun 2007 23:17:20 GMT
Author: ersiner
Date: Mon Jun 11 16:17:17 2007
New Revision: 546317

URL: http://svn.apache.org/viewvc?view=rev&rev=546317
Log:
Added one more test method for Triggers: a simple entry (not prescriptive) trigger test.
Organized TriggerServiceTest.java.

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

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=546317&r1=546316&r2=546317
==============================================================================
--- 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 16:17:17 2007
@@ -44,6 +44,7 @@
 {
     private LdapContext ctx;
     
+    
     public void setUp() throws Exception
     {
         super.setUp();
@@ -57,6 +58,7 @@
         ctx = new InitialLdapContext( env, null );
     }
     
+    
     public void tearDown() throws Exception
     {
         ctx.close();
@@ -65,80 +67,48 @@
         super.tearDown();
     }
     
-    public void testAfterAddSubscribeUserToSomeGroups() throws NamingException
+    
+    public void testAfterDeleteBackupDeletedEntryEntryTrigger() throws NamingException
     {
-        // Create two groups to be subscribed to : staff and teachers.
         String ldif  = 
             "version: 1\n" +
             "\n" +
-            "dn: cn=staff, ou=system\n"+
+            "dn: ou=backupContext, ou=system\n"+
             "objectClass: top\n" +
-            "objectClass: groupOfUniqueNames\n" +
-            "uniqueMember: cn=dummy\n"+
-            "cn: staff\n" +
+            "objectClass: organizationalUnit\n" +
+            "ou: backupContext\n" +
             "\n" +
-            "dn: cn=teachers, ou=system\n"+
+            "dn: ou=testEntry, ou=system\n" +
             "objectClass: top\n" +
-            "objectClass: groupOfUniqueNames\n" +
-            "uniqueMember: cn=dummy\n"+
-            "cn: teachers\n";
+            "objectClass: organizationalUnit\n" +
+            "ou: testEntry\n";
         
-        // Load the stored procedure unit which has the stored procedure to be triggered.
-        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, ListUtilsSP.class );
-
-        // Inject the ldif file into the server
+        // Inject the ldif file into the server.
         injectEntries( 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( ctx );
-        TriggerUtils.createTriggerExecutionSubentry( ctx,
-                                                     "triggerSubentry1",
-                                                     "{}",
-                                                     "AFTER Add " +
-                                                         "CALL \"" + ListUtilsSP.class.getName()
+ ".subscribeToGroup\" ( $entry , $ldapContext \"" + staffDN + "\" ); " +
-                                                         "CALL \"" + ListUtilsSP.class.getName()
+ ".subscribeToGroup\" ( $entry , $ldapContext \"" + teachersDN + "\" );" );
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, BackupUtilitiesSP.class );
         
-        /**
-         * 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 the Entry Trigger Specification.
+        TriggerUtils.defineTriggerExecutionSpecificPoint( ctx );
+        LdapContext entry = ( LdapContext ) ctx.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" );
         
-        // 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( 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 ) );
+        // Check if the Trigger really worked (backed up the deleted entry).
+        assertNotNull( sysRoot.lookup( "ou=testEntry,ou=backupContext" ) );
     }
     
-    public void testAfterDeleteBackupDeletedEntry() throws NamingException
+    
+    public void testAfterDeleteBackupDeletedEntryPrescriptiveTrigger() throws NamingException
     {
         // Load the stored procedure unit which has the stored procedure to be triggered.
         JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, BackupUtilitiesSP.class );
@@ -164,15 +134,13 @@
                                                          "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  = 
@@ -197,4 +165,77 @@
         assertNotNull( sysRoot.lookup( "ou=testou,ou=backupContext" ) );
     }
     
+    
+    public void testAfterAddSubscribeUserToSomeGroupsPrescriptiveTrigger() throws NamingException
+    {
+        // 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.
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, ListUtilsSP.class );
+
+        // Inject the ldif file into the server
+        injectEntries( 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( ctx );
+        TriggerUtils.createTriggerExecutionSubentry( ctx,
+                                                     "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( 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 ) );
+    }
+ 
 }



Mime
View raw message