Skip to content

Commit d34d82c

Browse files
authored
Merge pull request #9 from tisoft/master
Allow running the LDAP server with no schema at all
2 parents a4708cf + bd09c0f commit d34d82c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/main/java/org/zapodot/junit/ldap/EmbeddedLdapRuleBuilder.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ private InMemoryDirectoryServerConfig createInMemoryServerConfiguration() {
192192
bindPort,
193193
null);
194194
inMemoryDirectoryServerConfig.setListenerConfigs(listenerConfig);
195-
for (Schema s : customSchema().asSet()) {
196-
inMemoryDirectoryServerConfig.setSchema(s);
197-
}
195+
inMemoryDirectoryServerConfig.setSchema(customSchema());
198196
return inMemoryDirectoryServerConfig;
199197
} catch (LDAPException e) {
200198
throw new IllegalStateException(
@@ -211,7 +209,7 @@ private String[] domainDsnArray() {
211209
}
212210
}
213211

214-
private Optional<Schema> customSchema() {
212+
private Schema customSchema() {
215213
final List<File> schemaFiles = schemaFiles();
216214

217215
try {
@@ -220,9 +218,9 @@ private Optional<Schema> customSchema() {
220218
final Schema customSchema = initialSchema == null
221219
? Schema.getSchema(schemaFiles)
222220
: Schema.mergeSchemas(initialSchema, Schema.getSchema(schemaFiles));
223-
return Optional.fromNullable(customSchema);
221+
return customSchema;
224222
} else {
225-
return Optional.absent();
223+
return null;
226224
}
227225

228226
} catch (IOException | LDIFException | LDAPException e) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.zapodot.junit.ldap;
2+
3+
import com.unboundid.ldap.sdk.schema.Schema;
4+
import org.junit.Rule;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertTrue;
8+
9+
public class EmbeddedLdapRuleCustomWithoutSchemaTest {
10+
11+
@Rule
12+
public EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder.newInstance()
13+
.withoutDefaultSchema()
14+
.build();
15+
16+
@Test
17+
public void testEmptySchema() throws Exception {
18+
final Schema schema =
19+
embeddedLdapRule.ldapConnection().getSchema();
20+
assertTrue(schema.getAttributeTypes().isEmpty());
21+
22+
}
23+
}

0 commit comments

Comments
 (0)