Skip to content

Commit

Permalink
Split the JUnit 4 rule and JUnit 5 extension into separate Maven modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bjansen committed Oct 29, 2020
1 parent 251e6db commit 6550282
Show file tree
Hide file tree
Showing 49 changed files with 263 additions and 157 deletions.
37 changes: 37 additions & 0 deletions embedded-ldap-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>embedded-ldap-parent</artifactId>
<groupId>org.zapodot</groupId>
<version>0.9-SNAPSHOT</version>
</parent>

<artifactId>embedded-ldap-core</artifactId>

<dependencies>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>${unboundid-ldapsdk.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface EmbeddedLdapServer {
* </p>
*
* @return the port number that the embedded server is listening to
* @see org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder#bindingToAddress(String)
* @see org.zapodot.junit.ldap.internal.AbstractEmbeddedLdapBuilder#bindingToAddress(String)
*/
int embeddedServerPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Objects;

/**
* A builder providing a fluent way of defining {@link org.zapodot.junit.ldap.EmbeddedLdapRule}
* or {@link org.zapodot.junit.ldap.junit5.EmbeddedLdapExtension} instances.
* A builder providing a fluent way of defining EmbeddedLdapRule
* or EmbeddedLdapExtension instances.
*/
public abstract class AbstractEmbeddedLdapBuilder<Self extends AbstractEmbeddedLdapBuilder<Self>> {

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class EmbeddedLdapServerImpl implements EmbeddedLdapServer {

private static final String JAVA_RT_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";

private static Logger logger = LoggerFactory.getLogger(EmbeddedLdapExtensionImpl.class);
private static Logger logger = LoggerFactory.getLogger(EmbeddedLdapServerImpl.class);
private final InMemoryDirectoryServer inMemoryDirectoryServer;
private final AuthenticationConfiguration authenticationConfiguration;
private LDAPConnection ldapConnection;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions embedded-ldap-junit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>embedded-ldap-parent</artifactId>
<groupId>org.zapodot</groupId>
<version>0.9-SNAPSHOT</version>
</parent>

<artifactId>embedded-ldap-junit</artifactId>

<dependencies>
<dependency>
<groupId>org.zapodot</groupId>
<artifactId>embedded-ldap-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.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>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static EmbeddedLdapRule createForConfiguration(final InMemoryDirectorySer
final AuthenticationConfiguration authenticationConfiguration,
final List<String> ldifs) {
try {
return new EmbeddedLdapRuleImpl(createServer(inMemoryDirectoryServerConfig, ldifs),
return new EmbeddedLdapRuleImpl(EmbeddedLdapServerImpl.createServer(inMemoryDirectoryServerConfig, ldifs),
authenticationConfiguration);
} catch (LDAPException e) {
throw new IllegalStateException("Can not initiate in-memory LDAP server due to an exception", e);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions embedded-ldap-junit5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>embedded-ldap-parent</artifactId>
<groupId>org.zapodot</groupId>
<version>0.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>embedded-ldap-junit5</artifactId>

<dependencies>
<dependency>
<groupId>org.zapodot</groupId>
<artifactId>embedded-ldap-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.zapodot.junit.ldap.junit5;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

class EmbeddedLdapExtensionBuilderTest {

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

@Test
void testPrematureLdapConnection() {
assertThrows(IllegalStateException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().build().ldapConnection()
);
}

@Test
void testPrematureContext() {
assertThrows(IllegalStateException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().build().context()
);
}

@Test
void testUnknownLDIF() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().importingLdifs("nonExisting.ldif").build()
);
}

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

}

@Test
void testIllegalDSN() {
assertThrows(IllegalStateException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().usingBindDSN("bindDsn").build()
);
}

@Test
void testIllegalPort() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().bindingToPort(Integer.MIN_VALUE).build()
);
}

@Test
void testSchemaNotFound() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().withSchema("non-existing-schema.ldif").build()
);
}

@Test
void testSchemaIsNotAFile() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().withSchema("folder").build()
);
}

@Test
void testSchemaIsInvalid() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().withSchema("invalid.ldif").build()
);
}

@Test
void testSchemaFileUnsupportedIsInvalid() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().withSchema("\"#%¤&&%/¤##¤¤").build()
);
}

@Test
void testInvalidPort() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().bindingToPort(Integer.MAX_VALUE)
);
}

@Test
void testInvalidBindAddress() {
assertThrows(IllegalArgumentException.class, () ->
EmbeddedLdapExtensionBuilder.newInstance().bindingToAddress("åpsldfåpl")
);
}


}
28 changes: 28 additions & 0 deletions embedded-ldap-junit5/src/test/resources/example.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 1

dn: dc=zapodot,dc=org
objectClass: domain
objectClass: top
dc: zapodot

dn: ou=groups,dc=zapodot,dc=org
objectclass: top
objectclass: organizationalUnit
ou: groups

dn: ou=people,dc=zapodot,dc=org
objectclass: top
objectclass: organizationalUnit
ou: people

dn: cn=Sondre Eikanger Kvalo,ou=people,dc=zapodot,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
uid: zapodot
userPassword: password
cn: Sondre Eikanger Kvalo
cn:: U29uZHJlIEVpa2FuZ2VyIEt2YWzDuA==
sn: Person
description: Developer
76 changes: 11 additions & 65 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.zapodot</groupId>
<artifactId>embedded-ldap-junit</artifactId>
<artifactId>embedded-ldap-parent</artifactId>
<packaging>pom</packaging>
<version>0.9-SNAPSHOT</version>

<modules>
<module>embedded-ldap-core</module>
<module>embedded-ldap-junit</module>
<module>embedded-ldap-junit5</module>
</modules>

<name>${project.artifactId}</name>
<description>Library that provides a JUnit rule for setting up an in-memory LDAP server by using the glorious Unboundid LDAP SDK</description>
<description>Library that provides a JUnit rule and extension for setting up an in-memory LDAP server by using the glorious Unboundid LDAP SDK</description>
<url>https://github.com/zapodot/embedded-ldap-junit</url>
<inceptionYear>2015</inceptionYear>
<developers>
Expand Down Expand Up @@ -42,69 +50,7 @@
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>${unboundid-ldapsdk.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.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>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Loading

0 comments on commit 6550282

Please sign in to comment.