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

dugan
23.37.2006 a91d4f6355968c0d4bb2cdc118d4d9ce07c739ce
Add UnbindRequestProtocolOp unit test
1 files added
1 files modified
118 ■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/LdapTestCase.java 47 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestUnbindRequestProtocolOp.java 71 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/LdapTestCase.java
@@ -27,27 +27,13 @@
package org.opends.server.protocols.ldap ;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.api.ClientConnection;
import org.opends.server.api.ConnectionHandler;
import org.opends.server.api.ConnectionSecurityProvider;
import org.opends.server.core.CancelRequest;
import org.opends.server.core.CancelResult;
import org.opends.server.core.Operation;
import org.opends.server.core.SearchOperation;
import org.opends.server.protocols.asn1.ASN1Boolean;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.asn1.ASN1Long;
import org.opends.server.protocols.asn1.ASN1Sequence;
import org.opends.server.types.DisconnectReason;
import org.opends.server.types.IntermediateResponse;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.types.SearchResultReference;
import org.testng.annotations.Test;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.ListIterator;
@@ -94,7 +80,28 @@
    return !(e1.hasNext() || e2.hasNext());
  }
  static void
  /**
   * Generate an exception by writing a long into a integer element.
   * @param op The op.
   * @param type The type of sequence.
   * @param index The index into the element to write to.
   * @throws Exception If the protocol op decode can't write the sequence.
   */
static void
  badIntegerElement(ProtocolOp op, byte type, int index) throws Exception {
      ASN1Element element = op.encode();
      ArrayList<ASN1Element> elements = ((ASN1Sequence)element).elements();
      elements.set(index, new ASN1Long(Long.MAX_VALUE));
      ProtocolOp.decode(new ASN1Sequence(type, elements));
  }
  /**
   * Generate an exception by adding an element.
 * @param op The op.
 * @param type The type of sequence.
 * @throws Exception If the protocol op decode has too many elements.
 */
static void
  tooManyElements(ProtocolOp op, byte type) throws Exception
  {
      ASN1Element element = op.encode();
@@ -103,7 +110,13 @@
      ProtocolOp.decode(new ASN1Sequence(type, elements));
  }
  static void
/**
 * Generate an excepting by removing an element.
 * @param op The op.
 * @param type The type of sequence.
 * @throws Exception If the protocol op decode has too few elements.
 */
static void
  tooFewElements(ProtocolOp op, byte type) throws Exception
  {
      ASN1Element element = op.encode();
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/ldap/TestUnbindRequestProtocolOp.java
New file
@@ -0,0 +1,71 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 */
package org.opends.server.protocols.ldap;
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.ldap.UnbindRequestProtocolOp;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class TestUnbindRequestProtocolOp  extends LdapTestCase {
    /**
     * Once-only initialization.
     *
     * @throws Exception
     *           If an unexpected error occurred.
     */
    @BeforeClass
    public void setUp() throws Exception {
        // This test suite depends on having the schema available, so we'll
        // start the server.TestBindResponseProtocolOp
        TestCaseUtils.startServer();
    }
  @Test()
  public void testUnbindRequest() throws Exception {
      UnbindRequestProtocolOp req = new UnbindRequestProtocolOp();
      ASN1Element reqElem=req.encode();
      ProtocolOp reqOp= ProtocolOp.decode(reqElem);
      assertTrue(reqOp.getProtocolOpName() == req.getProtocolOpName());
      assertTrue(reqOp.getType() == req.getType());
  }
  @Test ()
  public void testUnbindRequestToString() throws Exception
  {
      UnbindRequestProtocolOp r =
          new UnbindRequestProtocolOp();
      StringBuilder sb = new StringBuilder();
      r.toString(sb);
      r.toString(sb, 1);
  }
}