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

Ludovic Poitou
11.05.2012 9b7bf4aa4d0c3a7698caf7013e6a57c693622a95
opendj-sdk/opends/src/server/org/opends/server/schema/IntegerSyntax.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2012 ForgeRock AS
 */
package org.opends.server.schema;
import org.opends.messages.Message;
@@ -76,6 +77,7 @@
    /**
     * {@inheritDoc}
     */
    @Override
    public Integer decode(AttributeValue value) throws DirectoryException
    {
      ByteString nvalue = value.getNormalizedValue();
@@ -111,6 +113,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public void initializeSyntax(AttributeSyntaxCfg configuration)
         throws ConfigException
  {
@@ -146,6 +149,7 @@
   *
   * @return  The common name for this attribute syntax.
   */
  @Override
  public String getSyntaxName()
  {
    return SYNTAX_INTEGER_NAME;
@@ -158,6 +162,7 @@
   *
   * @return  The OID for this attribute syntax.
   */
  @Override
  public String getOID()
  {
    return SYNTAX_INTEGER_OID;
@@ -170,6 +175,7 @@
   *
   * @return  A description for this attribute syntax.
   */
  @Override
  public String getDescription()
  {
    return SYNTAX_INTEGER_DESCRIPTION;
@@ -185,6 +191,7 @@
   *          attributes with this syntax, or <CODE>null</CODE> if equality
   *          matches will not be allowed for this type by default.
   */
  @Override
  public EqualityMatchingRule getEqualityMatchingRule()
  {
    return defaultEqualityMatchingRule;
@@ -200,6 +207,7 @@
   *          attributes with this syntax, or <CODE>null</CODE> if ordering
   *          matches will not be allowed for this type by default.
   */
  @Override
  public OrderingMatchingRule getOrderingMatchingRule()
  {
    return defaultOrderingMatchingRule;
@@ -215,6 +223,7 @@
   *          attributes with this syntax, or <CODE>null</CODE> if substring
   *          matches will not be allowed for this type by default.
   */
  @Override
  public SubstringMatchingRule getSubstringMatchingRule()
  {
    return defaultSubstringMatchingRule;
@@ -230,6 +239,7 @@
   *          attributes with this syntax, or <CODE>null</CODE> if approximate
   *          matches will not be allowed for this type by default.
   */
  @Override
  public ApproximateMatchingRule getApproximateMatchingRule()
  {
    // There is no approximate matching rule by default.
@@ -250,6 +260,7 @@
   * @return  <CODE>true</CODE> if the provided value is acceptable for use with
   *          this syntax, or <CODE>false</CODE> if not.
   */
  @Override
  public boolean valueIsAcceptable(ByteSequence value,
                                   MessageBuilder invalidReason)
  {
@@ -278,13 +289,12 @@
        case '9':
          return true;
        case '-':
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_DASH_NEEDS_VALUE.get(
                  valueString));
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_DASH_NEEDS_VALUE
              .get(valueString));
          return false;
        default:
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER.get(
                  valueString,
                  valueString.charAt(0), 0));
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER
              .get(valueString, valueString.charAt(0), 0));
          return false;
      }
    }
@@ -295,8 +305,8 @@
      switch (valueString.charAt(0))
      {
        case '0':
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INITIAL_ZERO.get(
                  valueString));
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INITIAL_ZERO
              .get(valueString));
          return false;
        case '1':
        case '2':
@@ -314,9 +324,8 @@
          negative = true;
          break;
        default:
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER.get(
                  valueString,
                  valueString.charAt(0), 0));
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER
              .get(valueString, valueString.charAt(0), 0));
          return false;
      }
@@ -326,8 +335,8 @@
          // This is fine as long as the value isn't negative.
          if (negative)
          {
            invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INITIAL_ZERO.get(
                    valueString));
            invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INITIAL_ZERO
                .get(valueString));
            return false;
          }
          break;
@@ -343,9 +352,8 @@
          // These are all fine.
          break;
        default:
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER.get(
                  valueString,
                  valueString.charAt(0), 0));
          invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER
              .get(valueString, valueString.charAt(1), 1));
          return false;
      }
@@ -366,9 +374,8 @@
            // These are all fine.
            break;
          default:
            invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER.get(
                    valueString,
                    valueString.charAt(0), 0));
            invalidReason.append(WARN_ATTR_SYNTAX_INTEGER_INVALID_CHARACTER
                .get(valueString, valueString.charAt(i), i));
            return false;
        }
      }
@@ -382,6 +389,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isBinary()
  {
    return false;
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeSyntaxTest.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2012 ForgeRock AS
 */
package org.opends.server.schema;
@@ -40,17 +41,17 @@
   * Create data for the testAcceptableValues test.
   * This should be a table of tables with 2 elements.
   * The first one should be the value to test, the second the expected
   * result of the test.
   *
   * result of the test.
   *
   * @return a table containing data for the testAcceptableValues Test.
   */
  @DataProvider(name="acceptableValues")
  public abstract Object[][] createAcceptableValues();
  /**
   * Get an instance of the attribute syntax that muste be tested.
   *
   * @return An instance of the attribute syntax that muste be tested.
   * Get an instance of the attribute syntax that must be tested.
   *
   * @return An instance of the attribute syntax that must be tested.
   */
  protected abstract AttributeSyntax getRule();
@@ -68,9 +69,9 @@
    // test the valueIsAcceptable method
    Boolean liveResult =
      syntax.valueIsAcceptable(ByteString.valueOf(value), reason);
    if (liveResult != result)
      fail(syntax + ".valueIsAcceptable gave bad result for " + value +
      fail(syntax + ".valueIsAcceptable gave bad result for " + value +
          "reason : " + reason);
    // call the getters
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/IntegerSyntaxTest.java
New file
@@ -0,0 +1,67 @@
/*
 * 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/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * 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/CDDLv1_0.txt.  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
 *
 *
 *      Copyright 2012 ForgeRock AS
 */
package org.opends.server.schema;
import org.opends.server.api.AttributeSyntax;
import org.testng.annotations.DataProvider;
/**
 * Test the IA5StringSyntax.
 */
public class IntegerSyntaxTest extends AttributeSyntaxTest
{
  /**
   * {@inheritDoc}
   */
  @Override
  protected AttributeSyntax getRule()
  {
    return new IntegerSyntax();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  @DataProvider(name="acceptableValues")
  public Object[][] createAcceptableValues()
  {
    return new Object [][] {
        {"123", true},
        {"987654321", true},
        {"-1", true},
        {"10001", true},
        {"001", false},
        {"-01", false},
        {"12345678\u2163", false},
        {" 123", false},
        {"123 ", false}
    };
  }
}