Load entries from LDIF file

The following example demonstrates how to use the LDAP Maven Plugin to load directory contents from LDIF format before integration tests are performed.

  • LDAP Directory Server

    In this example we are assuming that Apache Directory Server is being used and is installed locally on port 10389 with the default administration account (uid=admin,ou=system) and password (secret). Furthermore, we are assuming that the base DN has not been modified from the default (o=sevenSeas).

Create LDIF file

Create a file called load.ldif with the following contents:

dn: ou=People,o=sevenSeas
changetype: add
ou: People
objectclass: organizationalUnit

dn: cn=Bart Simpson,ou=People,o=sevenSeas
changetype: add
cn: Bart Simpson
sn: Simpson
givenName: Bart
uid: bsimpson
objectclass: inetOrgPerson

dn: cn=Lisa Simpson,ou=People,o=sevenSeas
cn: Lisa Simpson
sn: Simpson
givenName: Lisa
uid: lsimpson
title: Kid
objectclass: inetOrgPerson

dn: cn=Maggie simpson,ou=People,o=sevenSeas
cn: Maggie Simpson
sn: Simpson
givenName: Maggie
uid: msimpson1
title: Baby
objectclass: inetOrgPerson

dn: cn=Homer Simpson,ou=People,o=sevenSeas
changetype: add
cn: Homer Simpson
sn: Simpson
givenName: Homer
uid: hsimpson
title: Parent
objectclass: inetOrgPerson

dn: cn=Marge Simpson,ou=People,o=sevenSeas
changetype: add
cn: Marge Simpson
sn: Simpson
givenName: Marge
uid: msimpson
title: Parent
objectclass: inetOrgPerson

Configure a POM

Add the following configuration to your project POM to load the data during test preparation:

<project>
  <modelVersion>4.0.0</modelVersion>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.btmatthews.maven.plugins.ldap</groupId>
        <artifactId>parent</artifactId>
        <executions>
          <execution>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>load</goal>
            </goals>
            <configuration>
              <host>localhost</host>
              <port>10389</port>
              <authDn>uid=admin,ou=system</authDn>
              <passwd>secret</passwd>
              <continueOnError>true</continueOnError>
              <sources>
                <ldif>load.ldif</ldif>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>