Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
04ee374e
Commit
04ee374e
authored
Apr 14, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add slice test annotation for LDAP"
Closes gh-8536
parent
2830bef9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
52 deletions
+55
-52
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+49
-49
DataLdapTestIntegrationTests.java
...autoconfigure/data/ldap/DataLdapTestIntegrationTests.java
+6
-3
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
04ee374e
...
...
@@ -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
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestIntegrationTests.java
View file @
04ee374e
...
...
@@ -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"
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment