Commit 04ee374e authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add slice test annotation for LDAP"

Closes gh-8536
parent 2830bef9
......@@ -5702,55 +5702,6 @@ 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
......@@ -5853,6 +5804,55 @@ A list of the auto-configuration that is enabled by `@DataNeo4jTest` 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), 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-rest-client]]
==== Auto-configured REST clients
The `@RestClientTest` annotation can be used if you want to test REST clients. By default
......
......@@ -16,6 +16,8 @@
package org.springframework.boot.test.autoconfigure.data.ldap;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -59,10 +61,11 @@ public class DataLdapTestIntegrationTests {
@Test
public void testRepository() {
LdapQuery ldapQuery = LdapQueryBuilder.query().where("cn").is("Bob Smith");
ExampleEntry entry = this.exampleRepository.findOne(ldapQuery);
assertThat(entry.getDn())
Optional<ExampleEntry> entry = this.exampleRepository.findOne(ldapQuery);
assertThat(entry.isPresent());
assertThat(entry.get().getDn())
.isEqualTo(LdapUtils.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
assertThat(this.ldapTemplate.findOne(ldapQuery, ExampleEntry.class).getDn())
assertThat(this.ldapTemplate.findOne(ldapQuery, ExampleEntry.class) .getDn())
.isEqualTo(LdapUtils.newLdapName("cn=Bob Smith,ou=company1,c=Sweden,dc=spring,dc=org"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment