title: Spring embedded ldap server in unit tests
body: <p>I am currently trying to use an embedded ldap server for unit tests.</p>
  
  <p>In Spring Security, you can quickly define an embedded ldap server for testing with the  tag with some sample data loaded from the specified ldif.</p>
  
  <p>I will be using Spring Ldap to perform ldap operations, and thinking of testing the usual CRUD features of my User service object.</p>
  
  <p>Is there, however, a way to ensure that the entries in the embedded server to be in the same consistent state (sort of like a delete all and reload the ldif entries) for each test I am running?</p>
  
  <p>I thought of the following:
  1) Indicate that the method dirties the context, and force a recreation of the embedded ldap server, which sounds painful as it would have to restart the server for every method
  2) Create the test entries in a test organization, such that I can unbind them and simply load in the ldif file again there.</p>
  
  <p>I prefer 2, but it seems like the Spring LDAP has no good helpers to load and send across the content of a ldif file.</p>
  
  <p>Any suggestions on how you perform ldap testing with an embedded ldap server of spring, or of the two possible solutions I mention?</p>
  
  <p>Thanks</p>