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

Jean-Noël Rouvignac
09.01.2016 cc8d04d24dbeb6ea310def297a6e9354fd93758d
fix tests broken by commit 6197694d7a0

RemoteConnection.readMessage() now always throw EOFException when end of file has been reached
2 files modified
76 ■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPv2TestCase.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/tasks/DisconnectClientTaskTestCase.java 68 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPv2TestCase.java
@@ -23,6 +23,7 @@
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
@@ -103,15 +104,14 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void testRejectExtendedRequest()
         throws Exception
  @Test(expectedExceptions = EOFException.class)
  public void testRejectExtendedRequest() throws Exception
  {
    try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort()))
    {
      bindLdapV2(conn, "cn=Directory Manager", "password");
      conn.writeMessage(new ExtendedRequestProtocolOp(OID_START_TLS_REQUEST));
      assertNull(conn.readMessage());
      conn.readMessage();
    }
  }
opendj-server-legacy/src/test/java/org/opends/server/tasks/DisconnectClientTaskTestCase.java
@@ -64,41 +64,22 @@
  public void testDisconnectWithNotification()
         throws Exception
  {
    // Establish a connection to the server, bind, and get the connection ID.
    try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort()))
    {
      conn.bind("cn=Directory Manager", "password");
      long connectionID = getConnectionID(conn);
      // Invoke the disconnect client task.
      String taskID = "Disconnect Client " + connectionID;
      LocalizableMessage disconnectMessage = LocalizableMessage.raw("testDisconnectWithNotification");
      DN taskDN = DN.valueOf("ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=Tasks");
      TestCaseUtils.addEntry(
          "dn: " + taskDN,
          "objectClass: top",
          "objectClass: ds-task",
          "objectClass: ds-task-disconnect",
          "ds-task-id: " + taskID,
          "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask",
          "ds-task-disconnect-connection-id: " + connectionID,
          "ds-task-disconnect-notify-client: true",
          "ds-task-disconnect-message: " + disconnectMessage);
      String disconnectMessage = "testDisconnectWithNotification";
      DN taskDN = invokeClientDisconnectTask(conn, disconnectMessage);
      waitTaskCompletedSuccessfully(taskDN);
      // Make sure that we get a notice of disconnection on the initial connection.
      LDAPMessage message = conn.readMessage();
      ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp();
      assertEquals(extendedResponse.getOID(), LDAPConstants.OID_NOTICE_OF_DISCONNECTION);
      assertEquals(extendedResponse.getErrorMessage(), disconnectMessage);
      assertEquals(extendedResponse.getErrorMessage(), LocalizableMessage.raw(disconnectMessage));
    }
  }
  /**
   * Tests the ability of the server to disconnect an arbitrary client
   * connection without a notice of disconnection.
@@ -109,17 +90,43 @@
  public void testDisconnectWithoutNotification()
         throws Exception
  {
    // Establish a connection to the server, bind, and get the connection ID.
    try (RemoteConnection conn = new RemoteConnection("localhost", TestCaseUtils.getServerLdapPort()))
    {
      conn.bind("cn=Directory Manager", "password");
      long connectionID = getConnectionID(conn);
      DN taskDN = invokeClientDisconnectTask(conn, null);
      waitTaskCompletedSuccessfully(taskDN);
      // Make sure that the client connection has been closed with no notice of disconnection.
      try
      {
        conn.readMessage();
        fail("Expected IOException");
      }
      catch (IOException expected) { /* nothing to do */ }
    }
  }
      // Invoke the disconnect client task.
      String taskID = "Disconnect Client " + connectionID;
      DN taskDN = DN.valueOf("ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=Tasks");
  private DN invokeClientDisconnectTask(RemoteConnection conn, String disconnectMessage) throws Exception
  {
    long connectionID = getConnectionID(conn);
    String taskID = "Disconnect Client " + connectionID;
    DN taskDN = DN.valueOf("ds-task-id=" + taskID + ",cn=Scheduled Tasks,cn=Tasks");
    if (disconnectMessage != null)
    {
      TestCaseUtils.addEntry(
          "dn: " + taskDN,
          "objectClass: top",
          "objectClass: ds-task",
          "objectClass: ds-task-disconnect",
          "ds-task-id: " + taskID,
          "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask",
          "ds-task-disconnect-connection-id: " + connectionID,
          "ds-task-disconnect-notify-client: true",
          "ds-task-disconnect-message: " + disconnectMessage);
    }
    else
    {
      TestCaseUtils.addEntry(
          "dn: " + taskDN,
          "objectClass: top",
@@ -129,13 +136,8 @@
          "ds-task-class-name: org.opends.server.tasks.DisconnectClientTask",
          "ds-task-disconnect-connection-id: " + connectionID,
          "ds-task-disconnect-notify-client: false");
      waitTaskCompletedSuccessfully(taskDN);
      // Make sure that the client connection has been closed with no notice of disconnection.
      assertNull(conn.readMessage());
    }
    return taskDN;
  }
  private long getConnectionID(RemoteConnection conn) throws IOException, LDAPException, LdapException, DecodeException