Skip to content

Commit

Permalink
Moved most of the unit tests from embedded-ldap-junit to embedded-lda…
Browse files Browse the repository at this point in the history
…p-core
  • Loading branch information
bjansen committed Jul 30, 2021
1 parent 6550282 commit d5cebef
Show file tree
Hide file tree
Showing 24 changed files with 2,339 additions and 1 deletion.
20 changes: 20 additions & 0 deletions embedded-ldap-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,25 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.zapodot.junit.ldap.internal;

import org.junit.Test;

import static org.junit.Assert.assertNotNull;

public class AbstractEmbeddedLdapBuilderTest {

@Test
public void bindingToLegalPort() {
assertNotNull(FakeEmbeddedLdapBuilder.newInstance().bindingToPort(9999));
}

@Test(expected = IllegalStateException.class)
public void testPrematureLdapConnection() throws Exception {
FakeEmbeddedLdapBuilder.newInstance().build().ldapConnection();

}

@Test(expected = IllegalStateException.class)
public void testPrematureContext() throws Exception {
FakeEmbeddedLdapBuilder.newInstance().build().context();

}

@Test(expected = IllegalArgumentException.class)
public void testUnknownLDIF() {
FakeEmbeddedLdapBuilder.newInstance().importingLdifs("nonExisting.ldif").build();

}

@Test
public void testNullLDIF() {
assertNotNull(FakeEmbeddedLdapBuilder.newInstance().importingLdifs(null).build());

}

@Test(expected = IllegalStateException.class)
public void testIllegalDSN() {
FakeEmbeddedLdapBuilder.newInstance().usingBindDSN("bindDsn").build();

}

@Test(expected = IllegalArgumentException.class)
public void testIllegalPort() {
FakeEmbeddedLdapBuilder.newInstance().bindingToPort(Integer.MIN_VALUE).build();

}

@Test(expected = IllegalArgumentException.class)
public void testSchemaNotFound() {
FakeEmbeddedLdapBuilder.newInstance().withSchema("non-existing-schema.ldif").build();

}

@Test(expected = IllegalArgumentException.class)
public void testSchemaIsNotAFile() {
FakeEmbeddedLdapBuilder.newInstance().withSchema("folder").build();

}

@Test(expected = IllegalArgumentException.class)
public void testSchemaIsInvalid() {
FakeEmbeddedLdapBuilder.newInstance().withSchema("invalid.ldif").build();

}

@Test(expected = IllegalArgumentException.class)
public void testSchemaFileUnsupportedIsInvalid() {
FakeEmbeddedLdapBuilder.newInstance().withSchema("\"#%¤&&%/¤##¤¤").build();

}

@Test(expected = IllegalArgumentException.class)
public void testInvalidPort() {
FakeEmbeddedLdapBuilder.newInstance().bindingToPort(Integer.MAX_VALUE);

}

@Test(expected = IllegalArgumentException.class)
public void testInvalidBindAddress() {
FakeEmbeddedLdapBuilder.newInstance().bindingToAddress("åpsldfåpl");

}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.schema.AttributeTypeDefinition;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertNotNull;

public class EmbeddedLdapServerCustomSchemaDuplicatedTest {

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
.withSchema("standard-schema.ldif")
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testFindCustomAttribute() throws Exception {
final AttributeTypeDefinition changelogAttribute =
embeddedLdapRule.ldapConnection().getSchema().getAttributeType("changelog");
assertNotNull(changelogAttribute);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.schema.AttributeTypeDefinition;
import com.unboundid.ldap.sdk.schema.Schema;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertNotNull;

public class EmbeddedLdapServerCustomStandardAndCustomSchemaTest {

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
.withSchema("custom-schema.ldif")
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testFindCustomAttribute() throws Exception {
final Schema currentSchema = embeddedLdapRule.ldapConnection().getSchema();
final AttributeTypeDefinition changelogAttribute =
currentSchema.getAttributeType("attribute");
assertNotNull(changelogAttribute);
assertNotNull(currentSchema.getObjectClass("type"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.schema.Schema;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertTrue;

public class EmbeddedLdapServerCustomWithoutSchemaTest {

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
.withoutDefaultSchema()
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testEmptySchema() throws Exception {
final Schema schema =
embeddedLdapRule.ldapConnection().getSchema();
assertTrue(schema.getAttributeTypes().isEmpty());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.schema.AttributeTypeDefinition;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertNotNull;

public class EmbeddedLdapServerCustomWithoutStandardSchemaTest {

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
.withoutDefaultSchema()
.withSchema("standard-schema.ldif")
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testFindCustomAttribute() throws Exception {
final AttributeTypeDefinition changelogAttribute =
embeddedLdapRule.ldapConnection().getSchema().getAttributeType("changelog");
assertNotNull(changelogAttribute);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPInterface;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertArrayEquals;

public class EmbeddedLdapServerMultipleDSNs {

public static final String DSN_ROOT_ONE = "dc=zapodot,dc=com";
public static final String DSN_ROOT_TWO = "dc=zapodot,dc=org";

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
.usingDomainDsn(DSN_ROOT_ONE)
.usingDomainDsn(DSN_ROOT_TWO)
.importingLdifs("example.ldif")
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testCheckNamingContexts() throws Exception {
final LDAPInterface ldapConnection = embeddedLdapRule.ldapConnection();
final String[] namingContextDNs = ldapConnection.getRootDSE().getNamingContextDNs();
assertArrayEquals(new String[]{DSN_ROOT_ONE, DSN_ROOT_TWO}, namingContextDNs);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertNotNull;

public class EmbeddedLdapServerNoAuthTest {

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder
.newInstance()
.usingBindCredentials(null)
.usingDomainDsn("dc=zapodot,dc=org")
.importingLdifs("example.ldif")
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testConnect() throws Exception {
assertNotNull(embeddedLdapRule.dirContext().search("cn=Sondre Eikanger Kvalo,ou=people,dc=zapodot,dc=org", null));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.zapodot.junit.ldap.internal;

import com.unboundid.ldap.sdk.LDAPException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zapodot.junit.ldap.EmbeddedLdapServer;

import static org.junit.Assert.assertArrayEquals;

public class EmbeddedLdapServerStandardContext {

private final EmbeddedLdapServer embeddedLdapRule = FakeEmbeddedLdapBuilder.newInstance()
.build();

@Before
public void setup() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).startEmbeddedLdapServer();
}

@After
public void teardown() throws LDAPException {
((EmbeddedLdapServerImpl) embeddedLdapRule).takeDownEmbeddedLdapServer();
}

@Test
public void testUsingDefaultDomain() throws Exception {
assertArrayEquals(new String[]{FakeEmbeddedLdapBuilder.DEFAULT_DOMAIN},
embeddedLdapRule.ldapConnection().getRootDSE().getNamingContextDNs());


}
}
Loading

0 comments on commit d5cebef

Please sign in to comment.