Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:44:28+00:00 2026-06-14T11:44:28+00:00

Spring embedded ldap server in unit tests is similar, however no answer was given

  • 0

Spring embedded ldap server in unit tests is similar, however no answer was given that suites me.

I can run my integration tests with spring and the embedded ldap server of spring-security without any problems.
However, I haven’t find a way yet to clear the embedded ldap server and load the ldif again to provide a common test environment.

LdapTestUtils of spring-ldap provides a cleanAndSetup() method. However, this does not work with the suggested version (1.5.5) of apache-ds, as LdifFileLoader now requires a CoreSession instead of the DirContext provided by LdapTestUtils. This causes a

java.lang.NoSuchMethodError:
org.apache.directory.server.protocol.shared.store.LdifFileLoader.<init>(Ljavax/naming/directory/DirContext;Ljava/lang/String;)

I only want a method that clear the embedded ldap server and fills it with the ldif file again (as done on startup).
Does anybody have an idea regarding this?

Version: spring 3.1, spring-ldap 1.3, spring-security 3.1, apache-ds 1.5.5

Solution (Thanks to Luke Taylor):

@Inject
private ApplicationContext applicationContext;

@Before
public void reloadLdapDirectory() throws NamingException, IOException{
    ApacheDSContainer apacheDSContainer = (ApacheDSContainer) applicationContext.getBean(BeanIds.EMBEDDED_APACHE_DS);
    LdapTestUtils.clearSubContexts(contextSource, DistinguishedName.EMPTY_PATH);

    ClassPathResource classPathResource = new ClassPathResource("ldap.ldif");

    File tempFile = File.createTempFile("spring_ldap_test", ".ldif");
    try {
        InputStream inputStream = classPathResource.getInputStream();
        IOUtils.copy(inputStream, new FileOutputStream(tempFile));
        LdifFileLoader fileLoader = new LdifFileLoader(apacheDSContainer.getService().getAdminSession(), tempFile.getAbsolutePath());
        fileLoader.execute();
    }
    finally {
        try {
            tempFile.delete();
        }
        catch (Exception e) {
            // Ignore this
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:44:29+00:00Added an answer on June 14, 2026 at 11:44 am

    Why not take a look at Spring Security’s LDAP integration tests and use those as a guide?

    At the moment, these just use an LDAP template to clear out data that each test has created if necessary (for speed), but there is also a commented-out Junit @After method which does reload an LDIF file. The CoreSession is obtained by calling getAdminSession() on the server instance (a DefaultDirectoryService).

    If you really have to run the tests using an XML application context, using the <ldap-server /> element, you can use:

    getBeanByName(BeanIds.EMBEDDED_APACHE_DS).getService()
    

    to get access to the DefaultDirectoryService instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Spring config for unit tests that includes ActiveMQ embedded broker,
We are trying to run integration tests of Spring based code on an embedded
I am using Spring's embedded-database (default DB is HSQLDB) for running some unit tests.
I'm using Spring embedded database in my unit tests. From Spring documentantatio: <jdbc:embedded-database id=dataSource>
I have a spring application that uses an embedded Jetty instance. Since I am
Does anybody has an experience with Spring Integration project as embedded ESB? I'm highly
I have configured spring security with a ldap server (but continue reading, it's not
I am experiencing trouble with my embedded tomcat: when I run my Spring app
I have a Spring application and I want to run in it an embedded
Spring support JUnit quite well on that: With the RunWith and ContextConfiguration annotation, things

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.