[[testing]]
= Testing
This section covers testing with Spring LDAP. It contains the following topics:
* xref:testing.adoc#spring-ldap-testing-embedded-server[Using an Embedded Server]
* xref:testing.adoc#spring-ldap-testing-apacheds[ApacheDS]
* xref:testing.adoc#spring-ldap-testing-unboundid[UnboundID]
[[spring-ldap-testing-embedded-server]]
== Using an Embedded Server
`spring-ldap-test` supplies an embedded LDAP server that is based on https://directory.apache.org/apacheds/[ApacheDS] or https://www.ldap.com/unboundid-ldap-sdk-for-java[UnboundID].
NOTE: `spring-ldap-test` is compatible with ApacheDS 1.5.5. Newer versions of ApacheDS are not supported.
To get started, you need to include the `spring-ldap-test` dependency.
The following listing shows how to include the `spring-ldap-test` for Maven:
====
[source,xml,subs="+attributes"]
----
org.springframework.ldap
spring-ldap-test
{project-version}
test
----
====
The following listing shows how to include the `spring-ldap-test` for Gradle:
====
[source,groovy]
[subs="verbatim,quotes,attributes"]
----
testCompile "org.springframework.ldap:spring-ldap-test:{project-version}"
----
====
[[spring-ldap-testing-apacheds]]
== ApacheDS
To use ApacheDS, you need to include a number of ApacheDS dependencies.
The following example shows how to include the ApacheDS dependencies for Maven:
====
[source,xml]
----
org.apache.directory.server
apacheds-core
1.5.5
test
org.apache.directory.server
apacheds-core-entry
1.5.5
test
org.apache.directory.server
apacheds-protocol-shared
1.5.5
test
org.apache.directory.server
apacheds-protocol-ldap
1.5.5
test
org.apache.directory.server
apacheds-server-jndi
1.5.5
test
org.apache.directory.shared
shared-ldap
0.9.15
test
----
====
The following example shows how to include the ApacheDS dependencies for Gradle:
====
[source,groovy]
[subs="verbatim,quotes"]
----
testCompile "org.apache.directory.server:apacheds-core:1.5.5",
"org.apache.directory.server:apacheds-core-entry:1.5.5",
"org.apache.directory.server:apacheds-protocol-shared:1.5.5",
"org.apache.directory.server:apacheds-protocol-ldap:1.5.5",
"org.apache.directory.server:apacheds-server-jndi:1.5.5",
"org.apache.directory.shared:shared-ldap:0.9.15"
----
====
The following bean definition creates an embedded LDAP server:
====
[source,xml]
----
----
====
`spring-ldap-test` provides a mechanism to populate the LDAP server by using `org.springframework.ldap.test.LdifPopulator`. To use it, create a bean similar to the following:
====
[source,xml]
----
----
====
Another way to work against an embedded LDAP server is by using `org.springframework.ldap.test.TestContextSourceFactoryBean`, as follows:
====
[source,xml]
----
----
====
Also, `org.springframework.ldap.test.LdapTestUtils` provides methods to programmatically work with an embedded LDAP server.
[[spring-ldap-testing-unboundid]]
== UnboundID
To use UnboundID, you need to include an UnboundID dependency.
The following example shows how to include the UnboundID dependency for Maven:
====
[source,xml]
----
com.unboundid
unboundid-ldapsdk
3.1.1
test
----
====
The following example shows how to include the UnboundID dependency for Gradle:
====
[source,groovy]
[subs="verbatim,quotes"]
----
testCompile "com.unboundid:unboundid-ldapsdk:3.1.1"
----
====
The following bean definition creates an embedded LDAP server:
====
[source,xml]
----
----
====
`spring-ldap-test` provides a way to populate the LDAP server by using `org.springframework.ldap.test.unboundid.LdifPopulator`. To use it, create a bean similar to the following:
====
[source,xml]
----
----
====
Another way to work against an embedded LDAP server is by using `org.springframework.ldap.test.unboundid.TestContextSourceFactoryBean`.
To use it, create a bean similar to the following:
====
[source,xml]
----
----
====
Also, `org.springframework.ldap.test.unboundid.LdapTestUtils` provide methods to programmatically work with an embedded LDAP server.