directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r539763 - in /directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server: BackupUtilities.java BackupUtilitiesSP.java DefaultServerTriggerServiceTest.java ListUtilsSP.java
Date Sat, 19 May 2007 14:36:15 GMT
Author: ersiner
Date: Sat May 19 07:36:14 2007
New Revision: 539763

URL: http://svn.apache.org/viewvc?view=rev&rev=539763
Log:
Added a new Trigger Service test case for demonstrating an AFTER Add Trigger for registering
an added user to some groups.

Added:
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/BackupUtilitiesSP.java
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ListUtilsSP.java
Removed:
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/BackupUtilities.java
Modified:
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DefaultServerTriggerServiceTest.java

Added: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/BackupUtilitiesSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/BackupUtilitiesSP.java?view=auto&rev=539763
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/BackupUtilitiesSP.java
(added)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/BackupUtilitiesSP.java
Sat May 19 07:36:14 2007
@@ -0,0 +1,45 @@
+/*
+ *  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.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.LdapContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class BackupUtilitiesSP
+{
+    private static final Logger log = LoggerFactory.getLogger( BackupUtilitiesSP.class );
+
+
+    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 );
+        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() + "\"" );
+    }
+}

Modified: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DefaultServerTriggerServiceTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DefaultServerTriggerServiceTest.java?view=diff&rev=539763&r1=539762&r2=539763
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DefaultServerTriggerServiceTest.java
(original)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/DefaultServerTriggerServiceTest.java
Sat May 19 07:36:14 2007
@@ -32,9 +32,13 @@
 import javax.naming.ldap.LdapContext;
 
 import org.apache.directory.server.ldap.support.extended.StoredProcedureExtendedOperationHandler;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.sp.JavaStoredProcedureUtils;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 
 
 /**
@@ -72,10 +76,67 @@
         super.tearDown();
     }
     
+    public void testAfterAddSubscribeUserToSomeGroups() throws NamingException
+    {
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, ListUtilsSP.class );
+        
+        // Create a container for backing up deleted entries.
+        Attributes staffGroupEntry = new AttributesImpl( SchemaConstants.CN_AT, "staff",
true );
+        Attribute objectClass = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        staffGroupEntry.put( objectClass );
+        objectClass.add( SchemaConstants.TOP_OC );
+        objectClass.add( SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC );
+        staffGroupEntry.put( SchemaConstants.UNIQUE_MEMBER_AT , "cn=dummy" );
+        Rdn staffRdn = new Rdn(SchemaConstants.CN_AT + "=" + "staff" );
+        sysRoot.createSubcontext( staffRdn.getUpName(), staffGroupEntry );
+        
+        // Create a container for backing up deleted entries.
+        Attributes teachersGroupEntry = new AttributesImpl( SchemaConstants.CN_AT, "teachers",
true );
+        objectClass = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        teachersGroupEntry.put( objectClass );
+        objectClass.add( SchemaConstants.TOP_OC );
+        objectClass.add( SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC );
+        teachersGroupEntry.put( SchemaConstants.UNIQUE_MEMBER_AT , "cn=dummy" );
+        Rdn teachersRdn = new Rdn( SchemaConstants.CN_AT + "=" + "teachers" );
+        sysRoot.createSubcontext( teachersRdn.getUpName(), teachersGroupEntry );
+        
+        // Create the Triger Specification within a Trigger Subentry.
+        String staffDN = staffRdn.getUpName() + "," + sysRoot.getNameInNamespace();
+        String teachersDN = teachersRdn.getUpName() + "," + sysRoot.getNameInNamespace();
+        
+        createTriggerSubentry( ctx, "triggerSubentry1",
+            "AFTER Add " +
+            "CALL \"" + ListUtilsSP.class.getName() + ".subcribeToGroup\" ( $entry , $ldapContext
\"" + staffDN + "\" ); " +
+            "CALL \"" + ListUtilsSP.class.getName() + ".subcribeToGroup\" ( $entry , $ldapContext
\"" + teachersDN + "\" );" );
+        
+        // Create a test entry which is selected by the Trigger Subentry.
+        Attributes testEntry = new AttributesImpl( SchemaConstants.CN_AT, "The Teacher of
All Times", true );
+        objectClass = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        testEntry.put( objectClass );
+        objectClass.add( SchemaConstants.TOP_OC );
+        objectClass.add( SchemaConstants.INET_ORG_PERSON_OC );
+        testEntry.put( SchemaConstants.SN_AT, "The Teacher" );
+        Rdn testEntryRdn = new Rdn( SchemaConstants.CN_AT + "=" + "The Teacher of All Times"
);
+        sysRoot.createSubcontext( testEntryRdn.getUpName(), testEntry );
+                
+        // ------------------------------------------
+        // The trigger should be fired at this point.
+        // ------------------------------------------
+        
+        // Check if the Trigger really worked (backed up the deleted entry).
+        Attributes staff = sysRoot.getAttributes( "cn=staff" );
+        Attributes teachers = sysRoot.getAttributes( "cn=teachers" );
+        System.out.println( staff );
+        String testEntryName = ( ( LdapContext )sysRoot.lookup( testEntryRdn.getUpName()
) ).getNameInNamespace();
+        assertTrue( AttributeUtils.containsValueCaseIgnore( staff.get(SchemaConstants.UNIQUE_MEMBER_AT),
testEntryName ) );
+        assertTrue( AttributeUtils.containsValueCaseIgnore( teachers.get(SchemaConstants.UNIQUE_MEMBER_AT),
testEntryName ) );
+    }
+    
     public void testAfterDeleteBackupDeletedEntry() throws NamingException
     {
         // Load the stored procedure unit which has the stored procedure to be triggered.
-        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, BackupUtilities.class );
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, BackupUtilitiesSP.class );
         
         // Create a container for backing up deleted entries.
         Attributes backupContext = new AttributesImpl( "ou", "backupContext", true );
@@ -87,7 +148,7 @@
         
         // Create the Triger Specification within a Trigger Subentry.
         createTriggerSubentry( ctx, "triggerSubentry1",
-            "AFTER Delete CALL \"" + BackupUtilities.class.getName() + ".backupDeleted\"
( $ldapContext \"\", $name, $operationPrincipal, $deletedEntry );" );
+            "AFTER Delete CALL \"" + BackupUtilitiesSP.class.getName() + ".backupDeleted\"
( $ldapContext \"\", $name, $operationPrincipal, $deletedEntry );" );
         
         // Create a test entry which is selected by the Trigger Subentry.
         Attributes testEntry = new AttributesImpl( "ou", "testou", true );

Added: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ListUtilsSP.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ListUtilsSP.java?view=auto&rev=539763
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ListUtilsSP.java
(added)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ListUtilsSP.java
Sat May 19 07:36:14 2007
@@ -0,0 +1,44 @@
+/*
+ *  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.NamingException;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ListUtilsSP
+{
+    private static final Logger log = LoggerFactory.getLogger( ListUtilsSP.class );
+
+
+    public static void subcribeToGroup( 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." );
+    }
+}



Mime
View raw message