Skip to content

Commit

Permalink
Merge pull request #11044 from hartimcwildfly/make-ldap-test-resource…
Browse files Browse the repository at this point in the history
…-reusable

made ldap server test resource reusable
  • Loading branch information
gsmet authored Jul 29, 2020
2 parents 2041ad6 + 26af7e1 commit 4013241
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
import com.unboundid.ldap.listener.InMemoryListenerConfig;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldif.LDIFReader;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

public class LdapServerTestResource implements QuarkusTestResourceLifecycleManager {

private InMemoryDirectoryServer ldapServer;
protected InMemoryDirectoryServer ldapServer;

public LdapServerTestResource() throws LDAPException {
InMemoryListenerConfig listenerConfig = new InMemoryListenerConfig("listener", InetAddress.getLoopbackAddress(),
10389, null, null, null);
InMemoryDirectoryServerConfig inMemoryDirectoryServerConfig = new InMemoryDirectoryServerConfig("dc=quarkus,dc=io");
inMemoryDirectoryServerConfig.setListenerConfigs(listenerConfig);
inMemoryDirectoryServerConfig.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
ldapServer = new InMemoryDirectoryServer(inMemoryDirectoryServerConfig);
ldapServer.importFromLDIF(true, new LDIFReader(ClassLoader.getSystemResourceAsStream("quarkus-io.ldif")));
}

@Override
public Map<String, String> start() {
try {
InMemoryListenerConfig listenerConfig = new InMemoryListenerConfig("listener", InetAddress.getByName("127.0.0.1"),
10389, null, null, null);

InMemoryDirectoryServerConfig inMemoryDirectoryServerConfig = new InMemoryDirectoryServerConfig("dc=quarkus,dc=io");
inMemoryDirectoryServerConfig.setListenerConfigs(listenerConfig);
inMemoryDirectoryServerConfig.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
ldapServer = new InMemoryDirectoryServer(inMemoryDirectoryServerConfig);
ldapServer.importFromLDIF(true, new LDIFReader(ClassLoader.getSystemResourceAsStream("quarkus-io.ldif")));
ldapServer.startListening();
System.out.println("[INFO] LDAP server started");
} catch (Exception e) {
Expand Down

0 comments on commit 4013241

Please sign in to comment.