You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/01/24 17:22:36 UTC
svn commit: r1235328 [8/12] - in /directory/apacheds/trunk:
server-annotations/src/main/java/org/apache/directory/server/annotations/
server-annotations/src/main/java/org/apache/directory/server/factory/
server-annotations/src/test/java/org/apache/dire...
Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchIT.java Tue Jan 24 16:22:33 2012
@@ -74,593 +74,591 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-@RunWith ( FrameworkRunner.class )
-@CreateLdapServer (
- transports =
- {
- @CreateTransport( protocol = "LDAP" )
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(
+ transports =
+ {
+ @CreateTransport(protocol = "LDAP")
})
-@ApplyLdifs( {
- // Entry # 2
- "dn: cn=Tori Amos,ou=system",
- "objectClass: person",
- "objectClass: top",
- "cn: Tori Amos",
- "description: an American singer-songwriter",
- "sn: Amos"
- }
-)
+@ApplyLdifs(
+ {
+ // Entry # 2
+ "dn: cn=Tori Amos,ou=system",
+ "objectClass: person",
+ "objectClass: top",
+ "cn: Tori Amos",
+ "description: an American singer-songwriter",
+ "sn: Amos"
+})
public class PersistentSearchIT extends AbstractLdapTestUnit
{
- private static final Logger LOG = LoggerFactory.getLogger( PersistentSearchIT.class );
-
- private static final String BASE = "ou=system";
- private static final String PERSON_DESCRIPTION = "an American singer-songwriter";
- private static final String RDN = "cn=Tori Amos";
-
-
- /**
- * Creation of required attributes of a person entry.
- */
- private Attributes getPersonAttributes( String sn, String cn ) throws LdapException
- {
- Attributes attributes = LdifUtils.createJndiAttributes(
- "objectClass: top",
- "objectClass: person",
- "cn", cn,
- "sn", sn );
+private static final Logger LOG = LoggerFactory.getLogger( PersistentSearchIT.class );
- return attributes;
- }
+private static final String BASE = "ou=system";
+private static final String PERSON_DESCRIPTION = "an American singer-songwriter";
+private static final String RDN = "cn=Tori Amos";
-
- EventDirContext ctx;
- EventService eventService;
- PSearchListener listener;
- Thread t;
-
- private void setUpListenerReturnECs() throws Exception
+/**
+ * Creation of required attributes of a person entry.
+ */
+private Attributes getPersonAttributes( String sn, String cn ) throws LdapException
+{
+ Attributes attributes = LdifUtils.createJndiAttributes(
+ "objectClass: top",
+ "objectClass: person",
+ "cn", cn,
+ "sn", sn );
+
+ return attributes;
+}
+
+EventDirContext ctx;
+EventService eventService;
+PSearchListener listener;
+Thread t;
+
+
+private void setUpListenerReturnECs() throws Exception
+{
+ setUpListener( true, new PersistentSearchImpl(), false );
+}
+
+
+private void setUpListener( boolean returnECs, PersistentSearch persistentSearch, boolean ignoreEmptyRegistryCheck )
+ throws Exception
+{
+ ctx = ( EventDirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+ eventService = getLdapServer().getDirectoryService().getEventService();
+ List<RegistrationEntry> registrationEntryList = eventService.getRegistrationEntries();
+
+ if ( !ignoreEmptyRegistryCheck )
{
- setUpListener( true, new PersistentSearchImpl(), false );
+ assertTrue( registrationEntryList.isEmpty() );
}
-
-
- private void setUpListener( boolean returnECs, PersistentSearch persistentSearch, boolean ignoreEmptyRegistryCheck )
- throws Exception
+
+ persistentSearch.setReturnECs( returnECs );
+ listener = new PSearchListener( persistentSearch );
+ t = new Thread( listener, "PSearchListener" );
+ t.start();
+
+ // let's wait until the listener thread started
+ while ( eventService.getRegistrationEntries().isEmpty() )
{
- ctx = ( EventDirContext ) getWiredContext( getLdapServer()).lookup( BASE );
- eventService = getLdapServer().getDirectoryService().getEventService();
- List<RegistrationEntry> registrationEntryList = eventService.getRegistrationEntries();
-
- if ( ! ignoreEmptyRegistryCheck )
- {
- assertTrue( registrationEntryList.isEmpty() );
- }
-
- persistentSearch.setReturnECs( returnECs );
- listener = new PSearchListener( persistentSearch );
- t = new Thread( listener, "PSearchListener" );
- t.start();
+ Thread.sleep( 100 );
+ }
- // let's wait until the listener thread started
- while ( eventService.getRegistrationEntries().isEmpty() )
- {
- Thread.sleep( 100 );
- }
-
- // Now we wait until the listener is registered (timing dependent crap)
- Thread.sleep( 250 );
+ // Now we wait until the listener is registered (timing dependent crap)
+ Thread.sleep( 250 );
+}
+
+
+private void setUpListener() throws Exception
+{
+ ctx = ( EventDirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+ eventService = getLdapServer().getDirectoryService().getEventService();
+ List<RegistrationEntry> registrationEntryList = eventService.getRegistrationEntries();
+ assertTrue( registrationEntryList.isEmpty() );
+
+ listener = new PSearchListener();
+ t = new Thread( listener, "PSearchListener" );
+ t.start();
+
+ // let's wait until the listener thread started
+ while ( eventService.getRegistrationEntries().isEmpty() )
+ {
+ Thread.sleep( 100 );
}
-
-
- private void setUpListener() throws Exception
+
+ // Now we wait until the listener is registered (timing dependent crap)
+ Thread.sleep( 250 );
+}
+
+
+@After
+public void tearDownListener() throws Exception
+{
+ listener.close();
+ ctx.close();
+
+ while ( !eventService.getRegistrationEntries().isEmpty() )
{
- ctx = ( EventDirContext ) getWiredContext( getLdapServer()).lookup( BASE );
- eventService = getLdapServer().getDirectoryService().getEventService();
- List<RegistrationEntry> registrationEntryList = eventService.getRegistrationEntries();
- assertTrue( registrationEntryList.isEmpty() );
-
- listener = new PSearchListener();
- t = new Thread( listener, "PSearchListener" );
- t.start();
+ Thread.sleep( 100 );
+ }
+}
+
+
+private void waitForThreadToDie( Thread t ) throws Exception
+{
+ long start = System.currentTimeMillis();
- // let's wait until the listener thread started
- while ( eventService.getRegistrationEntries().isEmpty() )
+ while ( t.isAlive() )
+ {
+ Thread.sleep( 200 );
+ if ( System.currentTimeMillis() - start > 1000 )
{
- Thread.sleep( 100 );
+ break;
}
-
- // Now we wait until the listener is registered (timing dependent crap)
- Thread.sleep( 250 );
}
-
-
- @After
- public void tearDownListener() throws Exception
- {
- listener.close();
- ctx.close();
+}
- while ( ! eventService.getRegistrationEntries().isEmpty() )
- {
- Thread.sleep( 100 );
- }
+
+/**
+ * Shows correct notifications for modify(4) changes.
+ */
+@Test
+public void testPsearchModify() throws Exception
+{
+ setUpListener();
+ ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE,
+ new BasicAttributes( "description", PERSON_DESCRIPTION, true ) );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( RDN, listener.result.getName() );
+}
+
+
+/**
+ * Shows correct notifications for moddn(8) changes.
+ */
+@Test
+public void testPsearchModifyDn() throws Exception
+{
+ setUpListener();
+ ctx.rename( RDN, "cn=Jack Black" );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+}
+
+
+/**
+ * Shows correct notifications for delete(2) changes.
+ */
+@Test
+public void testPsearchDelete() throws Exception
+{
+ setUpListener();
+ ctx.destroySubcontext( RDN );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( RDN, listener.result.getName() );
+}
+
+
+/**
+ * Shows correct notifications for add(1) changes.
+ */
+@Test
+public void testPsearchAdd() throws Exception
+{
+ setUpListener();
+ ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+}
+
+
+/**
+ * Shows correct notifications for modify(4) changes with returned
+ * EntryChangeControl.
+ */
+@Test
+public void testPsearchModifyWithEC() throws Exception
+{
+ setUpListenerReturnECs();
+ ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, new BasicAttributes( "description", PERSON_DESCRIPTION,
+ true ) );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( RDN, listener.result.getName() );
+ assertEquals( listener.result.control.getChangeType(), ChangeType.MODIFY );
+}
+
+
+/**
+ * Shows correct notifications for moddn(8) changes with returned
+ * EntryChangeControl.
+ */
+@Test
+public void testPsearchModifyDnWithEC() throws Exception
+{
+ setUpListenerReturnECs();
+ ctx.rename( RDN, "cn=Jack Black" );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+ assertEquals( listener.result.control.getChangeType(), ChangeType.MODDN );
+ assertEquals( ( RDN + ",ou=system" ), listener.result.control.getPreviousDn().getName() );
+}
+
+
+/**
+ * Shows correct notifications for delete(2) changes with returned
+ * EntryChangeControl.
+ */
+@Test
+public void testPsearchDeleteWithEC() throws Exception
+{
+ setUpListenerReturnECs();
+ ctx.destroySubcontext( RDN );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( RDN, listener.result.getName() );
+ assertEquals( listener.result.control.getChangeType(), ChangeType.DELETE );
+}
+
+
+/**
+ * Shows correct notifications for add(1) changes with returned
+ * EntryChangeControl.
+ */
+@Test
+public void testPsearchAddWithEC() throws Exception
+{
+ setUpListenerReturnECs();
+ ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
+ waitForThreadToDie( t );
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+ assertEquals( listener.result.control.getChangeType(), ChangeType.ADD );
+}
+
+
+/**
+ * Shows correct notifications for only add(1) and modify(4) registered changes with returned
+ * EntryChangeControl but not deletes.
+ */
+@Test
+public void testPsearchAddModifyEnabledWithEC() throws Exception
+{
+ PersistentSearch ctrl = new PersistentSearchImpl();
+ ctrl.setReturnECs( true );
+ ctrl.setChangeTypes( ChangeType.ADD.getValue() );
+ ctrl.enableNotification( ChangeType.MODIFY );
+ setUpListener( true, ctrl, false );
+ ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
+ waitForThreadToDie( t );
+
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+ assertEquals( listener.result.control.getChangeType(), ChangeType.ADD );
+ tearDownListener();
+
+ setUpListener( true, ctrl, true );
+ ctx.destroySubcontext( "cn=Jack Black" );
+ waitForThreadToDie( t );
+ assertNull( listener.result );
+
+ // thread is still waiting for notifications try a modify
+ ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, new BasicAttributes( "description", PERSON_DESCRIPTION,
+ true ) );
+ waitForThreadToDie( t );
+
+ assertNotNull( listener.result );
+ assertEquals( RDN, listener.result.getName() );
+ assertEquals( listener.result.control.getChangeType(), ChangeType.MODIFY );
+}
+
+/**
+ * Shows correct notifications for add(1) changes with returned
+ * EntryChangeControl and changesOnly set to false so we return
+ * the first set of entries.
+ *
+ * This test is commented out because it exhibits some producer
+ * consumer lockups (server and client being in same process)
+ *
+ * PLUS ALL THIS GARBAGE IS TIME DEPENDENT!!!!!
+ */
+// public void testPsearchAddWithECAndFalseChangesOnly() throws Exception
+// {
+// PersistentSearchDecorator decorator = new PersistentSearchDecorator();
+// decorator.setReturnECs( true );
+// decorator.setChangesOnly( false );
+// PSearchListener listener = new PSearchListener( decorator );
+// Thread t = new Thread( listener );
+// t.start();
+//
+// Thread.sleep( 3000 );
+//
+// assertEquals( 5, listener.count );
+// ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
+//
+// long start = System.currentTimeMillis();
+// while ( t.isAlive() )
+// {
+// Thread.sleep( 100 );
+// if ( System.currentTimeMillis() - start > 3000 )
+// {
+// break;
+// }
+// }
+//
+// assertEquals( 6, listener.count );
+// assertNotNull( listener.result );
+// assertEquals( "cn=Jack Black", listener.result.getName() );
+// assertEquals( listener.result.decorator.getChangeType(), ChangeType.ADD );
+// }
+
+/**
+ * Shows notifications functioning with the JNDI notification API of the SUN
+ * provider.
+ *
+@Test
+public void testPsearchAbandon() throws Exception
+{
+ PersistentSearchDecorator decorator = new PersistentSearchDecorator();
+ decorator.setReturnECs( true );
+ PSearchListener listener = new PSearchListener( decorator );
+ Thread t = new Thread( listener );
+ t.start();
+
+ while ( !listener.isReady )
+ {
+ Thread.sleep( 100 );
}
+ Thread.sleep( 250 );
-
- private void waitForThreadToDie( Thread t ) throws Exception
+ ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
+
+ long start = System.currentTimeMillis();
+ while ( t.isAlive() )
{
- long start = System.currentTimeMillis();
-
- while ( t.isAlive() )
+ Thread.sleep( 100 );
+ if ( System.currentTimeMillis() - start > 3000 )
{
- Thread.sleep( 200 );
- if ( System.currentTimeMillis() - start > 1000 )
- {
- break;
- }
+ break;
}
}
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+ assertEquals( listener.result.decorator.getChangeType(), ChangeType.ADD );
- /**
- * Shows correct notifications for modify(4) changes.
- */
- @Test
- public void testPsearchModify() throws Exception
- {
- setUpListener();
- ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE,
- new BasicAttributes( "description", PERSON_DESCRIPTION, true ) );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( RDN, listener.result.getName() );
- }
-
-
- /**
- * Shows correct notifications for moddn(8) changes.
- */
- @Test
- public void testPsearchModifyDn() throws Exception
- {
- setUpListener();
- ctx.rename( RDN, "cn=Jack Black" );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- }
-
-
- /**
- * Shows correct notifications for delete(2) changes.
- */
- @Test
- public void testPsearchDelete() throws Exception
- {
- setUpListener();
- ctx.destroySubcontext( RDN );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( RDN, listener.result.getName() );
- }
-
-
- /**
- * Shows correct notifications for add(1) changes.
- */
- @Test
- public void testPsearchAdd() throws Exception
- {
- setUpListener();
- ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- }
-
-
- /**
- * Shows correct notifications for modify(4) changes with returned
- * EntryChangeControl.
- */
- @Test
- public void testPsearchModifyWithEC() throws Exception
- {
- setUpListenerReturnECs();
- ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, new BasicAttributes( "description", PERSON_DESCRIPTION,
- true ) );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( RDN, listener.result.getName() );
- assertEquals( listener.result.control.getChangeType(), ChangeType.MODIFY );
- }
-
-
- /**
- * Shows correct notifications for moddn(8) changes with returned
- * EntryChangeControl.
- */
- @Test
- public void testPsearchModifyDnWithEC() throws Exception
- {
- setUpListenerReturnECs();
- ctx.rename( RDN, "cn=Jack Black" );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- assertEquals( listener.result.control.getChangeType(), ChangeType.MODDN );
- assertEquals( ( RDN + ",ou=system" ), listener.result.control.getPreviousDn().getName() );
- }
-
-
- /**
- * Shows correct notifications for delete(2) changes with returned
- * EntryChangeControl.
- */
- @Test
- public void testPsearchDeleteWithEC() throws Exception
- {
- setUpListenerReturnECs();
- ctx.destroySubcontext( RDN );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( RDN, listener.result.getName() );
- assertEquals( listener.result.control.getChangeType(), ChangeType.DELETE );
- }
-
-
- /**
- * Shows correct notifications for add(1) changes with returned
- * EntryChangeControl.
- */
- @Test
- public void testPsearchAddWithEC() throws Exception
- {
- setUpListenerReturnECs();
- ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
- waitForThreadToDie( t );
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- assertEquals( listener.result.control.getChangeType(), ChangeType.ADD );
- }
-
-
- /**
- * Shows correct notifications for only add(1) and modify(4) registered changes with returned
- * EntryChangeControl but not deletes.
- */
- @Test
- public void testPsearchAddModifyEnabledWithEC() throws Exception
- {
- PersistentSearch ctrl = new PersistentSearchImpl();
- ctrl.setReturnECs( true );
- ctrl.setChangeTypes( ChangeType.ADD.getValue() );
- ctrl.enableNotification( ChangeType.MODIFY );
- setUpListener( true, ctrl, false );
- ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
- waitForThreadToDie( t );
-
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- assertEquals( listener.result.control.getChangeType(), ChangeType.ADD );
- tearDownListener();
-
- setUpListener( true, ctrl, true );
- ctx.destroySubcontext( "cn=Jack Black" );
- waitForThreadToDie( t );
- assertNull( listener.result );
-
- // thread is still waiting for notifications try a modify
- ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, new BasicAttributes( "description", PERSON_DESCRIPTION,
- true ) );
- waitForThreadToDie( t );
-
- assertNotNull( listener.result );
- assertEquals( RDN, listener.result.getName() );
- assertEquals( listener.result.control.getChangeType(), ChangeType.MODIFY );
- }
-
-
- /**
- * Shows correct notifications for add(1) changes with returned
- * EntryChangeControl and changesOnly set to false so we return
- * the first set of entries.
- *
- * This test is commented out because it exhibits some producer
- * consumer lockups (server and client being in same process)
- *
- * PLUS ALL THIS GARBAGE IS TIME DEPENDENT!!!!!
- */
- // public void testPsearchAddWithECAndFalseChangesOnly() throws Exception
- // {
- // PersistentSearchDecorator decorator = new PersistentSearchDecorator();
- // decorator.setReturnECs( true );
- // decorator.setChangesOnly( false );
- // PSearchListener listener = new PSearchListener( decorator );
- // Thread t = new Thread( listener );
- // t.start();
- //
- // Thread.sleep( 3000 );
- //
- // assertEquals( 5, listener.count );
- // ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
- //
- // long start = System.currentTimeMillis();
- // while ( t.isAlive() )
- // {
- // Thread.sleep( 100 );
- // if ( System.currentTimeMillis() - start > 3000 )
- // {
- // break;
- // }
- // }
- //
- // assertEquals( 6, listener.count );
- // assertNotNull( listener.result );
- // assertEquals( "cn=Jack Black", listener.result.getName() );
- // assertEquals( listener.result.decorator.getChangeType(), ChangeType.ADD );
- // }
-
- /**
- * Shows notifications functioning with the JNDI notification API of the SUN
- * provider.
- *
- @Test
- public void testPsearchAbandon() throws Exception
- {
- PersistentSearchDecorator decorator = new PersistentSearchDecorator();
- decorator.setReturnECs( true );
- PSearchListener listener = new PSearchListener( decorator );
- Thread t = new Thread( listener );
- t.start();
+ listener = new PSearchListener( decorator );
+
+ t = new Thread( listener );
+ t.start();
- while ( !listener.isReady )
+ ctx.destroySubcontext( "cn=Jack Black" );
+
+ start = System.currentTimeMillis();
+ while ( t.isAlive() )
+ {
+ Thread.sleep( 100 );
+ if ( System.currentTimeMillis() - start > 3000 )
{
- Thread.sleep( 100 );
+ break;
}
- Thread.sleep( 250 );
+ }
- ctx.createSubcontext( "cn=Jack Black", getPersonAttributes( "Black", "Jack Black" ) );
+ // there seems to be a race condition here
+ // assertNull( listener.result );
+ assertNotNull( listener.result );
+ assertEquals( "cn=Jack Black", listener.result.getName() );
+ assertEquals( ChangeType.DELETE, listener.result.decorator.getChangeType() );
+ listener.result = null;
- long start = System.currentTimeMillis();
- while ( t.isAlive() )
+ // thread is still waiting for notifications try a modify
+ ctx.modifyAttributes( Rdn, DirContext.REMOVE_ATTRIBUTE, new AttributesImpl( "description", PERSON_DESCRIPTION,
+ true ) );
+ start = System.currentTimeMillis();
+ while ( t.isAlive() )
+ {
+ Thread.sleep( 200 );
+ if ( System.currentTimeMillis() - start > 3000 )
{
- Thread.sleep( 100 );
- if ( System.currentTimeMillis() - start > 3000 )
- {
- break;
- }
+ break;
}
+ }
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- assertEquals( listener.result.decorator.getChangeType(), ChangeType.ADD );
-
- listener = new PSearchListener( decorator );
-
- t = new Thread( listener );
- t.start();
+ assertNull( listener.result );
+ //assertEquals( Rdn, listener.result.getName() );
+ //assertEquals( listener.result.decorator.getChangeType(), ChangeType.MODIFY );
+}*/
- ctx.destroySubcontext( "cn=Jack Black" );
+class JndiNotificationListener implements NamespaceChangeListener, ObjectChangeListener
+{
+ boolean hasError = false;
+ ArrayList<EventObject> list = new ArrayList<EventObject>();
+ NamingExceptionEvent exceptionEvent = null;
- start = System.currentTimeMillis();
- while ( t.isAlive() )
- {
- Thread.sleep( 100 );
- if ( System.currentTimeMillis() - start > 3000 )
- {
- break;
- }
- }
- // there seems to be a race condition here
- // assertNull( listener.result );
- assertNotNull( listener.result );
- assertEquals( "cn=Jack Black", listener.result.getName() );
- assertEquals( ChangeType.DELETE, listener.result.decorator.getChangeType() );
- listener.result = null;
-
- // thread is still waiting for notifications try a modify
- ctx.modifyAttributes( Rdn, DirContext.REMOVE_ATTRIBUTE, new AttributesImpl( "description", PERSON_DESCRIPTION,
- true ) );
- start = System.currentTimeMillis();
- while ( t.isAlive() )
- {
- Thread.sleep( 200 );
- if ( System.currentTimeMillis() - start > 3000 )
- {
- break;
- }
- }
+ public void objectAdded( NamingEvent evt )
+ {
+ list.add( 0, evt );
+ }
- assertNull( listener.result );
- //assertEquals( Rdn, listener.result.getName() );
- //assertEquals( listener.result.decorator.getChangeType(), ChangeType.MODIFY );
- }*/
-
- class JndiNotificationListener implements NamespaceChangeListener, ObjectChangeListener
+ public void objectRemoved( NamingEvent evt )
{
- boolean hasError = false;
- ArrayList<EventObject> list = new ArrayList<EventObject>();
- NamingExceptionEvent exceptionEvent = null;
+ list.add( 0, evt );
+ }
- public void objectAdded( NamingEvent evt )
- {
- list.add( 0, evt );
- }
+ public void objectRenamed( NamingEvent evt )
+ {
+ list.add( 0, evt );
+ }
- public void objectRemoved( NamingEvent evt )
- {
- list.add( 0, evt );
- }
+ public void namingExceptionThrown( NamingExceptionEvent evt )
+ {
+ hasError = true;
+ exceptionEvent = evt;
+ list.add( 0, evt );
+ }
- public void objectRenamed( NamingEvent evt )
- {
- list.add( 0, evt );
- }
+ public void objectChanged( NamingEvent evt )
+ {
+ list.add( 0, evt );
+ }
+}
- public void namingExceptionThrown( NamingExceptionEvent evt )
- {
- hasError = true;
- exceptionEvent = evt;
- list.add( 0, evt );
- }
+class PSearchListener implements Runnable
+{
+ boolean isReady = false;
+ PSearchNotification result;
+ final PersistentSearchDecorator persistentSearch;
+ LdapContext ctx;
+ NamingEnumeration<SearchResult> list;
- public void objectChanged( NamingEvent evt )
- {
- list.add( 0, evt );
- }
+ PSearchListener()
+ {
+ persistentSearch = new PersistentSearchDecorator( getLdapServer().getDirectoryService().getLdapCodecService() );
}
-
- class PSearchListener implements Runnable
+
+ PSearchListener( PersistentSearch persistentSearch )
{
- boolean isReady = false;
- PSearchNotification result;
- final PersistentSearchDecorator persistentSearch;
- LdapContext ctx;
- NamingEnumeration<SearchResult> list;
-
- PSearchListener()
- {
- persistentSearch = new PersistentSearchDecorator( getLdapServer().getDirectoryService().getLdapCodecService() );
- }
+ CodecControl<? extends Control> wrapped =
+ getLdapServer().getDirectoryService().getLdapCodecService().newControl( persistentSearch );
+ this.persistentSearch = ( PersistentSearchDecorator ) wrapped;
+ }
- PSearchListener( PersistentSearch persistentSearch )
+ void close()
+ {
+ if ( list != null )
{
- CodecControl<? extends Control> wrapped =
- getLdapServer().getDirectoryService().getLdapCodecService().newControl( persistentSearch );
- this.persistentSearch = ( PersistentSearchDecorator ) wrapped;
+ try
+ {
+ list.close();
+ LOG.debug( "PSearchListener: search naming enumeration closed()" );
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "Error closing NamingEnumeration on PSearchListener", e );
+ }
}
-
- void close()
+ if ( ctx != null )
{
- if ( list != null )
+ try
{
- try
- {
- list.close();
- LOG.debug( "PSearchListener: search naming enumeration closed()" );
- }
- catch ( Exception e )
- {
- LOG.error( "Error closing NamingEnumeration on PSearchListener", e );
- }
+ ctx.close();
+ LOG.debug( "PSearchListener: search context closed()" );
}
-
- if ( ctx != null )
+ catch ( Exception e )
{
- try
- {
- ctx.close();
- LOG.debug( "PSearchListener: search context closed()" );
- }
- catch ( Exception e )
- {
- LOG.error( "Error closing connection on PSearchListener", e );
- }
+ LOG.error( "Error closing connection on PSearchListener", e );
}
}
+ }
-
- public void run()
- {
- LOG.debug( "PSearchListener.run() called." );
- LdapApiService codec = getLdapServer().getDirectoryService().getLdapCodecService();
- persistentSearch.setCritical( true );
- persistentSearch.setValue( persistentSearch.getValue() );
- Control[] ctxCtls = new Control[] { persistentSearch };
+ public void run()
+ {
+ LOG.debug( "PSearchListener.run() called." );
+ LdapApiService codec = getLdapServer().getDirectoryService().getLdapCodecService();
+ persistentSearch.setCritical( true );
+ persistentSearch.setValue( persistentSearch.getValue() );
+
+ Control[] ctxCtls = new Control[]
+ { persistentSearch };
+
+ try
+ {
+ ctx = ( LdapContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+ ctx.setRequestControls( JndiUtils.toJndiControls( codec, ctxCtls ) );
+ isReady = true;
+ LOG.debug( "PSearchListener is ready and about to issue persistent search request." );
+ list = ctx.search( "", "objectClass=*", null );
+ LOG.debug( "PSearchListener search request returned." );
+ EntryChange ecControl = null;
- try
+ while ( list.hasMore() )
{
- ctx = ( LdapContext ) getWiredContext( getLdapServer()).lookup( BASE );
- ctx.setRequestControls( JndiUtils.toJndiControls( codec, ctxCtls) );
- isReady = true;
- LOG.debug( "PSearchListener is ready and about to issue persistent search request." );
- list = ctx.search( "", "objectClass=*", null );
- LOG.debug( "PSearchListener search request returned." );
- EntryChange ecControl = null;
+ LOG.debug( "PSearchListener search request got an item." );
+ javax.naming.ldap.Control[] controls;
+ SearchResult sresult = list.next();
- while ( list.hasMore() )
+ if ( sresult instanceof HasControls )
{
- LOG.debug( "PSearchListener search request got an item." );
- javax.naming.ldap.Control[] controls;
- SearchResult sresult = list.next();
-
- if ( sresult instanceof HasControls )
+ controls = ( ( HasControls ) sresult ).getControls();
+
+ if ( controls != null )
{
- controls = ( ( HasControls ) sresult ).getControls();
-
- if ( controls != null )
+ for ( javax.naming.ldap.Control jndiControl : controls )
{
- for ( javax.naming.ldap.Control jndiControl : controls )
+ if ( jndiControl.getID().equals(
+ EntryChange.OID ) )
{
- if ( jndiControl.getID().equals(
- EntryChange.OID ) )
- {
- ecControl = (EntryChange)JndiUtils.fromJndiControl( codec, jndiControl );
- ((EntryChangeDecorator)ecControl).decode( jndiControl.getEncodedValue() );
- }
+ ecControl = ( EntryChange ) JndiUtils.fromJndiControl( codec, jndiControl );
+ ( ( EntryChangeDecorator ) ecControl ).decode( jndiControl.getEncodedValue() );
}
}
}
-
- result = new PSearchNotification( sresult, ecControl );
- break;
}
-
- LOG.debug( "PSearchListener broke out of while loop." );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- LOG.error( "PSearchListener encountered error", e );
- }
- finally
- {
+
+ result = new PSearchNotification( sresult, ecControl );
+ break;
}
+
+ LOG.debug( "PSearchListener broke out of while loop." );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ LOG.error( "PSearchListener encountered error", e );
+ }
+ finally
+ {
}
}
+}
-
- class PSearchNotification extends SearchResult
- {
- private static final long serialVersionUID = 1L;
- final EntryChange control;
+class PSearchNotification extends SearchResult
+{
+ private static final long serialVersionUID = 1L;
+ final EntryChange control;
- public PSearchNotification( SearchResult result, EntryChange control )
- {
- super( result.getName(), result.getClassName(), result.getObject(), result.getAttributes(), result
- .isRelative() );
- this.control = control;
- }
+ public PSearchNotification( SearchResult result, EntryChange control )
+ {
+ super( result.getName(), result.getClassName(), result.getObject(), result.getAttributes(), result
+ .isRelative() );
+ this.control = control;
+ }
- public String toString()
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "Dn: " ).append( getName() ).append( "\n" );
+
+ if ( control != null )
{
- StringBuffer buf = new StringBuffer();
- buf.append( "Dn: " ).append( getName() ).append( "\n" );
-
- if ( control != null )
- {
- buf.append( " EntryChangeControl =\n" );
- buf.append( " changeType : " ).append( control.getChangeType() ).append( "\n" );
- buf.append( " previousDN : " ).append( control.getPreviousDn() ).append( "\n" );
- buf.append( " changeNumber : " ).append( control.getChangeNumber() ).append( "\n" );
- }
-
- return buf.toString();
+ buf.append( " EntryChangeControl =\n" );
+ buf.append( " changeType : " ).append( control.getChangeType() ).append( "\n" );
+ buf.append( " previousDN : " ).append( control.getPreviousDn() ).append( "\n" );
+ buf.append( " changeNumber : " ).append( control.getChangeNumber() ).append( "\n" );
}
+
+ return buf.toString();
}
}
+}
Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchIT.java Tue Jan 24 16:22:33 2012
@@ -19,7 +19,7 @@
*/
package org.apache.directory.server.operations.search;
-
+
import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
import static org.junit.Assert.assertEquals;
@@ -63,365 +63,367 @@ import org.junit.runner.RunWith;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-@RunWith ( FrameworkRunner.class )
-@CreateLdapServer (
- transports =
- {
- @CreateTransport( protocol = "LDAP" )
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(
+ transports =
+ {
+ @CreateTransport(protocol = "LDAP")
})
-@ApplyLdifs( {
- // Add new ref for ou=RemoteUsers
- "dn: ou=RemoteUsers,ou=system",
- "objectClass: top",
- "objectClass: referral",
- "objectClass: extensibleObject",
- "ou: RemoteUsers",
- "ref: ldap://fermi:10389/ou=users,ou=system",
- "ref: ldap://hertz:10389/ou=users,dc=example,dc=com",
- "ref: ldap://maxwell:10389/ou=users,ou=system",
-
- "dn: c=France,ou=system",
- "objectClass: top",
- "objectClass: country",
- "c: France",
-
- "dn: c=USA,ou=system",
- "objectClass: top",
- "objectClass: country",
- "c: USA",
-
- "dn: l=Paris,c=france,ou=system",
- "objectClass: top",
- "objectClass: locality",
- "l: Paris",
-
- "dn: l=Jacksonville,c=usa,ou=system",
- "objectClass: top",
- "objectClass: locality",
- "l: Jacksonville",
-
- "dn: cn=emmanuel lecharny,l=paris,c=france,ou=system",
- "objectClass: top",
- "objectClass: person",
- "objectClass: residentialPerson",
- "cn: emmanuel lecharny",
- "sn: elecharny",
- "l: Paris",
-
- "dn: cn=alex karasulu,l=jacksonville,c=usa,ou=system",
- "objectClass: top",
- "objectClass: person",
- "objectClass: residentialPerson",
- "cn: alex karasulu",
- "sn: karasulu",
- "l: Jacksonville",
-
- "dn: ou=Countries,ou=system",
- "objectClass: top",
- "objectClass: organizationalUnit",
- "ou: Countries"
- }
-)
+@ApplyLdifs(
+ {
+ // Add new ref for ou=RemoteUsers
+ "dn: ou=RemoteUsers,ou=system",
+ "objectClass: top",
+ "objectClass: referral",
+ "objectClass: extensibleObject",
+ "ou: RemoteUsers",
+ "ref: ldap://fermi:10389/ou=users,ou=system",
+ "ref: ldap://hertz:10389/ou=users,dc=example,dc=com",
+ "ref: ldap://maxwell:10389/ou=users,ou=system",
+
+ "dn: c=France,ou=system",
+ "objectClass: top",
+ "objectClass: country",
+ "c: France",
+
+ "dn: c=USA,ou=system",
+ "objectClass: top",
+ "objectClass: country",
+ "c: USA",
+
+ "dn: l=Paris,c=france,ou=system",
+ "objectClass: top",
+ "objectClass: locality",
+ "l: Paris",
+
+ "dn: l=Jacksonville,c=usa,ou=system",
+ "objectClass: top",
+ "objectClass: locality",
+ "l: Jacksonville",
+
+ "dn: cn=emmanuel lecharny,l=paris,c=france,ou=system",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: residentialPerson",
+ "cn: emmanuel lecharny",
+ "sn: elecharny",
+ "l: Paris",
+
+ "dn: cn=alex karasulu,l=jacksonville,c=usa,ou=system",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: residentialPerson",
+ "cn: alex karasulu",
+ "sn: karasulu",
+ "l: Jacksonville",
+
+ "dn: ou=Countries,ou=system",
+ "objectClass: top",
+ "objectClass: organizationalUnit",
+ "ou: Countries"
+})
public class ReferralSearchIT extends AbstractLdapTestUnit
{
-
- @Before
- public void setupReferrals() throws Exception
- {
- String ldif =
+
+@Before
+public void setupReferrals() throws Exception
+{
+ String ldif =
"dn: c=europ,ou=Countries,ou=system\n" +
- "objectClass: top\n" +
- "objectClass: referral\n" +
- "objectClass: extensibleObject\n" +
- "c: europ\n" +
- "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
-
- "dn: c=america,ou=Countries,ou=system\n" +
- "objectClass: top\n" +
- "objectClass: referral\n" +
- "objectClass: extensibleObject\n" +
- "c: america\n" +
- "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
-
- LdifReader reader = new LdifReader( new StringReader( ldif ) );
-
- while ( reader.hasNext() )
- {
- LdifEntry entry = reader.next();
- getLdapServer().getDirectoryService().getAdminSession().add(
- new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
- }
- }
-
-
- @Test
- public void testSearchBaseIsReferral() throws Exception
+ "objectClass: top\n" +
+ "objectClass: referral\n" +
+ "objectClass: extensibleObject\n" +
+ "c: europ\n" +
+ "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
+
+ "dn: c=america,ou=Countries,ou=system\n" +
+ "objectClass: top\n" +
+ "objectClass: referral\n" +
+ "objectClass: extensibleObject\n" +
+ "c: america\n" +
+ "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
+
+ LdifReader reader = new LdifReader( new StringReader( ldif ) );
+
+ while ( reader.hasNext() )
{
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- try
- {
- ctx.search( "ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
- fail( "should never get here" );
- }
- catch ( ReferralException e )
- {
- assertEquals( "ldap://fermi:10389/ou=users,ou=system??sub", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://maxwell:10389/ou=users,ou=system??sub", e.getReferralInfo() );
- assertFalse( e.skipReferral() );
- }
+ LdifEntry entry = reader.next();
+ getLdapServer().getDirectoryService().getAdminSession().add(
+ new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
}
+}
- @Test
- public void testSearchBaseParentIsReferral() throws Exception
- {
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+@Test
+public void testSearchBaseIsReferral() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- try
- {
- ctx.search( "cn=alex karasulu,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
- }
- catch ( ReferralException e )
- {
- assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=users,dc=example,dc=com??base", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
- assertFalse( e.skipReferral() );
- }
+ try
+ {
+ ctx.search( "ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+ fail( "should never get here" );
+ }
+ catch ( ReferralException e )
+ {
+ assertEquals( "ldap://fermi:10389/ou=users,ou=system??sub", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://maxwell:10389/ou=users,ou=system??sub", e.getReferralInfo() );
+ assertFalse( e.skipReferral() );
}
+}
+
+@Test
+public void testSearchBaseParentIsReferral() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- @Test
- public void testSearchBaseAncestorIsReferral() throws Exception
+ try
{
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ ctx.search( "cn=alex karasulu,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+ }
+ catch ( ReferralException e )
+ {
+ assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=users,dc=example,dc=com??base", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=users,ou=system??base", e.getReferralInfo() );
+ assertFalse( e.skipReferral() );
+ }
+}
- try
- {
- ctx.search( "cn=alex karasulu,ou=apache,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
- }
- catch ( ReferralException e )
- {
- assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=apache,ou=users,dc=example,dc=com??base", e
- .getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e
- .getReferralInfo() );
- assertFalse( e.skipReferral() );
- }
+
+@Test
+public void testSearchBaseAncestorIsReferral() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+
+ try
+ {
+ ctx.search( "cn=alex karasulu,ou=apache,ou=RemoteUsers,ou=system", "(objectClass=*)", controls );
+ }
+ catch ( ReferralException e )
+ {
+ assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=apache,ou=users,dc=example,dc=com??base", e
+ .getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system??base", e
+ .getReferralInfo() );
+ assertFalse( e.skipReferral() );
}
+}
+
+@Test
+public void testSearchContinuations() throws Exception
+{
+ DirContext ctx = getWiredContext( getLdapServer() );
- @Test
- public void testSearchContinuations() throws Exception
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ NamingEnumeration<SearchResult> list = ctx.search( "ou=system", "(objectClass=*)", controls );
+ Map<String, SearchResult> results = new HashMap<String, SearchResult>();
+ while ( list.hasMore() )
{
- DirContext ctx = getWiredContext( getLdapServer() );
+ SearchResult result = list.next();
+ results.put( result.getName(), result );
+ }
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- NamingEnumeration<SearchResult> list = ctx.search( "ou=system", "(objectClass=*)", controls );
- Map<String,SearchResult> results = new HashMap<String,SearchResult>();
+ assertNotNull( results.get( "ou=users" ) );
+
+ // -------------------------------------------------------------------
+ // Now we will throw exceptions when searching for referrals
+ // -------------------------------------------------------------------
+
+ ctx.addToEnvironment( Context.REFERRAL, "throw" );
+ list = ctx.search( "ou=system", "(objectClass=*)", controls );
+ results = new HashMap<String, SearchResult>();
+
+ try
+ {
while ( list.hasMore() )
{
SearchResult result = list.next();
results.put( result.getName(), result );
}
-
- assertNotNull( results.get( "ou=users" ) );
-
- // -------------------------------------------------------------------
- // Now we will throw exceptions when searching for referrals
- // -------------------------------------------------------------------
-
- ctx.addToEnvironment( Context.REFERRAL, "throw" );
- list = ctx.search( "ou=system", "(objectClass=*)", controls );
- results = new HashMap<String,SearchResult>();
-
- try
+ }
+ catch ( ReferralException e )
+ {
+ // As we use the uuidIndex the order of search continuations returned by
+ // the server is not deterministic. So we collect all referrals first into
+ // an hashset and check afterwards if the expected URLs are included.
+ Set<Object> s = new HashSet<Object>();
+ s.add( e.getReferralInfo() );
+ while ( e.skipReferral() )
{
- while ( list.hasMore() )
+ try
{
- SearchResult result = list.next();
- results.put( result.getName(), result );
+ Context ctx2 = e.getReferralContext();
+ ctx2.list( "" );
}
- }
- catch ( ReferralException e )
- {
- // As we use the uuidIndex the order of search continuations returned by
- // the server is not deterministic. So we collect all referrals first into
- // an hashset and check afterwards if the expected URLs are included.
- Set<Object> s = new HashSet<Object>();
- s.add( e.getReferralInfo() );
- while ( e.skipReferral() )
+ catch ( NamingException ne )
{
- try
+ if ( ne instanceof ReferralException )
{
- Context ctx2 = e.getReferralContext();
- ctx2.list( "" );
+ e = ( ReferralException ) ne;
+ s.add( e.getReferralInfo() );
}
- catch ( NamingException ne )
+ else
{
- if ( ne instanceof ReferralException )
- {
- e = ( ReferralException ) ne;
- s.add( e.getReferralInfo() );
- }
- else
- {
- break;
- }
+ break;
}
}
-
- assertEquals( 5, s.size() );
- assertTrue( s.contains( "ldap://fermi:10389/ou=users,ou=system??sub" ) );
- assertTrue( s.contains( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub" ) );
- assertTrue( s.contains( "ldap://maxwell:10389/ou=users,ou=system??sub" ) );
}
- assertNull( results.get( "ou=remoteusers" ) );
+ assertEquals( 5, s.size() );
+ assertTrue( s.contains( "ldap://fermi:10389/ou=users,ou=system??sub" ) );
+ assertTrue( s.contains( "ldap://hertz:10389/ou=users,dc=example,dc=com??sub" ) );
+ assertTrue( s.contains( "ldap://maxwell:10389/ou=users,ou=system??sub" ) );
+ }
- // try again but this time with single level scope
+ assertNull( results.get( "ou=remoteusers" ) );
- controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
- list = ctx.search( "ou=system", "(objectClass=*)", controls );
- results = new HashMap<String,SearchResult>();
+ // try again but this time with single level scope
- try
- {
- while ( list.hasMore() )
- {
- SearchResult result = list.next();
- results.put( result.getName(), result );
- }
- }
- catch ( ReferralException e )
+ controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ list = ctx.search( "ou=system", "(objectClass=*)", controls );
+ results = new HashMap<String, SearchResult>();
+
+ try
+ {
+ while ( list.hasMore() )
{
- assertEquals( "ldap://fermi:10389/ou=users,ou=system??base", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??base", e.getReferralInfo() );
- assertTrue( e.skipReferral() );
- assertEquals( "ldap://maxwell:10389/ou=users,ou=system??base", e.getReferralInfo() );
+ SearchResult result = list.next();
+ results.put( result.getName(), result );
}
-
- assertNull( results.get( "ou=remoteusers" ) );
+ }
+ catch ( ReferralException e )
+ {
+ assertEquals( "ldap://fermi:10389/ou=users,ou=system??base", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://hertz:10389/ou=users,dc=example,dc=com??base", e.getReferralInfo() );
+ assertTrue( e.skipReferral() );
+ assertEquals( "ldap://maxwell:10389/ou=users,ou=system??base", e.getReferralInfo() );
}
+ assertNull( results.get( "ou=remoteusers" ) );
+}
- /**
- * Test of an search operation with a referral
- *
- * search for "cn=alex karasulu" on "c=america, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
- @Test
- public void testSearchWithReferralThrow() throws Exception
- {
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- try
- {
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??sub", referral );
- }
+/**
+ * Test of an search operation with a referral
+ *
+ * search for "cn=alex karasulu" on "c=america, ou=system"
+ * we should get a referral URL thrown, which point to
+ * "c=usa, ou=system", and ask for a subtree search
+ */
+@Test
+public void testSearchWithReferralThrow() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+
+ try
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
+ }
+ catch ( ReferralException re )
+ {
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??sub", referral );
}
+}
- /**
- * Test of an search operation with a referral
- *
- * search for "cn=alex karasulu" on "c=america, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
- @Test
- public void testSearchBaseWithReferralThrow() throws Exception
- {
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+/**
+ * Test of an search operation with a referral
+ *
+ * search for "cn=alex karasulu" on "c=america, ou=system"
+ * we should get a referral URL thrown, which point to
+ * "c=usa, ou=system", and ask for a subtree search
+ */
+@Test
+public void testSearchBaseWithReferralThrow() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- try
- {
- ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
+ try
+ {
+ ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
}
-
-
- /**
- * Test of an search operation with a referral after the entry
- * has been renamed.
- *
- * search for "cn=alex karasulu" on "c=usa, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
- @Test
- public void testSearchBaseWithReferralThrowAfterRename() throws Exception
+ catch ( ReferralException re )
{
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+ }
+}
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- try
- {
- ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
-
- ((LdapContext)ctx).setRequestControls( new javax.naming.ldap.Control[]{new ManageReferralControl()} );
+/**
+ * Test of an search operation with a referral after the entry
+ * has been renamed.
+ *
+ * search for "cn=alex karasulu" on "c=usa, ou=system"
+ * we should get a referral URL thrown, which point to
+ * "c=usa, ou=system", and ask for a subtree search
+ */
+@Test
+public void testSearchBaseWithReferralThrowAfterRename() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- // Now let's move the entry
- ctx.rename( "c=america,ou=Countries,ou=system", "c=USA,ou=Countries,ou=system" );
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ try
+ {
+ ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
+ }
+ catch ( ReferralException re )
+ {
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+ }
- ((LdapContext)ctx).setRequestControls( new javax.naming.ldap.Control[]{} );
+ ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+ { new ManageReferralControl() } );
- try
- {
- ctx.search( "c=usa,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
+ // Now let's move the entry
+ ctx.rename( "c=america,ou=Countries,ou=system", "c=USA,ou=Countries,ou=system" );
+
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+
+ ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+ {} );
+
+ try
+ {
+ ctx.search( "c=usa,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
+ }
+ catch ( ReferralException re )
+ {
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
}
+}
}
\ No newline at end of file
Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchMoveAndRenameIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchMoveAndRenameIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchMoveAndRenameIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchMoveAndRenameIT.java Tue Jan 24 16:22:33 2012
@@ -19,7 +19,7 @@
*/
package org.apache.directory.server.operations.search;
-
+
import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -52,146 +52,147 @@ import org.junit.runner.RunWith;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-@RunWith ( FrameworkRunner.class )
-@CreateLdapServer (
- transports =
- {
- @CreateTransport( protocol = "LDAP" )
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(
+ transports =
+ {
+ @CreateTransport(protocol = "LDAP")
})
-@ApplyLdifs( {
- // Add new ref for ou=RemoteUsers
- "dn: ou=RemoteUsers,ou=system",
- "objectClass: top",
- "objectClass: referral",
- "objectClass: extensibleObject",
- "ou: RemoteUsers",
- "ref: ldap://fermi:10389/ou=users,ou=system",
- "ref: ldap://hertz:10389/ou=users,dc=example,dc=com",
- "ref: ldap://maxwell:10389/ou=users,ou=system",
-
- "dn: c=France,ou=system",
- "objectClass: top",
- "objectClass: country",
- "c: France",
-
- "dn: c=USA,ou=system",
- "objectClass: top",
- "objectClass: country",
- "c: USA",
-
- "dn: l=Paris,c=france,ou=system",
- "objectClass: top",
- "objectClass: locality",
- "l: Paris",
-
- "dn: l=Jacksonville,c=usa,ou=system",
- "objectClass: top",
- "objectClass: locality",
- "l: Jacksonville",
-
- "dn: cn=emmanuel lecharny,l=paris,c=france,ou=system",
- "objectClass: top",
- "objectClass: person",
- "objectClass: residentialPerson",
- "cn: emmanuel lecharny",
- "sn: elecharny",
- "l: Paris",
-
- "dn: cn=alex karasulu,l=jacksonville,c=usa,ou=system",
- "objectClass: top",
- "objectClass: person",
- "objectClass: residentialPerson",
- "cn: alex karasulu",
- "sn: karasulu",
- "l: Jacksonville",
-
- "dn: ou=Countries,ou=system",
- "objectClass: top",
- "objectClass: organizationalUnit",
- "ou: Countries"
- }
-)
+@ApplyLdifs(
+ {
+ // Add new ref for ou=RemoteUsers
+ "dn: ou=RemoteUsers,ou=system",
+ "objectClass: top",
+ "objectClass: referral",
+ "objectClass: extensibleObject",
+ "ou: RemoteUsers",
+ "ref: ldap://fermi:10389/ou=users,ou=system",
+ "ref: ldap://hertz:10389/ou=users,dc=example,dc=com",
+ "ref: ldap://maxwell:10389/ou=users,ou=system",
+
+ "dn: c=France,ou=system",
+ "objectClass: top",
+ "objectClass: country",
+ "c: France",
+
+ "dn: c=USA,ou=system",
+ "objectClass: top",
+ "objectClass: country",
+ "c: USA",
+
+ "dn: l=Paris,c=france,ou=system",
+ "objectClass: top",
+ "objectClass: locality",
+ "l: Paris",
+
+ "dn: l=Jacksonville,c=usa,ou=system",
+ "objectClass: top",
+ "objectClass: locality",
+ "l: Jacksonville",
+
+ "dn: cn=emmanuel lecharny,l=paris,c=france,ou=system",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: residentialPerson",
+ "cn: emmanuel lecharny",
+ "sn: elecharny",
+ "l: Paris",
+
+ "dn: cn=alex karasulu,l=jacksonville,c=usa,ou=system",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: residentialPerson",
+ "cn: alex karasulu",
+ "sn: karasulu",
+ "l: Jacksonville",
+
+ "dn: ou=Countries,ou=system",
+ "objectClass: top",
+ "objectClass: organizationalUnit",
+ "ou: Countries"
+})
public class ReferralSearchMoveAndRenameIT extends AbstractLdapTestUnit
-{
- @Before
- public void setupReferrals() throws Exception
- {
- getLdapServer().getDirectoryService().getChangeLog().setEnabled( false );
-
- String ldif =
+{
+@Before
+public void setupReferrals() throws Exception
+{
+ getLdapServer().getDirectoryService().getChangeLog().setEnabled( false );
+
+ String ldif =
"dn: c=europ,ou=Countries,ou=system\n" +
- "objectClass: top\n" +
- "objectClass: referral\n" +
- "objectClass: extensibleObject\n" +
- "c: europ\n" +
- "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
-
- "dn: c=america,ou=Countries,ou=system\n" +
- "objectClass: top\n" +
- "objectClass: referral\n" +
- "objectClass: extensibleObject\n" +
- "c: america\n" +
- "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
-
- LdifReader reader = new LdifReader( new StringReader( ldif ) );
-
- while ( reader.hasNext() )
- {
- LdifEntry entry = reader.next();
- getLdapServer().getDirectoryService().getAdminSession().add(
- new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
- }
+ "objectClass: top\n" +
+ "objectClass: referral\n" +
+ "objectClass: extensibleObject\n" +
+ "c: europ\n" +
+ "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
+
+ "dn: c=america,ou=Countries,ou=system\n" +
+ "objectClass: top\n" +
+ "objectClass: referral\n" +
+ "objectClass: extensibleObject\n" +
+ "c: america\n" +
+ "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
+
+ LdifReader reader = new LdifReader( new StringReader( ldif ) );
+
+ while ( reader.hasNext() )
+ {
+ LdifEntry entry = reader.next();
+ getLdapServer().getDirectoryService().getAdminSession().add(
+ new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
}
-
-
+}
+
+
+/**
+ * Test of an search operation with a referral after the entry
+ * has been moved.
+ *
+ * search for "cn=alex karasulu" on "c=usa, ou=system"
+ * we should get a referral URL thrown, which point to
+ * "c=usa, ou=system", and ask for a subtree search
+ */
+@Test
+public void testSearchBaseWithReferralThrowAfterMoveAndRename() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- /**
- * Test of an search operation with a referral after the entry
- * has been moved.
- *
- * search for "cn=alex karasulu" on "c=usa, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
- @Test
- public void testSearchBaseWithReferralThrowAfterMoveAndRename() throws Exception
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+
+ try
{
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+ ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
+ }
+ catch ( ReferralException re )
+ {
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+ }
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+ { new ManageReferralControl() } );
- try
- {
- ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
-
- ((LdapContext)ctx).setRequestControls( new javax.naming.ldap.Control[]{new ManageReferralControl()} );
+ // Now let's move the entry
+ ctx.rename( "c=america,ou=Countries,ou=system", "c=us,ou=system" );
- // Now let's move the entry
- ctx.rename( "c=america,ou=Countries,ou=system", "c=us,ou=system" );
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+ {} );
- ((LdapContext)ctx).setRequestControls( new javax.naming.ldap.Control[]{} );
+ try
+ {
+ NamingEnumeration<SearchResult> results = ctx.search( "c=us,ou=system", "(cn=alex karasulu)", controls );
- try
- {
- NamingEnumeration<SearchResult> results = ctx.search( "c=us,ou=system", "(cn=alex karasulu)", controls );
-
- results.next();
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
+ results.next();
+ fail( "Should fail here throwing a ReferralException" );
+ }
+ catch ( ReferralException re )
+ {
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
}
+}
}
\ No newline at end of file
Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchNoRevertIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchNoRevertIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchNoRevertIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/ReferralSearchNoRevertIT.java Tue Jan 24 16:22:33 2012
@@ -19,7 +19,7 @@
*/
package org.apache.directory.server.operations.search;
-
+
import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -55,169 +55,172 @@ import org.junit.runner.RunWith;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-@RunWith ( FrameworkRunner.class )
-@CreateDS(
+@RunWith(FrameworkRunner.class)
+@CreateDS(
name = "ReferralSearchNoReertDS",
partitions =
- {
- @CreatePartition(
- name = "example",
- suffix = "dc=example,dc=com",
- contextEntry = @ContextEntry(
- entryLdif =
+ {
+ @CreatePartition(
+ name = "example",
+ suffix = "dc=example,dc=com",
+ contextEntry = @ContextEntry(
+ entryLdif =
"dn: dc=example,dc=com\n" +
- "dc: example\n" +
- "objectClass: top\n" +
- "objectClass: domain\n\n" ),
- indexes =
- {
- @CreateIndex( attribute = "objectClass" ),
- @CreateIndex( attribute = "dc" ),
- @CreateIndex( attribute = "ou" )
- } )
- } )
-@CreateLdapServer (
- transports =
- {
- @CreateTransport( protocol = "LDAP" )
+ "dc: example\n" +
+ "objectClass: top\n" +
+ "objectClass: domain\n\n"),
+ indexes =
+ {
+ @CreateIndex(attribute = "objectClass"),
+ @CreateIndex(attribute = "dc"),
+ @CreateIndex(attribute = "ou")
+ })
})
-@ApplyLdifs( {
- // Add new ref for ou=RemoteUsers
- "dn: ou=RemoteUsers,ou=system",
- "objectClass: top",
- "objectClass: referral",
- "objectClass: extensibleObject",
- "ou: RemoteUsers",
- "ref: ldap://fermi:10389/ou=users,ou=system",
- "ref: ldap://hertz:10389/ou=users,dc=example,dc=com",
- "ref: ldap://maxwell:10389/ou=users,ou=system",
-
- "dn: c=France,ou=system",
- "objectClass: top",
- "objectClass: country",
- "c: France",
-
- "dn: c=USA,ou=system",
- "objectClass: top",
- "objectClass: country",
- "c: USA",
-
- "dn: l=Paris,c=france,ou=system",
- "objectClass: top",
- "objectClass: locality",
- "l: Paris",
-
- "dn: l=Jacksonville,c=usa,ou=system",
- "objectClass: top",
- "objectClass: locality",
- "l: Jacksonville",
-
- "dn: cn=emmanuel lecharny,l=paris,c=france,ou=system",
- "objectClass: top",
- "objectClass: person",
- "objectClass: residentialPerson",
- "cn: emmanuel lecharny",
- "sn: elecharny",
- "l: Paris",
-
- "dn: cn=alex karasulu,l=jacksonville,c=usa,ou=system",
- "objectClass: top",
- "objectClass: person",
- "objectClass: residentialPerson",
- "cn: alex karasulu",
- "sn: karasulu",
- "l: Jacksonville",
-
- "dn: ou=Countries,ou=system",
- "objectClass: top",
- "objectClass: organizationalUnit",
- "ou: Countries"
- }
-)
+@CreateLdapServer(
+ transports =
+ {
+ @CreateTransport(protocol = "LDAP")
+ })
+@ApplyLdifs(
+ {
+ // Add new ref for ou=RemoteUsers
+ "dn: ou=RemoteUsers,ou=system",
+ "objectClass: top",
+ "objectClass: referral",
+ "objectClass: extensibleObject",
+ "ou: RemoteUsers",
+ "ref: ldap://fermi:10389/ou=users,ou=system",
+ "ref: ldap://hertz:10389/ou=users,dc=example,dc=com",
+ "ref: ldap://maxwell:10389/ou=users,ou=system",
+
+ "dn: c=France,ou=system",
+ "objectClass: top",
+ "objectClass: country",
+ "c: France",
+
+ "dn: c=USA,ou=system",
+ "objectClass: top",
+ "objectClass: country",
+ "c: USA",
+
+ "dn: l=Paris,c=france,ou=system",
+ "objectClass: top",
+ "objectClass: locality",
+ "l: Paris",
+
+ "dn: l=Jacksonville,c=usa,ou=system",
+ "objectClass: top",
+ "objectClass: locality",
+ "l: Jacksonville",
+
+ "dn: cn=emmanuel lecharny,l=paris,c=france,ou=system",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: residentialPerson",
+ "cn: emmanuel lecharny",
+ "sn: elecharny",
+ "l: Paris",
+
+ "dn: cn=alex karasulu,l=jacksonville,c=usa,ou=system",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: residentialPerson",
+ "cn: alex karasulu",
+ "sn: karasulu",
+ "l: Jacksonville",
+
+ "dn: ou=Countries,ou=system",
+ "objectClass: top",
+ "objectClass: organizationalUnit",
+ "ou: Countries"
+})
public class ReferralSearchNoRevertIT extends AbstractLdapTestUnit
{
-
- @Before
- public void setupReferrals() throws Exception
- {
- getLdapServer().getDirectoryService().getChangeLog().setEnabled( false );
- String ldif =
+@Before
+public void setupReferrals() throws Exception
+{
+ getLdapServer().getDirectoryService().getChangeLog().setEnabled( false );
+
+ String ldif =
"dn: c=europ,ou=Countries,ou=system\n" +
- "objectClass: top\n" +
- "objectClass: referral\n" +
- "objectClass: extensibleObject\n" +
- "c: europ\n" +
- "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
-
- "dn: c=america,ou=Countries,ou=system\n" +
- "objectClass: top\n" +
- "objectClass: referral\n" +
- "objectClass: extensibleObject\n" +
- "c: america\n" +
- "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
+ "objectClass: top\n" +
+ "objectClass: referral\n" +
+ "objectClass: extensibleObject\n" +
+ "c: europ\n" +
+ "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=france,ou=system\n\n" +
+
+ "dn: c=america,ou=Countries,ou=system\n" +
+ "objectClass: top\n" +
+ "objectClass: referral\n" +
+ "objectClass: extensibleObject\n" +
+ "c: america\n" +
+ "ref: ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system\n\n";
- LdifReader reader = new LdifReader( new StringReader( ldif ) );
- while ( reader.hasNext() )
- {
- LdifEntry entry = reader.next();
- getLdapServer().getDirectoryService().getAdminSession().add(
- new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
- }
+ LdifReader reader = new LdifReader( new StringReader( ldif ) );
+ while ( reader.hasNext() )
+ {
+ LdifEntry entry = reader.next();
+ getLdapServer().getDirectoryService().getAdminSession().add(
+ new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(), entry.getEntry() ) );
}
+}
-
- /**
- * Test of an search operation with a referral after the entry
- * has been moved.
- *
- * search for "cn=alex karasulu" on "c=america, ou=system"
- * we should get a referral URL thrown, which point to
- * "c=usa, ou=system", and ask for a subtree search
- */
- @Test
- public void testSearchBaseWithReferralThrowAfterMove() throws Exception
- {
- DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+/**
+ * Test of an search operation with a referral after the entry
+ * has been moved.
+ *
+ * search for "cn=alex karasulu" on "c=america, ou=system"
+ * we should get a referral URL thrown, which point to
+ * "c=usa, ou=system", and ask for a subtree search
+ */
+@Test
+public void testSearchBaseWithReferralThrowAfterMove() throws Exception
+{
+ DirContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
+
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- try
- {
- ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
-
- ((LdapContext)ctx).setRequestControls( new javax.naming.ldap.Control[]{new ManageReferralControl()} );
+ try
+ {
+ ctx.search( "c=america,ou=Countries,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
+ }
+ catch ( ReferralException re )
+ {
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
+ }
- // Now let's move the entry
- ctx.rename( "c=america,ou=Countries,ou=system", "c=america,ou=system" );
+ ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+ { new ManageReferralControl() } );
- controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ // Now let's move the entry
+ ctx.rename( "c=america,ou=Countries,ou=system", "c=america,ou=system" );
- ((LdapContext)ctx).setRequestControls( new javax.naming.ldap.Control[]{} );
+ controls.setSearchScope( SearchControls.OBJECT_SCOPE );
- try
- {
- ctx.search( "c=america,ou=system", "(cn=alex karasulu)", controls );
- fail( "Should fail here throwing a ReferralException" );
- }
- catch ( ReferralException re )
- {
- String referral = (String)re.getReferralInfo();
- assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
- }
+ ( ( LdapContext ) ctx ).setRequestControls( new javax.naming.ldap.Control[]
+ {} );
+
+ try
+ {
+ ctx.search( "c=america,ou=system", "(cn=alex karasulu)", controls );
+ fail( "Should fail here throwing a ReferralException" );
}
-
- @After
- public void after()
+ catch ( ReferralException re )
{
- getLdapServer().getDirectoryService().getChangeLog().setEnabled( true );
+ String referral = ( String ) re.getReferralInfo();
+ assertEquals( "ldap://localhost:" + getLdapServer().getPort() + "/c=usa,ou=system??base", referral );
}
+}
+
+
+@After
+public void after()
+{
+ getLdapServer().getDirectoryService().getChangeLog().setEnabled( true );
+}
}
\ No newline at end of file