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

Nicolas Capponi
04.11.2014 4d05eea8a9d06056e422f3203b77aefd49a5dcd0
OPENDJ-1630 CR-5560 Fix some matching rules and their tests

Fix AbstractSubstringMatchingRuleImpl.evaluatesEscape() method
Fix SchemaUtils.normalizeNumericStringAttributeValue() method

Fix tests:
- AbstractSubstringMatchingRuleImplTest
- DirectoryStringFirstComponentEqualityMatchingRuleTest
- NumericStringEqualityMatchingRuleTest
- NumericStringOrderingMatchingRuleTest
- NumericStringSubstringMatchingRuleTest
- SchemaUtilsTest
- UniqueMemberEqualityMatchingRuleTest
9 files modified
58 ■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java 1 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java 8 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImplTest.java 9 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleTest.java 9 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleTest.java 9 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/NumericStringOrderingMatchingRuleTest.java 10 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/NumericStringSubstringMatchingRuleTest.java 3 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaUtilsTest.java 2 ●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleTest.java 7 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java
@@ -508,6 +508,7 @@
                valueBuffer.append(evaluateEscapedChar(reader, escapeChars));
                reader.mark();
                length = 0;
                continue;
            }
            if (delimiterChars != null) {
                for (final char delimiterChar : delimiterChars) {
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaUtils.java
@@ -771,6 +771,14 @@
        final StringBuilder buffer = new StringBuilder();
        prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD);
        // Remove any space
        for (int pos = buffer.length() - 1; pos > 0; pos--) {
            char c = buffer.charAt(pos);
            if (c == ' ') {
                buffer.delete(pos, pos + 1);
            }
        }
        if (buffer.length() == 0) {
            return ByteString.empty();
        }
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImplTest.java
@@ -152,7 +152,9 @@
            { "**" },
            { "\\g" },
            { "\\0" },
            { "\\00" },
            { "\\0g" },
            { gen() },
        };
    }
@@ -170,10 +172,9 @@
            { "this is a string", "this*is*a*string", ConditionResult.TRUE },
            { "this is a string", "this*my*string", ConditionResult.FALSE },
            { "this is a string", "string*a*is*this", ConditionResult.FALSE },
            // FIXME next line is not working (StringIndexOutOfBoundsException), is it incorrect?
            // { "this is a string", "\\00", ConditionResult.FALSE },
            // FIXME next line is not working (DecodeException), is it incorrect?
            // { "this is a string", gen(), ConditionResult.FALSE },
            { "this is a string", "string*a*is*this", ConditionResult.FALSE },
            { "this is a string", "*\\00", ConditionResult.FALSE },
            { "this is a string", gen() + "*", ConditionResult.FALSE },
            // initial longer than value
            { "tt", "this*", ConditionResult.FALSE },
            { "tt", "*this", ConditionResult.FALSE },
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleTest.java
@@ -27,12 +27,14 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_DIRECTORY_STRING_FIRST_COMPONENT_OID;
import org.forgerock.opendj.ldap.ConditionResult;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test the DirectoryStringFirstComponentEqualityMatchingRule.
 */
//TODO: fix matching rule so that commented data in data providers pass
@Test
public class DirectoryStringFirstComponentEqualityMatchingRuleTest extends MatchingRuleTest {
    /** {@inheritDoc} */
@@ -47,8 +49,9 @@
    @DataProvider(name = "matchingrules")
    public Object[][] createMatchingRuleTest() {
        return new Object[][] {
            //{"(1.2.8.5 NAME 'testtype' DESC 'full type')", "1.2.8.5", ConditionResult.TRUE },
            //{"(1.2.8.5 NAME 'testtype' DESC 'full type')", "something", ConditionResult.FALSE },
            { "('full type' 'other value')", "other value", ConditionResult.FALSE },
            { "('full type' 'other value')", "something", ConditionResult.FALSE },
            { "('full type' 'other value')", "full type", ConditionResult.TRUE },
        };
    }
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleTest.java
@@ -29,11 +29,12 @@
import org.forgerock.opendj.ldap.ConditionResult;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test the NumericStringEqualityMatchingRule.
 */
//TODO: fix matching rule so that commented data in data providers pass
@Test
public class NumericStringEqualityMatchingRuleTest extends MatchingRuleTest {
    /** {@inheritDoc} */
@@ -41,7 +42,6 @@
    @DataProvider(name = "matchingRuleInvalidAttributeValues")
    public Object[][] createMatchingRuleInvalidAttributeValues() {
        return new Object[][] {
            //{"A2B1"}
        };
    }
@@ -50,9 +50,12 @@
    @DataProvider(name = "matchingrules")
    public Object[][] createMatchingRuleTest() {
        return new Object[][] {
            // non-numeric characters are tolerated and treated as significant
            {"A2B1", "A2B1", ConditionResult.TRUE },
            {"A2B1", "A2b1", ConditionResult.FALSE },
            {"1234567890", "1234567890", ConditionResult.TRUE },
            {" 1234567890  ", "1234567890", ConditionResult.TRUE },
            //{" 123   4567890  ", "1234567890", ConditionResult.TRUE },
            {" 123   4567890  ", "1234567890", ConditionResult.TRUE },
            {"1234", "5678", ConditionResult.FALSE },
        };
    }
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/NumericStringOrderingMatchingRuleTest.java
@@ -28,11 +28,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.OMR_NUMERIC_STRING_OID;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test the NumericStringOrderingMatchingRule.
 */
//TODO: fix matching rule so that commented data in data providers pass
@Test
public class NumericStringOrderingMatchingRuleTest extends OrderingMatchingRuleTest {
    /** {@inheritDoc} */
@@ -40,8 +41,6 @@
    @DataProvider(name = "OrderingMatchingRuleInvalidValues")
    public Object[][] createOrderingMatchingRuleInvalidValues() {
        return new Object[][] {
            //{"jfhslur"},
            //{"123AB"},
        };
    }
@@ -50,8 +49,13 @@
    @DataProvider(name = "Orderingmatchingrules")
    public Object[][] createOrderingMatchingRuleTestData() {
        return new Object[][] {
            // non-numeric characters are tolerated and treated as significant
            {"jfhslur", "JFH", 1},
            {"123AB", "2", -1},
            {"1", "999999999999999999999", -1},
            {"1", "9",  -1},
            {"10", "9",  -1},
            {"1 0", "9",  -1},
            {"1", " 1 ", 0},
            {"0", "1",  -1},
            {"1", "0",  1},
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/NumericStringSubstringMatchingRuleTest.java
@@ -29,11 +29,13 @@
import org.forgerock.opendj.ldap.ConditionResult;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test the NumericStringSubstringMatchingRule.
 */
@SuppressWarnings("javadoc")
@Test
public class NumericStringSubstringMatchingRuleTest extends SubstringMatchingRuleTest {
    @Override
@@ -56,6 +58,7 @@
    public Object[][] createSubstringFinalMatchData() {
        return new Object[][] {
            {"123456789",  "123456789", ConditionResult.TRUE },
            {"12 345 6789",  "123456789", ConditionResult.TRUE },
            {"123456789",  "456789", ConditionResult.TRUE },
            {"123456789",  "567", ConditionResult.FALSE },
            {"123456789",  "123", ConditionResult.FALSE },
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaUtilsTest.java
@@ -249,7 +249,7 @@
            { "", "" },
            { "   ", "" },
            { " 123  ", "123" },
            { " 123  456  ", "123 456" },
            { " 123  456  ", "123456" },
        };
    }
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleTest.java
@@ -29,11 +29,12 @@
import org.forgerock.opendj.ldap.ConditionResult;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test the UniqueMemberEqualityMatchingRule.
 */
//TODO: fix matching rule so that commented data in data providers pass
@Test
public class UniqueMemberEqualityMatchingRuleTest extends MatchingRuleTest {
    /** {@inheritDoc} */
@@ -41,7 +42,6 @@
    @DataProvider(name = "matchingRuleInvalidAttributeValues")
    public Object[][] createMatchingRuleInvalidAttributeValues() {
        return new Object[][] {
            //{"1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'123'B"},
            {"1.3.6.1.4.1.1466.01"}
        };
    }
@@ -51,6 +51,9 @@
    @DataProvider(name = "matchingrules")
    public Object[][] createMatchingRuleTest() {
        return new Object[][] {
            // non-bit string content on optional uid is tolerated
            { "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'123'B",
              "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'123'B", ConditionResult.TRUE },
            { "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'0101'B",
              "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'0101'B", ConditionResult.TRUE },
            { "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'0101'B",