The following example demonstrates how to use the LDAP Maven Plugin to load directory contents from LDIF format before integration tests are performed.
In this example we are assuming that Apache Directory Server is being used and is installed locally on port 10389 with the default admininstration 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 a file called load.dif 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
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</groupId> <artifactId>ldap-maven-plugin</artifactId> <executions> <execution> <phase>pre-integration-test</phase> <goals> <goal>ldif-load</goal> </goals> <configuration> <version>3</version> <host>localhost</host> <port>10389</port> <authDn>uid=admin,ou=system</authDn> <passwd>secret</passwd> <continueOnError>true</continueOnError> <ldapFiles> <ldapFile>load.ldif</ldapFile> </ldapFiles> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>