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

lutoff
26.14.2006 14b9411e06193834f809022c8685b24b790e9e93
Add Controls unit-test
3 files added
928 ■■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/controls/ControlsTestCase.java 54 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/controls/PasswordControlTest.java 517 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/controls/PersistentSearchControlTest.java 357 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/controls/ControlsTestCase.java
New file
@@ -0,0 +1,54 @@
/*
 * 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.controls;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.TestCaseUtils;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
/**
 * An abstract class that all synchronization unit test should extend.
 */
@Test(groups = { "precommit", "controls" })
public abstract class ControlsTestCase extends DirectoryServerTestCase
{
  /**
   * Set up the environment for performing the tests in this suite.
   *
   * @throws Exception
   *         If the environment could not be set up.
   */
  @BeforeClass
  public void setUp() throws Exception
  {
    // This test suite depends on having the schema available.
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/controls/PasswordControlTest.java
New file
@@ -0,0 +1,517 @@
/*
 * 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.controls;
import static org.opends.server.util.ServerConstants.*;
import java.util.HashMap;
import java.util.Set;
import org.opends.server.protocols.asn1.ASN1Boolean;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.protocols.ldap.LDAPException;
import org.opends.server.types.Control;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
/**
 * Test password control
 */
public class PasswordControlTest
    extends ControlsTestCase
{
  /**
   * Create values for PasswordPolicyErrorType
   */
  @DataProvider(name = "passwordPolicyErrorTypeData")
  public Object[][] createPasswordPolicyErrorTypeData()
  {
    HashMap<Integer, String> values = new HashMap<Integer, String>();
    values.put(0, "passwordExpired");
    values.put(1, "accountLocked");
    values.put(2, "changeAfterReset");
    values.put(3, "passwordModNotAllowed");
    values.put(4, "mustSupplyOldPassword");
    values.put(5, "insufficientPasswordQuality");
    values.put(6, "passwordTooShort");
    values.put(7, "passwordTooYoung");
    values.put(8, "passwordInHistory");
    return new Object[][]
    {
    { values } };
  }
  /**
   * Test if int value are ok
   */
  @Test(dataProvider = "passwordPolicyErrorTypeData")
  public void checkIntValuePasswordPolicyErrorTypeTest(
      HashMap<Integer, String> expectedValues) throws Exception
  {
    for (Integer i : expectedValues.keySet())
    {
      PasswordPolicyErrorType val = PasswordPolicyErrorType.valueOf(i);
      String expected = expectedValues.get(i);
      assertEquals(val.toString(), expected);
    }
  }
  /**
   * Test If we have only the required values
   */
  @Test(dataProvider = "passwordPolicyErrorTypeData")
  public void checkRequiredValuesPasswordPolicyErrorTypeTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    // Retrieve the values
    PasswordPolicyErrorType[] vals = PasswordPolicyErrorType.values();
    // Check if we have the correct munber
    assertEquals(vals.length, exceptedValues.size());
    // Check if we have the correct int value
    for (PasswordPolicyErrorType val : vals)
    {
      assertTrue(exceptedValues.containsKey(val.intValue()));
    }
  }
  /**
   * Test invalid int values
   */
  @Test(dataProvider = "passwordPolicyErrorTypeData")
  public void checkInvalidIntPasswordPolicyErrorTypeTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    Set<Integer> keys = exceptedValues.keySet() ;
    for (int i=-10 ; i< 10 ; i++)
    {
      if (keys.contains(i)) continue ;
      assertNull(PasswordPolicyErrorType.valueOf(i));
    }
  }
  /**
   * Create correct values
   */
  @DataProvider(name = "passwordPolicyWarningTypeData")
  public Object[][] createPasswordPolicyWarningTypeData()
  {
    HashMap<Byte, String> values = new HashMap<Byte, String>();
    values.put((byte)0x80, "timeBeforeExpiration");
    values.put((byte)0x81, "graceAuthNsRemaining");
    return new Object[][]
    {
    { values } };
  }
  /**
   * Test if byte values are ok
   */
  @Test(dataProvider = "passwordPolicyWarningTypeData")
  public void checkIntValuePasswordPolicyWarningTypeTest(
      HashMap<Byte, String> expectedValues) throws Exception
  {
    for (byte i : expectedValues.keySet())
    {
      PasswordPolicyWarningType val = PasswordPolicyWarningType.valueOf(i);
      String expected = expectedValues.get(i);
      assertEquals(val.toString(), expected);
      assertEquals(i, val.getType());
    }
  }
  /**
   * Test If we have only the required values
   */
  @Test(dataProvider = "passwordPolicyWarningTypeData")
  public void checkRequiredValuesPasswordPolicyWarningTypeTest(
      HashMap<Byte, String> exceptedValues) throws Exception
  {
    // Retrieve the values
    PasswordPolicyWarningType[] vals = PasswordPolicyWarningType.values();
    // Check if we have the correct munber
    assertEquals(vals.length, exceptedValues.size());
    // Check if we have the correct byte value
    for (PasswordPolicyWarningType val : vals)
    {
      assertTrue(exceptedValues.containsValue(val.toString()));
    }
  }
  /**
   * Test invalid int values
   */
  @Test(dataProvider = "passwordPolicyWarningTypeData")
  public void checkInvalidIntPasswordPolicyWarningTypeTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    Set<Integer> keys = exceptedValues.keySet();
    for (int i = 0x70; i < 0x90; i++)
    {
      byte b = new Integer(i).byteValue();
      if (keys.contains(b))
      {
        continue;
      }
      else
      {
        assertNull(PasswordPolicyWarningType.valueOf(b));
        PasswordPolicyWarningType val = PasswordPolicyWarningType.valueOf(b);
        assertNull(val);
      }
    }
  }
  /**
   * Create values for PasswordControl
   */
  @DataProvider(name = "passwordControlData")
  public Object[][] createPasswordExpiredControlData()
  {
    return new Object[][] {
     { OID_NS_PASSWORD_EXPIRED, true , -1},
     { OID_NS_PASSWORD_EXPIRED, false , 0},
     { OID_NS_PASSWORD_EXPIRING, true,  1},
     { OID_NS_PASSWORD_EXPIRING, false, 2},
    };
  }
  /**
   * Test OID
   */
  @Test()
  public void checkPasswordOID() throws Exception
  {
    assertEquals(OID_NS_PASSWORD_EXPIRED,     "2.16.840.1.113730.3.4.4");
    assertEquals(OID_NS_PASSWORD_EXPIRING,    "2.16.840.1.113730.3.4.5");
    //assertEquals(OID_PASSWORD_POLICY_CONTROL, "");
  }
  /**
   * Test "Netscape password expired control" implementation
   */
  @Test(dataProvider = "passwordControlData")
  public void passwordExpiredControlTest(
      String oid, boolean isCritical, int sec) throws Exception
  {
    // Check default constructor
    PasswordExpiredControl pec = new PasswordExpiredControl();
    assertNotNull(pec);
    assertEquals("PasswordExpiredControl()", pec.toString());
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRED);
    // Check constructor with oid and boolean
    pec = new PasswordExpiredControl(oid, isCritical);
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),oid);
    // Check the decode
    Control control = new Control(oid,isCritical);
    pec = PasswordExpiredControl.decodeControl(control);
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),oid);
    control.setValue(new ASN1Boolean(true).decodeAsOctetString());
    try
    {
      pec = PasswordExpiredControl.decodeControl(control);
      assertTrue(false,
          "should be allow to create a passwordExpiredControl with value");
    }
    catch (LDAPException e)
    {
      // Normal case
      assertTrue(true,
          "should be allow to create a passwordExpiredControl with value");
    }
    // Check toString
    assertEquals("PasswordExpiredControl()", pec.toString());
  }
  /**
   * Test "Netscape password expired control" implementation
   */
  @Test(dataProvider = "passwordControlData")
  public void passwordExpiringControlTest(
      String oid, boolean isCritical, int sec) throws Exception
  {
    // Check constructor with int
    PasswordExpiringControl pec = new PasswordExpiringControl(sec);
    assertNotNull(pec);
    String toString = "PasswordExpiringControl(secondsUntilExpiration=" + sec +")" ;
    assertEquals(toString, pec.toString());
    assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRING);
    assertEquals(pec.getSecondsUntilExpiration(), sec);
    // Check constructor with oid, boolean and int
    pec = new PasswordExpiringControl(oid, isCritical, sec);
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),oid);
    assertEquals(pec.getSecondsUntilExpiration(), sec);
    // Check the decode
    Control control = new Control(oid,isCritical);
    try
    {
      pec = PasswordExpiringControl.decodeControl(control);
      assertTrue(false,
          "shouldn't be allow to create PasswordExpiringControl without value");
    }
    catch (LDAPException e)
    {
      // Normal case
      assertTrue(true,
          "shouldn't be allow to create PasswordExpiringControl without value");
    }
    control.setValue(new ASN1OctetString("invalid value"));
    try
    {
      pec = PasswordExpiringControl.decodeControl(control);
      assertTrue(false,
      "shouldn't be allow to create PasswordExpiringControl with a wrong value");
    }
    catch (LDAPException e)
    {
      // Normal case
      assertTrue(true,
      "shouldn't be allow to create PasswordExpiringControl with a wrong value");
    }
    pec = new PasswordExpiringControl(oid, isCritical, sec);
    control= new Control(oid,isCritical,pec.getValue());
    PasswordExpiringControl newPec = PasswordExpiringControl.decodeControl(control);
    assertNotNull(newPec);
    assertEquals(newPec.isCritical(), isCritical);
    assertEquals(newPec.getOID(), oid);
    // assertEquals(newPec.getSecondsUntilExpiration(), sec);
  }
  /**
   * Test PasswordPolicyRequestControl
   */
  @Test(dataProvider = "passwordControlData")
  public void passwordPolicyRequestControlTest(
      String oid, boolean isCritical, int sec) throws Exception
  {
    // Check default constructor
    PasswordPolicyRequestControl pec = new PasswordPolicyRequestControl();
    assertNotNull(pec);
    assertEquals("PasswordPolicyRequestControl()", pec.toString());
    assertEquals(pec.getOID(),OID_PASSWORD_POLICY_CONTROL);
    // Check constructor with oid and boolean
    pec = new PasswordPolicyRequestControl(oid, isCritical);
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),oid);
    // Check the decode
    Control control = new Control(oid,isCritical);
    pec = PasswordPolicyRequestControl.decodeControl(control);
    assertNotNull(pec);
    assertEquals(pec.isCritical(),isCritical);
    assertEquals(pec.getOID(),oid);
    control.setValue(new ASN1Boolean(true).decodeAsOctetString());
    try
    {
      pec = PasswordPolicyRequestControl.decodeControl(control);
      assertTrue(false,
          "should be allow to create a PasswordPolicyRequestControl with value");
    }
    catch (LDAPException e)
    {
      // Normal case
      assertTrue(true,
          "should be allow to create a PasswordPolicyRequestControl with value");
    }
    // Check toString
    assertEquals("PasswordPolicyRequestControl()", pec.toString());
  }
  /**
   * Create values for PasswordControl
   */
  @DataProvider(name = "passwordPolicyResponseControl")
  public Object[][] createPasswordPolicyResponseControlData()
  {
    return new Object[][] {
     { OID_PASSWORD_POLICY_CONTROL, true , -1},
     { OID_PASSWORD_POLICY_CONTROL, false , -1},
     { OID_PASSWORD_POLICY_CONTROL, true , 0},
     { OID_PASSWORD_POLICY_CONTROL, false , 0},
     { OID_NS_PASSWORD_EXPIRING, true,      1},
     { OID_NS_PASSWORD_EXPIRING, false,     2}
    };
  }
  /**
   * Test PasswordPolicyResponseControl
   */
   @Test(dataProvider = "passwordPolicyResponseControl")
  public void passwordPolicyResponseControlTest(
      String oid, boolean isCritical, int warningValue)
      throws Exception
  {
    // Check default constructor
    PasswordPolicyResponseControl pprc = new PasswordPolicyResponseControl();
    assertNotNull(pprc);
    assertEquals("PasswordPolicyResponseControl()", pprc.toString());
    assertEquals(pprc.getOID(), OID_PASSWORD_POLICY_CONTROL);
    assertNull(pprc.getWarningType());
    assertNull(pprc.getErrorType());
    // check constructor PasswordPolicyResponseControl
    // (PasswordPolicyWarningType warningType,
    //    int warningValue,
    //    PasswordPolicyErrorType errorType)
    for (PasswordPolicyErrorType errorType : PasswordPolicyErrorType.values())
    {
      for (PasswordPolicyWarningType warningType : PasswordPolicyWarningType.values())
      {
        pprc = new PasswordPolicyResponseControl(warningType,warningValue,errorType);
        assertNotNull(pprc) ;
        assertEquals(warningType, pprc.getWarningType());
        assertEquals(errorType, pprc.getErrorType());
        assertEquals(pprc.getWarningValue(),warningValue);
      }
    }
    // check constructor PasswordPolicyResponseControl
    // (PString oid, boolean isCritical,
    //     PasswordPolicyWarningType warningType,
    //   warningValue,
    // PasswordPolicyErrorType errorType)
    for (PasswordPolicyErrorType errorType : PasswordPolicyErrorType.values())
    {
      for (PasswordPolicyWarningType warningType : PasswordPolicyWarningType
          .values())
      {
        pprc = new PasswordPolicyResponseControl(oid, isCritical,
            warningType, warningValue, errorType);
        assertNotNull(pprc);
        assertEquals(warningType, pprc.getWarningType());
        assertEquals(errorType, pprc.getErrorType());
        assertEquals(pprc.getWarningValue(), warningValue);
      }
    }
    // check decode
    Control control ;
    for (PasswordPolicyErrorType errorType : PasswordPolicyErrorType.values())
    {
      for (PasswordPolicyWarningType warningType : PasswordPolicyWarningType
          .values())
      {
        control = new PasswordPolicyResponseControl(oid, isCritical,
            warningType, warningValue, errorType);
        pprc = PasswordPolicyResponseControl.decodeControl(control);
        assertNotNull(pprc);
        assertEquals(warningType, pprc.getWarningType());
        assertEquals(errorType, pprc.getErrorType());
        assertEquals(pprc.getWarningValue(), warningValue);
        // check to String
        String toString =
          "PasswordPolicyResponseControl(" +
          warningType.toString() +
          "=" +
          warningValue +
          ", " +
          errorType.toString() +
          ")" ;
        assertEquals(toString, pprc.toString()) ;
        // check null value for the control
        try
        {
          control.setValue(null);
          pprc = PasswordPolicyResponseControl.decodeControl(control);
          assertTrue(false,"the control should have a value");
        }
        catch (LDAPException e)
        {
          // normal case
          assertTrue(true,"the control should have a value");
        }
        // check null warning type
        control = new PasswordPolicyResponseControl(oid, isCritical,
            null, warningValue, errorType);
        try
        {
          pprc = PasswordPolicyResponseControl.decodeControl(control);
//          assertTrue(false,"the warning type shouldn't be null");
        }
        catch (LDAPException e)
        {
          // normal case
          assertTrue(true,"the warning type shouldn't be null");
        }
        // check null error type
        control = new PasswordPolicyResponseControl(oid, isCritical,
            warningType, warningValue, null);
        try
        {
          pprc = PasswordPolicyResponseControl.decodeControl(control);
//          assertTrue(false,"the error type shouldn't be null");
        }
        catch (LDAPException e)
        {
          // normal case
          assertTrue(true,"the error type shouldn't be null");
        }
      }
    }
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/controls/PersistentSearchControlTest.java
New file
@@ -0,0 +1,357 @@
/*
 * 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.controls;
import static org.opends.server.util.ServerConstants.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.server.util.ServerConstants.OID_NS_PASSWORD_EXPIRED;
import static org.opends.server.util.ServerConstants.OID_NS_PASSWORD_EXPIRING;
import static org.opends.server.util.ServerConstants.OID_PASSWORD_POLICY_CONTROL;
import static org.testng.Assert.*;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.protocols.ldap.LDAPException;
import org.opends.server.types.Control;
/**
 * Test ChangeNumber and ChangeNumberGenerator
 */
public class PersistentSearchControlTest
    extends ControlsTestCase
{
  /**
   * Create correct values
   */
  @DataProvider(name = "persistentSearchChangeTypeData")
  public Object[][] createPersistentSearchChangeTypeData()
  {
    HashMap<Integer, String> values = new HashMap<Integer, String>();
    values.put(1, "add");
    values.put(2, "delete");
    values.put(4, "modify");
    values.put(8, "modDN");
    return new Object[][]
    {
    { values } };
  }
  /**
   * Test if int value are ok
   */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkIntValueTest(
      HashMap<Integer, String> expectedValues) throws Exception
  {
    for (Integer i : expectedValues.keySet())
    {
      PersistentSearchChangeType val = PersistentSearchChangeType.valueOf(i);
      String expected = expectedValues.get(i);
      assertEquals(val.toString(), expected);
    }
  }
  /**
   * Test If we have only the required values
   */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkRequiredValuesTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    // Retrieve the values
    PersistentSearchChangeType[] vals = PersistentSearchChangeType.values();
    // Check if we have the correct munber
    assertEquals(vals.length, exceptedValues.size());
    // Check if we have the correct int value
    for (PersistentSearchChangeType val : vals)
    {
      assertTrue(exceptedValues.containsKey(val.intValue()));
    }
  }
  /**
   * Test invalid int values
   */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkInvalidIntTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    Set<Integer> keys = exceptedValues.keySet() ;
    for (int i=-10 ; i< 10 ; i++)
    {
      if (keys.contains(i)) continue ;
      try
      {
        PersistentSearchChangeType.valueOf(i);
        assertTrue(false,"the int '" + i + "' is not a set of type - exception expected");
      }
      catch (LDAPException e)
      {
        assertTrue(true,"the int '" + i + "' is not a set of type - exception expected");
      }
    }
  }
  /**
   * Test int to type
   */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkIntToTypeTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    Set<Integer> keys = exceptedValues.keySet() ;
    Set<PersistentSearchChangeType> returnTypes;
    HashSet<PersistentSearchChangeType> expectedTypes =
      new HashSet<PersistentSearchChangeType>(4);
    for (int i = 1; i <= 15; i++)
    {
      expectedTypes.clear();
      for (int key : keys)
      {
        if ((i & key) != 0)
        {
          expectedTypes.add(PersistentSearchChangeType.valueOf(key));
        }
      }
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      assertEquals(expectedTypes.size(), returnTypes.size());
      for (PersistentSearchChangeType type: expectedTypes)
      {
        assertTrue(returnTypes.contains(type));
      }
    }
    // We should have and exception
    try
    {
      PersistentSearchChangeType.intToTypes(0);
      assertTrue(false,"the int '" + 0 + "' is not a set of type - exception expected");
    }
    catch (LDAPException e)
    {
      assertTrue(true,"the int is not a set of type - exception expected");
    }
    // We should have and exception
    try
    {
      int i = 16 ;
      PersistentSearchChangeType.intToTypes(i);
      assertTrue(false,"the int '" + i + "' is not a set of type - exception expected");
    }
    catch (LDAPException e)
    {
      assertTrue(true,"the int is not a set of type - exception expected");
    }
  }
  /**
   * Test type to int
   */
  @Test(dataProvider = "persistentSearchChangeTypeData", dependsOnMethods= {"checkIntToTypeTest"})
  public void checkTypesToIntTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    Set<PersistentSearchChangeType> returnTypes;
    for (int i = 1; i <= 15; i++)
    {
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      int ret = PersistentSearchChangeType.changeTypesToInt(returnTypes);
      assertEquals(ret, i);
    }
  }
  @Test(dataProvider = "persistentSearchChangeTypeData", dependsOnMethods= {"checkIntToTypeTest"})
  public void checkChangeTypesToStringTest(
      HashMap<Integer, String> exceptedValues) throws Exception
  {
    Set<PersistentSearchChangeType> returnTypes;
    for (int i = 1; i <= 15; i++)
    {
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      String ret = PersistentSearchChangeType.changeTypesToString(returnTypes);
      String exceptedRet = null ;
      for (PersistentSearchChangeType type : returnTypes)
      {
        if (exceptedRet == null)
        {
          exceptedRet = type.toString();
        }
        else
        {
          exceptedRet = exceptedRet + "|" + type.toString();
        }
      }
      assertEquals(ret, exceptedRet);
    }
  }
  /**
   * Create values for PersistentSearchControl
   */
  @DataProvider(name = "persistentSearchControl")
  public Object[][] createPasswordPolicyResponseControlData()
  {
    return new Object[][]
    {
    { OID_NS_PASSWORD_EXPIRED, true , true, true },
    { OID_NS_PASSWORD_EXPIRED, false  ,true, false },
    {OID_PERSISTENT_SEARCH , true,  false, true },
    {OID_PERSISTENT_SEARCH ,  false, false, false }, };
  }
  /**
   * Test PersistentSearchControl
   */
  @Test(dataProvider = "persistentSearchControl")
  public void CheckPersistentSearchControlTest(
      String oid, boolean isCritical, boolean changesOnly, boolean returnECs)
      throws Exception
  {
    // Test contructor
    // CheclPersistentSearchControlTest(Set<PersistentSearchChangeType>
    // changeTypes,
    // boolean changesOnly, boolean returnECs
    Set<PersistentSearchChangeType> returnTypes;
    for (int i = 1; i <= 15; i++)
    {
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      PersistentSearchControl psc = new PersistentSearchControl(returnTypes,
          changesOnly, returnECs);
      assertNotNull(psc);
      assertEquals(changesOnly, psc.getChangesOnly());
      assertEquals(returnECs, psc.getReturnECs());
      assertEquals(returnTypes.size(), psc.getChangeTypes().size());
      assertEquals(OID_PERSISTENT_SEARCH, psc.getOID());
    }
    // Test contructor
    // CString oid, boolean isCritical,
    // Set<PersistentSearchChangeType> changeTypes,
    //    boolean changesOnly, boolean returnECs
    for (int i = 1; i <= 15; i++)
    {
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      PersistentSearchControl psc = new PersistentSearchControl(oid,
          isCritical, returnTypes, changesOnly, returnECs);
      assertNotNull(psc);
      assertEquals(isCritical, psc.isCritical());
      assertEquals(oid, psc.getOID());
      assertEquals(changesOnly, psc.getChangesOnly());
      assertEquals(returnECs, psc.getReturnECs());
      assertEquals(returnTypes.size(), psc.getChangeTypes().size());
    }
    // Test decodeControl
    for (int i = 1; i <= 15; i++)
    {
      returnTypes = PersistentSearchChangeType.intToTypes(i);
      Control control = new PersistentSearchControl(oid,
          isCritical, returnTypes, changesOnly, returnECs);
      PersistentSearchControl psc = PersistentSearchControl.decodeControl(control);
      assertNotNull(psc);
      assertEquals(isCritical, psc.isCritical());
      assertEquals(oid, psc.getOID());
      assertEquals(changesOnly, psc.getChangesOnly());
      assertEquals(returnECs, psc.getReturnECs());
      assertEquals(returnTypes.size(), psc.getChangeTypes().size());
      // Check setChangeTypes
      Set<PersistentSearchChangeType> newChangetype =
        new HashSet<PersistentSearchChangeType>();
      psc.setChangeTypes(newChangetype);
      assertEquals(0, psc.getChangeTypes().size());
      psc.setChangeTypes(returnTypes);
      assertEquals(returnTypes.size(), psc.getChangeTypes().size());
      // Check setChangesOnly
      psc.setChangesOnly(!psc.getChangesOnly());
      assertEquals(!changesOnly,psc.getChangesOnly());
      psc.setChangesOnly(!psc.getChangesOnly());
      assertEquals(changesOnly,psc.getChangesOnly());
      // Check setReturnECs
      psc.setReturnECs(!psc.getReturnECs());
      assertEquals(!returnECs,psc.getReturnECs());
      psc.setReturnECs(!psc.getReturnECs());
      assertEquals(returnECs,psc.getReturnECs());
      // Check the toString
      String toString = "PersistentSearchControl(changeTypes=\"" +
      PersistentSearchChangeType.changeTypesToString(psc.getChangeTypes()) +
      "\",changesOnly=" + psc.getChangesOnly() +
      ",returnECs=" +psc.getReturnECs() +")" ;
      assertEquals(psc.toString(), toString);
      // check null value for the control
      try
      {
        control.setValue(null);
        psc = PersistentSearchControl.decodeControl(control);
        assertTrue(false,"the control should have a value");
      }
      catch (LDAPException e)
      {
        // normal case
        assertTrue(true,"the control should have a value");
      }
      // check invalid value for the control
      control = new PasswordPolicyResponseControl(oid, isCritical,
          PasswordPolicyWarningType.GRACE_LOGINS_REMAINING, 2,
          PasswordPolicyErrorType.ACCOUNT_LOCKED);
      try
      {
        psc = PersistentSearchControl.decodeControl(control);
        assertTrue(false, "the control should have a value");
      }
      catch (LDAPException e)
      {
        // normal case
        assertTrue(true, "the control should have a value");
      }
    }
  }
}