Skip to content

Commit d5cebef

Browse files
committed
Moved most of the unit tests from embedded-ldap-junit to embedded-ldap-core
1 parent 6550282 commit d5cebef

24 files changed

+2339
-1
lines changed

embedded-ldap-core/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,25 @@
3333
<artifactId>slf4j-api</artifactId>
3434
<version>${slf4j.version}</version>
3535
</dependency>
36+
37+
<!-- Test dependencies -->
38+
<dependency>
39+
<groupId>junit</groupId>
40+
<artifactId>junit</artifactId>
41+
<version>${junit.version}</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.bouncycastle</groupId>
46+
<artifactId>bcprov-jdk15on</artifactId>
47+
<version>${bouncycastle.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.bouncycastle</groupId>
52+
<artifactId>bcpkix-jdk15on</artifactId>
53+
<version>${bouncycastle.version}</version>
54+
<scope>test</scope>
55+
</dependency>
3656
</dependencies>
3757
</project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertNotNull;
6+
7+
public class AbstractEmbeddedLdapBuilderTest {
8+
9+
@Test
10+
public void bindingToLegalPort() {
11+
assertNotNull(FakeEmbeddedLdapBuilder.newInstance().bindingToPort(9999));
12+
}
13+
14+
@Test(expected = IllegalStateException.class)
15+
public void testPrematureLdapConnection() throws Exception {
16+
FakeEmbeddedLdapBuilder.newInstance().build().ldapConnection();
17+
18+
}
19+
20+
@Test(expected = IllegalStateException.class)
21+
public void testPrematureContext() throws Exception {
22+
FakeEmbeddedLdapBuilder.newInstance().build().context();
23+
24+
}
25+
26+
@Test(expected = IllegalArgumentException.class)
27+
public void testUnknownLDIF() {
28+
FakeEmbeddedLdapBuilder.newInstance().importingLdifs("nonExisting.ldif").build();
29+
30+
}
31+
32+
@Test
33+
public void testNullLDIF() {
34+
assertNotNull(FakeEmbeddedLdapBuilder.newInstance().importingLdifs(null).build());
35+
36+
}
37+
38+
@Test(expected = IllegalStateException.class)
39+
public void testIllegalDSN() {
40+
FakeEmbeddedLdapBuilder.newInstance().usingBindDSN("bindDsn").build();
41+
42+
}
43+
44+
@Test(expected = IllegalArgumentException.class)
45+
public void testIllegalPort() {
46+
FakeEmbeddedLdapBuilder.newInstance().bindingToPort(Integer.MIN_VALUE).build();
47+
48+
}
49+
50+
@Test(expected = IllegalArgumentException.class)
51+
public void testSchemaNotFound() {
52+
FakeEmbeddedLdapBuilder.newInstance().withSchema("non-existing-schema.ldif").build();
53+
54+
}
55+
56+
@Test(expected = IllegalArgumentException.class)
57+
public void testSchemaIsNotAFile() {
58+
FakeEmbeddedLdapBuilder.newInstance().withSchema("folder").build();
59+
60+
}
61+
62+
@Test(expected = IllegalArgumentException.class)
63+
public void testSchemaIsInvalid() {
64+
FakeEmbeddedLdapBuilder.newInstance().withSchema("invalid.ldif").build();
65+
66+
}
67+
68+
@Test(expected = IllegalArgumentException.class)
69+
public void testSchemaFileUnsupportedIsInvalid() {
70+
FakeEmbeddedLdapBuilder.newInstance().withSchema("\"#%¤&&%/¤##¤¤").build();
71+
72+
}
73+
74+
@Test(expected = IllegalArgumentException.class)
75+
public void testInvalidPort() {
76+
FakeEmbeddedLdapBuilder.newInstance().bindingToPort(Integer.MAX_VALUE);
77+
78+
}
79+
80+
@Test(expected = IllegalArgumentException.class)
81+
public void testInvalidBindAddress() {
82+
FakeEmbeddedLdapBuilder.newInstance().bindingToAddress("åpsldfåpl");
83+
84+
}
85+
86+
87+
}
88+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import com.unboundid.ldap.sdk.schema.AttributeTypeDefinition;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
9+
10+
import static org.junit.Assert.assertNotNull;
11+
12+
public class EmbeddedLdapServerCustomSchemaDuplicatedTest {
13+
14+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
15+
.withSchema("standard-schema.ldif")
16+
.build();
17+
18+
@Before
19+
public void setup() throws LDAPException {
20+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
21+
}
22+
23+
@After
24+
public void teardown() throws LDAPException {
25+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
26+
}
27+
28+
@Test
29+
public void testFindCustomAttribute() throws Exception {
30+
final AttributeTypeDefinition changelogAttribute =
31+
embeddedLdapRule.ldapConnection().getSchema().getAttributeType("changelog");
32+
assertNotNull(changelogAttribute);
33+
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import com.unboundid.ldap.sdk.schema.AttributeTypeDefinition;
5+
import com.unboundid.ldap.sdk.schema.Schema;
6+
import org.junit.After;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
10+
11+
import static org.junit.Assert.assertNotNull;
12+
13+
public class EmbeddedLdapServerCustomStandardAndCustomSchemaTest {
14+
15+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
16+
.withSchema("custom-schema.ldif")
17+
.build();
18+
19+
@Before
20+
public void setup() throws LDAPException {
21+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
22+
}
23+
24+
@After
25+
public void teardown() throws LDAPException {
26+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
27+
}
28+
29+
@Test
30+
public void testFindCustomAttribute() throws Exception {
31+
final Schema currentSchema = embeddedLdapRule.ldapConnection().getSchema();
32+
final AttributeTypeDefinition changelogAttribute =
33+
currentSchema.getAttributeType("attribute");
34+
assertNotNull(changelogAttribute);
35+
assertNotNull(currentSchema.getObjectClass("type"));
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import com.unboundid.ldap.sdk.schema.Schema;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
9+
10+
import static org.junit.Assert.assertTrue;
11+
12+
public class EmbeddedLdapServerCustomWithoutSchemaTest {
13+
14+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
15+
.withoutDefaultSchema()
16+
.build();
17+
18+
@Before
19+
public void setup() throws LDAPException {
20+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
21+
}
22+
23+
@After
24+
public void teardown() throws LDAPException {
25+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
26+
}
27+
28+
@Test
29+
public void testEmptySchema() throws Exception {
30+
final Schema schema =
31+
embeddedLdapRule.ldapConnection().getSchema();
32+
assertTrue(schema.getAttributeTypes().isEmpty());
33+
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import com.unboundid.ldap.sdk.schema.AttributeTypeDefinition;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
9+
10+
import static org.junit.Assert.assertNotNull;
11+
12+
public class EmbeddedLdapServerCustomWithoutStandardSchemaTest {
13+
14+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
15+
.withoutDefaultSchema()
16+
.withSchema("standard-schema.ldif")
17+
.build();
18+
19+
@Before
20+
public void setup() throws LDAPException {
21+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
22+
}
23+
24+
@After
25+
public void teardown() throws LDAPException {
26+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
27+
}
28+
29+
@Test
30+
public void testFindCustomAttribute() throws Exception {
31+
final AttributeTypeDefinition changelogAttribute =
32+
embeddedLdapRule.ldapConnection().getSchema().getAttributeType("changelog");
33+
assertNotNull(changelogAttribute);
34+
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import com.unboundid.ldap.sdk.LDAPInterface;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
9+
10+
import static org.junit.Assert.assertArrayEquals;
11+
12+
public class EmbeddedLdapServerMultipleDSNs {
13+
14+
public static final String DSN_ROOT_ONE = "dc=zapodot,dc=com";
15+
public static final String DSN_ROOT_TWO = "dc=zapodot,dc=org";
16+
17+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
18+
.usingDomainDsn(DSN_ROOT_ONE)
19+
.usingDomainDsn(DSN_ROOT_TWO)
20+
.importingLdifs("example.ldif")
21+
.build();
22+
23+
@Before
24+
public void setup() throws LDAPException {
25+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
26+
}
27+
28+
@After
29+
public void teardown() throws LDAPException {
30+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
31+
}
32+
33+
@Test
34+
public void testCheckNamingContexts() throws Exception {
35+
final LDAPInterface ldapConnection = embeddedLdapRule.ldapConnection();
36+
final String[] namingContextDNs = ldapConnection.getRootDSE().getNamingContextDNs();
37+
assertArrayEquals(new String[]{DSN_ROOT_ONE, DSN_ROOT_TWO}, namingContextDNs);
38+
39+
}
40+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import org.junit.After;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
8+
9+
import static org.junit.Assert.assertNotNull;
10+
11+
public class EmbeddedLdapServerNoAuthTest {
12+
13+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder
14+
.newInstance()
15+
.usingBindCredentials(null)
16+
.usingDomainDsn("dc=zapodot,dc=org")
17+
.importingLdifs("example.ldif")
18+
.build();
19+
20+
@Before
21+
public void setup() throws LDAPException {
22+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
23+
}
24+
25+
@After
26+
public void teardown() throws LDAPException {
27+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
28+
}
29+
30+
@Test
31+
public void testConnect() throws Exception {
32+
assertNotNull(embeddedLdapRule.dirContext().search("cn=Sondre Eikanger Kvalo,ou=people,dc=zapodot,dc=org", null));
33+
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.zapodot.junit.ldap.internal;
2+
3+
import com.unboundid.ldap.sdk.LDAPException;
4+
import org.junit.After;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.zapodot.junit.ldap.EmbeddedLdapServer;
8+
9+
import static org.junit.Assert.assertArrayEquals;
10+
11+
public class EmbeddedLdapServerStandardContext {
12+
13+
private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
14+
.build();
15+
16+
@Before
17+
public void setup() throws LDAPException {
18+
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
19+
}
20+
21+
@After
22+
public void teardown() throws LDAPException {
23+
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
24+
}
25+
26+
@Test
27+
public void testUsingDefaultDomain() throws Exception {
28+
assertArrayEquals(new String[]{FakeEmbeddedLdapBuilder.DEFAULT_DOMAIN},
29+
embeddedLdapRule.ldapConnection().getRootDSE().getNamingContextDNs());
30+
31+
32+
}
33+
}

0 commit comments

Comments
 (0)