Add slice test annotation for LDAP
This commit adds new annotation `@DataLdapTest` which provides test infrastructure for LDAP. By default, embedded ldap server is initialized if available. See gh-8536
This commit is contained in:
committed by
Stephane Nicoll
parent
209ecf95f0
commit
2830bef95c
@@ -5702,6 +5702,55 @@ A list of the auto-configuration that is enabled by `@JdbcTest` can be
|
||||
|
||||
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-ldap-test]]
|
||||
==== Auto-configured Data LDAP tests
|
||||
`@DataLdapTest` can be used if you want to test LDAP applications. By default, it will
|
||||
configure an in-memory embedded LDAP (if available), configure a `LdapTemplate`, scan
|
||||
for `@Entry` classes and configure Spring Data LDAP repositories. Regular
|
||||
`@Component` beans will not be loaded into the `ApplicationContext`:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataLdapTest
|
||||
public class ExampleDataLdapTests {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
//
|
||||
}
|
||||
----
|
||||
|
||||
In-memory embedded LDAP generally works well for tests since it is fast and doesn't
|
||||
require any developer installation. If, however, you prefer to run tests against a real
|
||||
LDAP server you should exclude the embedded LDAP auto-configuration:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataLdapTest(excludeAutoConfiguration = EmbeddedLdapAutoConfiguration.class)
|
||||
public class ExampleDataLdapNonEmbeddedTests {
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
A list of the auto-configuration that is enabled by `@DataLdapTest` can be
|
||||
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
|
||||
|
||||
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-mongo-test]]
|
||||
==== Auto-configured Data MongoDB tests
|
||||
`@DataMongoTest` can be used if you want to test MongoDB applications. By default, it will
|
||||
|
||||
Reference in New Issue
Block a user