mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
27.05.2014 f41d9f79fac04988420d11ac45b054f1316c3630
opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/AdaptersTestCase.java
@@ -32,7 +32,6 @@
import org.forgerock.opendj.ldap.AuthorizationException;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ConnectionFactory;
import org.forgerock.opendj.ldap.Connections;
import org.forgerock.opendj.ldap.ConstraintViolationException;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.DecodeException;
@@ -41,6 +40,7 @@
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.EntryNotFoundException;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.LDAPOptions;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.LinkedHashMapEntry;
import org.forgerock.opendj.ldap.ModificationType;
@@ -74,9 +74,14 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.util.concurrent.TimeUnit.*;
import static org.fest.assertions.Assertions.*;
import static org.fest.assertions.Fail.*;
import static org.forgerock.opendj.adapter.server2x.Adapters.*;
import static org.forgerock.opendj.adapter.server2x.EmbeddedServerTestCaseUtils.*;
import static org.forgerock.opendj.ldap.Connections.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
/**
 * This class defines a set of tests for the Adapters.class.
@@ -85,6 +90,13 @@
@Test
public class AdaptersTestCase extends ForgeRockTestCase {
    /** The timeout after which a connection will be marked as failed. */
    private static final long TIMEOUT_SEC = 3;
    private Integer getListenPort() {
        return Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"));
    }
    /**
     * Provides an anonymous connection factories.
     *
@@ -93,9 +105,8 @@
    @DataProvider
    public Object[][] anonymousConnectionFactories() {
        return new Object[][] {
            { new LDAPConnectionFactory("localhost",
                    Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"))) },
            { Adapters.newAnonymousConnectionFactory() } };
            { newLDAPConnectionFactory("localhost", getListenPort()) },
            { newAnonymousConnectionFactory() } };
    }
    /**
@@ -106,11 +117,13 @@
    @DataProvider
    public Object[][] rootConnectionFactories() {
        return new Object[][] {
            { Connections.newAuthenticatedConnectionFactory(
                   new LDAPConnectionFactory("localhost",
                           Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"))),
                   Requests.newSimpleBindRequest("cn=directory manager", "password".toCharArray())) },
            { Adapters.newConnectionFactoryForUser(DN.valueOf("cn=directory manager")) } };
            { newLDAPConnectionFactory(
                    "localhost",
                    getListenPort(),
                    new LDAPOptions()
                        .setBindRequest(newSimpleBindRequest("cn=directory manager", "password".toCharArray()))
                        .setTimeout(TIMEOUT_SEC, SECONDS)) },
            { newConnectionFactoryForUser(DN.valueOf("cn=directory manager")) } };
    }
    /**
@@ -214,8 +227,7 @@
    @Test
    public void testSimpleLDAPConnectionFactorySimpleBind() throws LdapException {
        final LDAPConnectionFactory factory =
                new LDAPConnectionFactory("localhost",
                        Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port")));
                newLDAPConnectionFactory("localhost", getListenPort());
        Connection connection = null;
        try {
            connection = factory.getConnection();
@@ -239,8 +251,7 @@
    @Test
    public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, LdapException {
        LDAPConnectionFactory factory =
                new LDAPConnectionFactory("localhost",
                        Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port")));
                newLDAPConnectionFactory("localhost", getListenPort());
        Connection connection = factory.getConnection();
        PlainSASLBindRequest request =
@@ -993,9 +1004,7 @@
        final DeleteRequest deleteRequest = Requests.newDeleteRequest("sn=babs,dc=example,dc=org");
        // LDAP Connection
        final LDAPConnectionFactory factory =
                new LDAPConnectionFactory("localhost",
                        Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port")));
        final LDAPConnectionFactory factory = newLDAPConnectionFactory("localhost", getListenPort());
        Connection connection = null;
        connection = factory.getConnection();
        connection.bind("cn=Directory Manager", "password".toCharArray());