1
+ package org .springframework .ldap .test .unboundid ;
2
+
3
+ import static org .assertj .core .api .Assertions .assertThat ;
4
+
5
+ import java .io .IOException ;
6
+ import java .nio .file .Files ;
7
+ import java .nio .file .Path ;
8
+
9
+ import javax .naming .NamingException ;
10
+ import javax .naming .directory .Attributes ;
11
+
12
+ import org .junit .BeforeClass ;
13
+ import org .junit .Test ;
14
+ import org .springframework .context .support .ClassPathXmlApplicationContext ;
15
+ import org .springframework .ldap .core .AttributesMapper ;
16
+ import org .springframework .ldap .core .LdapTemplate ;
17
+ import org .springframework .ldap .query .LdapQueryBuilder ;
18
+
19
+ public class EmbeddedLdapServerTest {
20
+
21
+ private static String tempLogFile ;
22
+
23
+ @ BeforeClass
24
+ public static void before () throws IOException {
25
+ tempLogFile = Files .createTempFile ("ldap-log-" , ".txt" ).toAbsolutePath ().toString ();
26
+ }
27
+
28
+ @ Test
29
+ public void testServerStartup_withCustomConfig () {
30
+
31
+ EmbeddedLdapServer .Builder serverBuilder = EmbeddedLdapServer .Builder
32
+ .withEntry (null )
33
+ .withPort (1234 )
34
+ .withConfigurationCustomizer (config -> config .setCodeLogDetails (tempLogFile , true ));
35
+
36
+ try (EmbeddedLdapServer server = serverBuilder .build ()) {
37
+ server .start ();
38
+
39
+ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
40
+ "/applicationContext-testContextSource-withCustomInterceptor.xml" );
41
+ LdapTemplate ldapTemplate = ctx .getBean (LdapTemplate .class );
42
+ assertThat (ldapTemplate ).isNotNull ();
43
+
44
+ ldapTemplate .search (LdapQueryBuilder .query ().where ("objectclass" ).is ("person" ), new AttributesMapper <>() {
45
+ public String mapFromAttributes (Attributes attrs ) throws NamingException {
46
+ return (String ) attrs .get ("cn" ).get ();
47
+ }
48
+ });
49
+
50
+ assertThat (Path .of (tempLogFile )).isNotEmptyFile ();
51
+ }
52
+
53
+ }
54
+
55
+ }
0 commit comments