Skip to content

Commit 328ae8c

Browse files
committed
builder pattern
1 parent 7af94ea commit 328ae8c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ public void shutdown() {
102102
this.directoryServer.shutDown(true);
103103
}
104104

105-
}
105+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)