From f89c99bee37103772b4009fea14387fa92f9da98 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Tue, 08 Oct 2013 16:12:52 +0000
Subject: [PATCH] OPENDJ-346 Consider using java.util.ServiceLoader for loading extensions and requesting transport implementations

---
 opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java                   |   16 ++-
 opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java |   43 ++++---
 opendj3/opendj-ldap-sdk/src/test/java/com/forgerock/opendj/ldap/GrizzlyLDAPConnectionTestCase.java |    6 
 opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionFactoryTestCase.java     |   63 ++++-------
 opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPServer.java                    |    2 
 opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java                 |   22 ----
 opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java          |   90 ++++++++---------
 7 files changed, 106 insertions(+), 136 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java
index 1c5f81e..30f05e4 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/util/StaticUtils.java
@@ -2264,15 +2264,17 @@
      * <p>
      * The provider is loaded using the {@code ServiceLoader} facility.
      *
-     * @param <P> type of provider
+     * @param <P>
+     *            type of provider
      * @param providerClass
-     *          class of provider
+     *            class of provider
      * @param requestedProvider
      *            name of provider to use, or {@code null} if no specific
      *            provider is requested.
      * @param classLoader
      *            class loader to use to load the provider, or {@code null} to
-     *            use the default class loader.
+     *            use the default class loader (the context class loader of the
+     *            current thread).
      * @return a provider
      * @throws ProviderNotFoundException
      *             if no provider is available or if the provider requested
@@ -2280,8 +2282,12 @@
      */
     public static <P extends Provider> P getProvider(final Class<P> providerClass, final String requestedProvider,
             final ClassLoader classLoader) {
-
-        ServiceLoader<P> loader = ServiceLoader.load(providerClass, classLoader);
+        ServiceLoader<P> loader = null;
+        if (classLoader == null) {
+            loader = ServiceLoader.load(providerClass);
+        } else {
+            loader = ServiceLoader.load(providerClass, classLoader);
+        }
         StringBuilder providersFound = new StringBuilder();
         for (P provider : loader) {
             if (providersFound.length() > 0) {
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/com/forgerock/opendj/ldap/GrizzlyLDAPConnectionTestCase.java b/opendj3/opendj-ldap-sdk/src/test/java/com/forgerock/opendj/ldap/GrizzlyLDAPConnectionTestCase.java
index c1b271d..8af2738 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/com/forgerock/opendj/ldap/GrizzlyLDAPConnectionTestCase.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/com/forgerock/opendj/ldap/GrizzlyLDAPConnectionTestCase.java
@@ -38,6 +38,7 @@
 import org.forgerock.opendj.ldap.ErrorResultException;
 import org.forgerock.opendj.ldap.LDAPConnectionFactory;
 import org.forgerock.opendj.ldap.LDAPListener;
+import org.forgerock.opendj.ldap.LDAPOptions;
 import org.forgerock.opendj.ldap.RequestHandler;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.SearchResultHandler;
@@ -83,15 +84,14 @@
         @SuppressWarnings("unchecked")
         LDAPListener listener =
                 new LDAPListener(address, Connections
-                        .newServerConnectionFactory(mock(RequestHandler.class)),
-                        TestCaseUtils.getLDAPListenerTestOptions());
+                        .newServerConnectionFactory(mock(RequestHandler.class)));
 
         /*
          * Use a very long time out in order to prevent the timeout thread from
          * triggering the timeout.
          */
         LDAPConnectionFactory factory = new LDAPConnectionFactory(address,
-                TestCaseUtils.getLDAPTestOptions().setTimeout(100, TimeUnit.SECONDS));
+                new LDAPOptions().setTimeout(100, TimeUnit.SECONDS));
         GrizzlyLDAPConnection connection = (GrizzlyLDAPConnection) factory.getConnection();
         try {
             SearchRequest request =
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionFactoryTestCase.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionFactoryTestCase.java
index 2319b8c..8b66228 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionFactoryTestCase.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionFactoryTestCase.java
@@ -27,22 +27,15 @@
 
 package org.forgerock.opendj.ldap;
 
-import static java.util.Arrays.asList;
+import static java.util.Arrays.*;
 
-import static org.forgerock.opendj.ldap.TestCaseUtils.getLDAPTestOptions;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.forgerock.opendj.ldap.Connections.newFixedConnectionPool;
-import static org.forgerock.opendj.ldap.Connections.newHeartBeatConnectionFactory;
-import static org.forgerock.opendj.ldap.Connections.newLoadBalancer;
-import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult;
+import static org.fest.assertions.Assertions.*;
+import static org.forgerock.opendj.ldap.Connections.*;
+import static org.forgerock.opendj.ldap.ErrorResultException.*;
 import static org.forgerock.opendj.ldap.TestCaseUtils.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+import static org.testng.Assert.*;
 
 import java.util.Arrays;
 import java.util.concurrent.Callable;
@@ -143,7 +136,7 @@
 
         factories[0][0] =
                 Connections.newHeartBeatConnectionFactory(new LDAPConnectionFactory(
-                        getServerSocketAddress(), getLDAPTestOptions()),
+                        getServerSocketAddress()),
                         1000, 500, TimeUnit.MILLISECONDS, request);
 
         // InternalConnectionFactory
@@ -151,26 +144,21 @@
 
         // AuthenticatedConnectionFactory
         factories[2][0] =
-                new AuthenticatedConnectionFactory(new LDAPConnectionFactory(
-                        getServerSocketAddress(), getLDAPTestOptions()),
+                new AuthenticatedConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress()),
                         Requests.newSimpleBindRequest("", new char[0]));
 
         // AuthenticatedConnectionFactory with multi-stage SASL
         factories[3][0] =
-                new AuthenticatedConnectionFactory(new LDAPConnectionFactory(
-                        getServerSocketAddress(), getLDAPTestOptions()),
-                        Requests.newCRAMMD5SASLBindRequest("id:user",
-                            "password".toCharArray()));
+                new AuthenticatedConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress()),
+                        Requests.newCRAMMD5SASLBindRequest("id:user", "password".toCharArray()));
 
         // LDAPConnectionFactory with default options
-        factories[4][0] = new LDAPConnectionFactory(getServerSocketAddress(),
-                getLDAPTestOptions());
+        factories[4][0] = new LDAPConnectionFactory(getServerSocketAddress());
 
         // LDAPConnectionFactory with startTLS
         SSLContext sslContext =
                 new SSLContextBuilder().setTrustManager(TrustManagers.trustAll()).getSSLContext();
-        LDAPOptions options =
-                getLDAPTestOptions().setSSLContext(sslContext).setUseStartTLS(true)
+        LDAPOptions options = new LDAPOptions().setSSLContext(sslContext).setUseStartTLS(true)
                         .addEnabledCipherSuite(
                                 new String[] { "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
                                     "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
@@ -193,14 +181,14 @@
 
         // Connection pool and load balancing tests.
         ConnectionFactory offlineServer1 =
-                Connections.newNamedConnectionFactory(new LDAPConnectionFactory(findFreeSocketAddress(),
-                        getLDAPTestOptions()), "offline1");
+                Connections.newNamedConnectionFactory(
+                        new LDAPConnectionFactory(findFreeSocketAddress()), "offline1");
         ConnectionFactory offlineServer2 =
-                Connections.newNamedConnectionFactory(new LDAPConnectionFactory(findFreeSocketAddress(),
-                        getLDAPTestOptions()), "offline2");
+                Connections.newNamedConnectionFactory(
+                        new LDAPConnectionFactory(findFreeSocketAddress()), "offline2");
         ConnectionFactory onlineServer =
-                Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                        getServerSocketAddress(), getLDAPTestOptions()), "online");
+                Connections.newNamedConnectionFactory(
+                        new LDAPConnectionFactory(getServerSocketAddress()), "online");
 
         // Connection pools.
         factories[7][0] = Connections.newFixedConnectionPool(onlineServer, 10);
@@ -546,11 +534,10 @@
                     }
                 });
 
-        LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer,
-                TestCaseUtils.getLDAPListenerTestOptions());
+        LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer);
         try {
             LDAPConnectionFactory clientFactory =
-                    new LDAPConnectionFactory(listener.getSocketAddress(), getLDAPTestOptions());
+                    new LDAPConnectionFactory(listener.getSocketAddress());
             final Connection client = clientFactory.getConnection();
             connectLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS);
             MockConnectionEventListener mockListener = null;
@@ -629,11 +616,10 @@
                     }
                 });
 
-        LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer,
-                getLDAPListenerTestOptions());
+        LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer);
         try {
             LDAPConnectionFactory clientFactory =
-                    new LDAPConnectionFactory(listener.getSocketAddress(), getLDAPTestOptions());
+                    new LDAPConnectionFactory(listener.getSocketAddress());
             final Connection client = clientFactory.getConnection();
             connectLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS);
             try {
@@ -669,8 +655,7 @@
     public void testFactoryCloseBeforeConnectionClose() throws Exception {
         final ConnectionFactory factory =
                 newLoadBalancer(new FailoverLoadBalancingAlgorithm(asList(newFixedConnectionPool(
-                        newHeartBeatConnectionFactory(new LDAPConnectionFactory(
-                                getServerSocketAddress(), getLDAPTestOptions())), 2))));
+                        newHeartBeatConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress())), 2))));
         Connection conn = null;
         try {
             conn = factory.getConnection();
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java
index 171df62..93c70d0 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java
@@ -27,7 +27,6 @@
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.forgerock.opendj.ldap.TestCaseUtils.findFreeSocketAddress;
-import static org.forgerock.opendj.ldap.TestCaseUtils.getLDAPTestOptions;
 import static org.mockito.Mockito.mock;
 
 import java.io.IOException;
@@ -48,14 +47,23 @@
     @Test
     public void testCreateLDAPConnectionFactory() throws Exception {
         // test no exception is thrown, which means transport provider is correctly loaded
-        LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), getLDAPTestOptions());
+        LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress());
+        factory.close();
+    }
+
+    @Test
+    public void testCreateLDAPConnectionFactoryWithCustomClassLoader() throws Exception {
+        // test no exception is thrown, which means transport provider is correctly loaded
+        LDAPOptions options = new LDAPOptions().
+                setProviderClassLoader(Thread.currentThread().getContextClassLoader());
+        LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), options);
         factory.close();
     }
 
     @Test(expectedExceptions = { ProviderNotFoundException.class },
             expectedExceptionsMessageRegExp = "^The requested provider 'unknown' .*")
     public void testCreateLDAPConnectionFactoryFailureProviderNotFound() throws Exception {
-        LDAPOptions options = getLDAPTestOptions().setTransportProvider("unknown");
+        LDAPOptions options = new LDAPOptions().setTransportProvider("unknown");
         LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), options);
         factory.close();
     }
@@ -69,8 +77,7 @@
         final AtomicReference<LDAPClientContext> context = new AtomicReference<LDAPClientContext>();
         final Semaphore latch = new Semaphore(0);
         final LDAPListener server = createServer(latch, context);
-        final ConnectionFactory factory = new LDAPConnectionFactory(server.getSocketAddress(),
-                getLDAPTestOptions());
+        final ConnectionFactory factory = new LDAPConnectionFactory(server.getSocketAddress());
         try {
             for (int i = 0; i < 100; i++) {
                 // Connect to the server.
@@ -97,19 +104,17 @@
         }
     }
 
-    private LDAPListener createServer(final Semaphore latch,
-            final AtomicReference<LDAPClientContext> context) throws IOException {
-        return new LDAPListener(findFreeSocketAddress(),
-                new ServerConnectionFactory<LDAPClientContext, Integer>() {
-                    @SuppressWarnings("unchecked")
-                    @Override
-                    public ServerConnection<Integer> handleAccept(
-                            final LDAPClientContext clientContext) throws ErrorResultException {
-                        context.set(clientContext);
-                        latch.release();
-                        return mock(ServerConnection.class);
-                    }
-                },
-                TestCaseUtils.getLDAPListenerTestOptions());
+    private LDAPListener createServer(final Semaphore latch, final AtomicReference<LDAPClientContext> context)
+            throws IOException {
+        return new LDAPListener(findFreeSocketAddress(), new ServerConnectionFactory<LDAPClientContext, Integer>() {
+            @SuppressWarnings("unchecked")
+            @Override
+            public ServerConnection<Integer> handleAccept(final LDAPClientContext clientContext)
+                    throws ErrorResultException {
+                context.set(clientContext);
+                latch.release();
+                return mock(ServerConnection.class);
+            }
+        });
     }
 }
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java
index dda8d5d..efa6588 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPListenerTestCase.java
@@ -239,8 +239,22 @@
     public void testCreateLDAPListener() throws Exception {
         // test no exception is thrown, which means transport provider is
         // correctly loaded
-        LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mock(ServerConnectionFactory.class),
-                getLDAPListenerTestOptions());
+        LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mock(ServerConnectionFactory.class));
+        listener.close();
+    }
+
+    /**
+     * Test creation of LDAP listener with default transport provider and custom class loader.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCreateLDAPListenerWithCustomClassLoader() throws Exception {
+        // test no exception is thrown, which means transport provider is
+        // correctly loaded
+        LDAPListenerOptions options = new LDAPListenerOptions().
+                setProviderClassLoader(Thread.currentThread().getContextClassLoader());
+        LDAPListener listener = new LDAPListener(findFreeSocketAddress(),
+                mock(ServerConnectionFactory.class), options);
         listener.close();
     }
 
@@ -251,7 +265,7 @@
     @Test(expectedExceptions = { ProviderNotFoundException.class },
         expectedExceptionsMessageRegExp = "^The requested provider 'unknown' .*")
     public void testCreateLDAPListenerFailureProviderNotFound() throws Exception {
-        LDAPListenerOptions options = getLDAPListenerTestOptions().setTransportProvider("unknown");
+        LDAPListenerOptions options = new LDAPListenerOptions().setTransportProvider("unknown");
         LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mock(ServerConnectionFactory.class), options);
         listener.close();
     }
@@ -268,13 +282,11 @@
         final MockServerConnectionFactory serverConnectionFactory =
                 new MockServerConnectionFactory(serverConnection);
         final LDAPListener listener =
-                new LDAPListener(new InetSocketAddress(0), serverConnectionFactory,
-                        TestCaseUtils.getLDAPListenerTestOptions());
+                new LDAPListener(new InetSocketAddress(0), serverConnectionFactory);
         try {
             // Connect and close.
             final Connection connection =
-                    new LDAPConnectionFactory(listener.getSocketAddress(), getLDAPTestOptions()).
-                    getConnection();
+                    new LDAPConnectionFactory(listener.getSocketAddress()).getConnection();
             assertThat(serverConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
             assertThat(serverConnection.isClosed.getCount()).isEqualTo(1);
             connection.close();
@@ -305,13 +317,13 @@
             // Connection pool and load balancing tests.
             final ConnectionFactory offlineServer1 =
                     Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                            findFreeSocketAddress(), getLDAPTestOptions()), "offline1");
+                            findFreeSocketAddress()), "offline1");
             final ConnectionFactory offlineServer2 =
                     Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                            findFreeSocketAddress(), getLDAPTestOptions()), "offline2");
+                            findFreeSocketAddress()), "offline2");
             final ConnectionFactory onlineServer =
                     Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                            onlineServerListener.getSocketAddress(), getLDAPTestOptions()),
+                            onlineServerListener.getSocketAddress()),
                             "online");
 
             // Round robin.
@@ -374,21 +386,19 @@
         final MockServerConnectionFactory onlineServerConnectionFactory =
                 new MockServerConnectionFactory(onlineServerConnection);
         final LDAPListener onlineServerListener =
-                new LDAPListener(new InetSocketAddress(0), onlineServerConnectionFactory,
-                        getLDAPListenerTestOptions());
+                new LDAPListener(new InetSocketAddress(0), onlineServerConnectionFactory);
 
         try {
             // Connection pool and load balancing tests.
             final ConnectionFactory offlineServer1 =
-                    Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                            findFreeSocketAddress(), getLDAPTestOptions()), "offline1");
+                    Connections.newNamedConnectionFactory(
+                            new LDAPConnectionFactory(findFreeSocketAddress()), "offline1");
             final ConnectionFactory offlineServer2 =
-                    Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                            findFreeSocketAddress(), getLDAPTestOptions()), "offline2");
+                    Connections.newNamedConnectionFactory(
+                            new LDAPConnectionFactory(findFreeSocketAddress()), "offline2");
             final ConnectionFactory onlineServer =
-                    Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
-                            onlineServerListener.getSocketAddress(), getLDAPTestOptions()),
-                            "online");
+                    Connections.newNamedConnectionFactory(
+                            new LDAPConnectionFactory(onlineServerListener.getSocketAddress()), "online");
 
             // Round robin.
             final ConnectionFactory loadBalancer =
@@ -427,13 +437,11 @@
                     new MockServerConnectionFactory(proxyServerConnection);
 
             final LDAPListener proxyListener =
-                    new LDAPListener(new InetSocketAddress(0), proxyServerConnectionFactory,
-                            getLDAPListenerTestOptions());
+                    new LDAPListener(new InetSocketAddress(0), proxyServerConnectionFactory);
             try {
                 // Connect, bind, and close.
                 final Connection connection =
-                        new LDAPConnectionFactory(proxyListener.getSocketAddress(),
-                                getLDAPTestOptions()).getConnection();
+                        new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
                 try {
                     connection.bind("cn=test", "password".toCharArray());
 
@@ -480,8 +488,7 @@
                                 final LDAPClientContext clientContext) throws ErrorResultException {
                             // First attempt offline server.
                             LDAPConnectionFactory lcf =
-                                    new LDAPConnectionFactory(findFreeSocketAddress(),
-                                            getLDAPTestOptions());
+                                    new LDAPConnectionFactory(findFreeSocketAddress());
                             try {
                                 // This is expected to fail.
                                 lcf.getConnection().close();
@@ -520,8 +527,7 @@
             try {
                 // Connect and close.
                 final Connection connection =
-                        new LDAPConnectionFactory(proxyListener.getSocketAddress(), getLDAPTestOptions()).
-                        getConnection();
+                        new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
 
                 assertThat(proxyServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
                 assertThat(onlineServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
@@ -551,8 +557,7 @@
         final MockServerConnectionFactory onlineServerConnectionFactory =
                 new MockServerConnectionFactory(onlineServerConnection);
         final LDAPListener onlineServerListener =
-                new LDAPListener(findFreeSocketAddress(), onlineServerConnectionFactory,
-                        getLDAPListenerTestOptions());
+                new LDAPListener(findFreeSocketAddress(), onlineServerConnectionFactory);
 
         try {
             final MockServerConnection proxyServerConnection = new MockServerConnection() {
@@ -567,8 +572,7 @@
                         final ResultHandler<BindResult> resultHandler)
                         throws UnsupportedOperationException {
                     // First attempt offline server.
-                    LDAPConnectionFactory lcf = new LDAPConnectionFactory(findFreeSocketAddress(),
-                            getLDAPTestOptions());
+                    LDAPConnectionFactory lcf = new LDAPConnectionFactory(findFreeSocketAddress());
                     try {
                         // This is expected to fail.
                         lcf.getConnection().close();
@@ -578,8 +582,7 @@
                     } catch (final ConnectionException ce) {
                         // This is expected - so go to online server.
                         try {
-                            lcf = new LDAPConnectionFactory(onlineServerListener.getSocketAddress(),
-                                    getLDAPTestOptions());
+                            lcf = new LDAPConnectionFactory(onlineServerListener.getSocketAddress());
                             lcf.getConnection().close();
                             resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS));
                         } catch (final Exception e) {
@@ -600,14 +603,11 @@
             final MockServerConnectionFactory proxyServerConnectionFactory =
                     new MockServerConnectionFactory(proxyServerConnection);
             final LDAPListener proxyListener =
-                    new LDAPListener(findFreeSocketAddress(), proxyServerConnectionFactory,
-                            TestCaseUtils.getLDAPListenerTestOptions());
+                    new LDAPListener(findFreeSocketAddress(), proxyServerConnectionFactory);
             try {
                 // Connect, bind, and close.
                 final Connection connection =
-                        new LDAPConnectionFactory(proxyListener.getSocketAddress(),
-                                getLDAPTestOptions()).
-                        getConnection();
+                        new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
                 try {
                     connection.bind("cn=test", "password".toCharArray());
 
@@ -640,13 +640,12 @@
         final MockServerConnection serverConnection = new MockServerConnection();
         final MockServerConnectionFactory factory =
                 new MockServerConnectionFactory(serverConnection);
-        final LDAPListenerOptions options =
-                TestCaseUtils.getLDAPListenerTestOptions().setMaxRequestSize(2048);
+        final LDAPListenerOptions options = new LDAPListenerOptions().setMaxRequestSize(2048);
         final LDAPListener listener = new LDAPListener(findFreeSocketAddress(), factory, options);
 
         Connection connection = null;
         try {
-            connection = new LDAPConnectionFactory(listener.getSocketAddress(), getLDAPTestOptions()).
+            connection = new LDAPConnectionFactory(listener.getSocketAddress()).
                     getConnection();
 
             // Small request
@@ -699,14 +698,12 @@
         final MockServerConnection serverConnection = new MockServerConnection();
         final MockServerConnectionFactory factory =
                 new MockServerConnectionFactory(serverConnection);
-        final LDAPListener listener = new LDAPListener(findFreeSocketAddress(), factory,
-                TestCaseUtils.getLDAPListenerTestOptions());
+        final LDAPListener listener = new LDAPListener(findFreeSocketAddress(), factory);
 
         final Connection connection;
         try {
             // Connect and bind.
-            connection = new LDAPConnectionFactory(listener.getSocketAddress(), getLDAPTestOptions()).
-                    getConnection();
+            connection = new LDAPConnectionFactory(listener.getSocketAddress()).getConnection();
             try {
                 connection.bind("cn=test", "password".toCharArray());
             } catch (final ErrorResultException e) {
@@ -721,8 +718,7 @@
         try {
             // Connect and bind.
             final Connection failedConnection =
-                    new LDAPConnectionFactory(listener.getSocketAddress(), getLDAPTestOptions()).
-                    getConnection();
+                    new LDAPConnectionFactory(listener.getSocketAddress()).getConnection();
             failedConnection.close();
             connection.close();
             fail("Connection attempt to closed listener succeeded unexpectedly");
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPServer.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPServer.java
index 051bb6f..4b3bb3f 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPServer.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPServer.java
@@ -545,7 +545,7 @@
         sslContext = new SSLContextBuilder().getSSLContext();
         listener =
                 new LDAPListener(findFreeSocketAddress(), getInstance(),
-                        getLDAPListenerTestOptions().setBacklog(4096));
+                        new LDAPListenerOptions().setBacklog(4096));
         isRunning = true;
     }
 
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
index 17bd937..2a8c3bd 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
@@ -222,26 +222,4 @@
         }
         return mock;
     }
-
-    /**
-     * Returns LDAP options with the parameter {@code LDAPOptions#getClassLoader()} already
-     * set to the test class loader.
-     *
-     * @return LDAPOptions already set with the class loader used by the test.
-     *         This is required if the test need to use a transport provider.
-     */
-    public static LDAPOptions getLDAPTestOptions() {
-        return new LDAPOptions().setProviderClassLoader(Thread.currentThread().getContextClassLoader());
-    }
-
-    /**
-     * Returns LDAPListener options with the parameter {@code LDAPListenerOptions#getClassLoader()} already
-     * set to the test class loader.
-     *
-     * @return LDAPListenerOptions already set with the class loader used by the test.
-     *         This is required if the test need to use a transport provider.
-     */
-    public static LDAPListenerOptions getLDAPListenerTestOptions() {
-        return new LDAPListenerOptions().setProviderClassLoader(Thread.currentThread().getContextClassLoader());
-    }
 }

--
Gitblit v1.10.0