OPENDJ-1308 Migrate schema support
Preparation work for removing org.opends.server.api.MatchingRule.normalizeAssertionValue().
Assertion.java:
In matches(), renamed attributeValue parameter to normalizedAttributeValue.
MatchingRuleImpl.java:
In getAssertion(), renamed value parameter to assertionValue.
Fixed javadocs.
AbstractApproximateMatchingRuleImpl.java, AbstractEqualityMatchingRuleImpl.java: ADDED
Made the relevant approximate and equality matching rule classes subclass these new ones.
AbstractMatchingRuleImpl.java:
In getAssertion(), returned UNDEFINED_ASSERTION.
Extracted method trimConsecutiveSpaces() here from several places in the code.
WordEqualityMatchingRuleImpl.java: REMOVED
Implementation was the same as KeywordEqualityMatchingRuleImpl so reused that class instead + updated CoreSchemaImpl.
KeywordEqualityMatchingRuleImpl.java:
Extracted method isAcceptable().
Removed useless calls to String.intern() on String literals.
IntegerFirstComponentEqualityMatchingRuleImpl.java:
In getAssertion(), used DefaultEqualityAssertion instead of custom built Assertion.
EnumSyntaxTestCase.java:
Made the code more readable.
*.java:
Simplified code by using ConditionResult.valueOf().
1 files deleted
2 files added
41 files modified
| | |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | /** |
| | |
| | | * Indicates whether the provided attribute value should be considered a |
| | | * match for this assertion value according to the matching rule. |
| | | * |
| | | * @param attributeValue |
| | | * @param normalizedAttributeValue |
| | | * The normalized attribute value. |
| | | * @return {@code TRUE} if the attribute value should be considered a match |
| | | * for the provided assertion value, {@code FALSE} if it does not |
| | | * match, or {@code UNDEFINED} if the result is undefined. |
| | | */ |
| | | public abstract ConditionResult matches(ByteSequence attributeValue); |
| | | ConditionResult matches(ByteSequence normalizedAttributeValue); |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 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 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 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | /** |
| | | * This class implements an approximate matching rule that matches normalized |
| | | * values in byte order. |
| | | */ |
| | | abstract class AbstractApproximateMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | |
| | | AbstractApproximateMatchingRuleImpl() { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | return new DefaultEqualityAssertion(normalizeAttributeValue(schema, assertionValue)); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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 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 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 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | |
| | | /** |
| | | * This class implements an equality matching rule that matches normalized |
| | | * values in byte order. |
| | | */ |
| | | abstract class AbstractEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | |
| | | AbstractEqualityMatchingRuleImpl() { |
| | | // Nothing to do. |
| | | } |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | return new DefaultEqualityAssertion(normalizeAttributeValue(schema, assertionValue)); |
| | | } |
| | | |
| | | } |
| | |
| | | * matches normalized values in byte order. |
| | | */ |
| | | abstract class AbstractMatchingRuleImpl implements MatchingRuleImpl { |
| | | static class DefaultEqualityAssertion implements Assertion { |
| | | ByteSequence normalizedAssertionValue; |
| | | static final class DefaultEqualityAssertion implements Assertion { |
| | | private final ByteSequence normalizedAssertionValue; |
| | | |
| | | protected DefaultEqualityAssertion(final ByteSequence normalizedAssertionValue) { |
| | | DefaultEqualityAssertion(final ByteSequence normalizedAssertionValue) { |
| | | this.normalizedAssertionValue = normalizedAssertionValue; |
| | | } |
| | | |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | | return normalizedAssertionValue.equals(attributeValue) ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE; |
| | | return ConditionResult.valueOf(normalizedAssertionValue.equals(attributeValue)); |
| | | } |
| | | } |
| | | |
| | |
| | | return DEFAULT_COMPARATOR; |
| | | } |
| | | |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | return new DefaultEqualityAssertion(normalizeAttributeValue(schema, value)); |
| | | return UNDEFINED_ASSERTION; |
| | | } |
| | | |
| | | public Assertion getSubstringAssertion(final Schema schema, final ByteSequence subInitial, |
| | |
| | | throws DecodeException { |
| | | return UNDEFINED_ASSERTION; |
| | | } |
| | | |
| | | static void trimConsecutiveSpaces(StringBuilder buffer) { |
| | | for (int pos = buffer.length() - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ' |
| | | && buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | // Nothing to do. |
| | | } |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final ByteString normAssertion = normalizeAttributeValue(schema, value); |
| | | return new Assertion() { |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | | return attributeValue.compareTo(normAssertion) < 0 ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE; |
| | | return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) < 0); |
| | | } |
| | | }; |
| | | } |
| | |
| | | final ByteString normAssertion = normalizeAttributeValue(schema, value); |
| | | return new Assertion() { |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | | return attributeValue.compareTo(normAssertion) >= 0 ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE; |
| | | return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) >= 0); |
| | | } |
| | | }; |
| | | } |
| | |
| | | final ByteString normAssertion = normalizeAttributeValue(schema, value); |
| | | return new Assertion() { |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | | return attributeValue.compareTo(normAssertion) <= 0 ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE; |
| | | return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) <= 0); |
| | | } |
| | | }; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | if (value.length() == 0) { |
| | | if (assertionValue.length() == 0) { |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_EMPTY.get()); |
| | | } |
| | | |
| | |
| | | ByteSequence finalString = null; |
| | | List<ByteSequence> anyStrings = null; |
| | | |
| | | final String valueString = value.toString(); |
| | | final String valueString = assertionValue.toString(); |
| | | |
| | | if (valueString.length() == 1 && valueString.charAt(0) == '*') { |
| | | return getSubstringAssertion(schema, initialString, anyStrings, finalString); |
| | |
| | | initialString = normalizeSubString(schema, bytes); |
| | | } |
| | | if (reader.remaining() == 0) { |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_NO_WILDCARDS.get(value |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_NO_WILDCARDS.get(assertionValue |
| | | .toString())); |
| | | } |
| | | while (true) { |
| | |
| | | if (reader.remaining() > 0) { |
| | | if (bytes.length() == 0) { |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_CONSECUTIVE_WILDCARDS |
| | | .get(value.toString(), reader.pos())); |
| | | .get(assertionValue.toString(), reader.pos())); |
| | | } |
| | | if (anyStrings == null) { |
| | | anyStrings = new LinkedList<ByteSequence>(); |
| | |
| | | * This class implements the authPasswordMatch matching rule defined in RFC |
| | | * 3112. |
| | | */ |
| | | final class AuthPasswordExactEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class AuthPasswordExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder[] authPWComponents = |
| | |
| | | * This class defines the bitStringMatch matching rule defined in X.520 and |
| | | * referenced in RFC 2252. |
| | | */ |
| | | final class BitStringEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class BitStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final String valueString = value.toString().toUpperCase(); |
| | |
| | | * This class defines the booleanMatch matching rule defined in X.520 and |
| | | * referenced in RFC 4519. |
| | | */ |
| | | final class BooleanEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class BooleanEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final String valueString = value.toString().toUpperCase(); |
| | |
| | | * This class defines the caseExactMatch matching rule defined in X.520 and |
| | | * referenced in RFC 4519. |
| | | */ |
| | | final class CaseExactEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class CaseExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * This class implements the caseExactIA5Match matching rule defined in RFC |
| | | * 2252. |
| | | */ |
| | | final class CaseExactIA5EqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class CaseExactIA5EqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * This class defines the caseIgnoreMatch matching rule defined in X.520 and |
| | | * referenced in RFC 2252. |
| | | */ |
| | | final class CaseIgnoreEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class CaseIgnoreEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * This class implements the caseIgnoreIA5Match matching rule defined in RFC |
| | | * 2252. |
| | | */ |
| | | final class CaseIgnoreIA5EqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class CaseIgnoreIA5EqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | |
| | | * This class implements the caseIgnoreListMatch matching rule defined in X.520 |
| | | * and referenced in RFC 2252. |
| | | */ |
| | | final class CaseIgnoreListEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class CaseIgnoreListEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | .syntaxOID(SYNTAX_NAME_AND_OPTIONAL_UID_OID).extraProperties(RFC4512_ORIGIN) |
| | | .implementation(new UniqueMemberEqualityMatchingRuleImpl()).addToSchema(); |
| | | builder.buildMatchingRule(EMR_WORD_OID).names(EMR_WORD_NAME).syntaxOID(SYNTAX_DIRECTORY_STRING_OID) |
| | | .extraProperties(RFC4512_ORIGIN).implementation(new WordEqualityMatchingRuleImpl()) |
| | | .extraProperties(RFC4512_ORIGIN).implementation(new KeywordEqualityMatchingRuleImpl()) |
| | | .addToSchema(); |
| | | } |
| | | |
| | |
| | | * objectclass descriptions) in which the "first component" is the first item |
| | | * after the opening parenthesis. |
| | | */ |
| | | final class DirectoryStringFirstComponentEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class DirectoryStringFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) { |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | prepareUnicode(buffer, assertionValue, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (value.length() > 0) { |
| | | if (assertionValue.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return new DefaultEqualityAssertion(SchemaConstants.SINGLE_SPACE_VALUE); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return new DefaultEqualityAssertion(ByteString.valueOf(buffer.toString())); |
| | | } |
| | |
| | | } |
| | | |
| | | // The next character must be an open parenthesis. If it is not, |
| | | // then |
| | | // that is an error. |
| | | // then that is an error. |
| | | final char c = reader.read(); |
| | | if (c != '(') { |
| | | final LocalizableMessage message = |
| | |
| | | throw DecodeException.error(message); |
| | | } |
| | | |
| | | // Skip over any spaces immediately following the opening |
| | | // parenthesis. |
| | | // Skip over any spaces immediately following the opening parenthesis. |
| | | reader.skipWhitespaces(); |
| | | |
| | | // The next set of characters must be the OID. |
| | |
| | | * This class defines the distinguishedNameMatch matching rule defined in X.520 |
| | | * and referenced in RFC 2252. |
| | | */ |
| | | final class DistinguishedNameEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class DistinguishedNameEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | |
| | | * redundant checks that aren't needed. It has also been updated to always only |
| | | * generate a single value rather than one or possibly two values. |
| | | */ |
| | | final class DoubleMetaphoneApproximateMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class DoubleMetaphoneApproximateMatchingRuleImpl extends AbstractApproximateMatchingRuleImpl { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.TRIM; |
| | | import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_LDAPSYNTAX_ENUM_INVALID_VALUE; |
| | | |
| | | import static org.forgerock.opendj.ldap.schema.AbstractMatchingRuleImpl.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.AMR_DOUBLE_METAPHONE_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_CASE_IGNORE_OID; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.OMR_OID_GENERIC_ENUM; |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return buffer.toString(); |
| | | } |
| | |
| | | * consider two values approximately equal only if they have the same length. It |
| | | * is intended purely for testing purposes. |
| | | */ |
| | | final class EqualLengthApproximateMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class EqualLengthApproximateMatchingRuleImpl extends AbstractApproximateMatchingRuleImpl { |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | return new Assertion() { |
| | | @Override |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | | return attributeValue.length() == value.length() ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE; |
| | | return ConditionResult.valueOf(attributeValue.length() == assertionValue.length()); |
| | | } |
| | | }; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return value.toByteString(); |
| | | } |
| | |
| | | * This class defines the generalizedTimeMatch matching rule defined in X.520 |
| | | * and referenced in RFC 2252. |
| | | */ |
| | | final class GeneralizedTimeEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class GeneralizedTimeEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | try { |
| | |
| | | * This class defines the integerMatch matching rule defined in X.520 and |
| | | * referenced in RFC 2252. |
| | | */ |
| | | final class IntegerEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class IntegerEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | try { |
| | | return ByteString.valueOf(Integer.parseInt(value.toString())); |
| | | } catch (final Exception e) { |
| | | logger.debug(LocalizableMessage.raw("%s", e)); |
| | | |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value.toString()); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value)); |
| | | } |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.Assertion; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | |
| | | * objectclass descriptions) in which the "first component" is the first item |
| | | * after the opening parenthesis. |
| | | */ |
| | | final class IntegerFirstComponentEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class IntegerFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | try { |
| | | final String definition = value.toString(); |
| | | final String definition = assertionValue.toString(); |
| | | final SubstringReader reader = new SubstringReader(definition); |
| | | final int intValue = SchemaUtils.readRuleID(reader); |
| | | |
| | | return new Assertion() { |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | | final int actualIntValue = attributeValue.toByteString().toInt(); |
| | | return intValue == actualIntValue ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE; |
| | | } |
| | | }; |
| | | return new DefaultEqualityAssertion(ByteString.valueOf(intValue)); |
| | | } catch (final Exception e) { |
| | | logger.debug(LocalizableMessage.raw("%s", e)); |
| | | |
| | | final LocalizableMessage message = |
| | | ERR_EMR_INTFIRSTCOMP_FIRST_COMPONENT_NOT_INT.get(value.toString()); |
| | | ERR_EMR_INTFIRSTCOMP_FIRST_COMPONENT_NOT_INT.get(assertionValue.toString()); |
| | | throw DecodeException.error(message); |
| | | } |
| | | |
| | |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | @Override |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | try { |
| | | return ByteString.valueOf(Integer.parseInt(value.toString())); |
| | | } catch (final Exception e) { |
| | | logger.debug(LocalizableMessage.raw("%s", e)); |
| | | |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value.toString()); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value)); |
| | | } |
| | | } |
| | | } |
| | |
| | | * This class implements the keywordMatch matching rule defined in X.520. That |
| | | * document defines "keyword" as implementation-specific, but in this case we |
| | | * will consider it a match if the assertion value is contained within the |
| | | * attribute value and is bounded by the edge of the value or any of the |
| | | * following characters: <BR> |
| | | * attribute value and is bounded by the start or the end of the attribute value |
| | | * or any of the following characters: <BR> |
| | | * <UL> |
| | | * <LI>A space</LI> |
| | | * <LI>A period</LI> |
| | |
| | | * <LI>An equal sign</LI> |
| | | * </UL> |
| | | */ |
| | | final class KeywordEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class KeywordEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | final String normalStr = normalize(value); |
| | | final String normalStr = normalize(assertionValue); |
| | | |
| | | return new Assertion() { |
| | | public ConditionResult matches(final ByteSequence attributeValue) { |
| | |
| | | |
| | | if (pos > 0) { |
| | | final char c = valueStr1.charAt(pos - 1); |
| | | switch (c) { |
| | | case ' ': |
| | | case '.': |
| | | case ',': |
| | | case '/': |
| | | case '$': |
| | | case '+': |
| | | case '-': |
| | | case '_': |
| | | case '#': |
| | | case '=': |
| | | // These are all acceptable. |
| | | break; |
| | | |
| | | default: |
| | | // Anything else is not. |
| | | if (!isAcceptable(c)) { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | } |
| | | |
| | | if (valueStr1.length() > pos + normalStr.length()) { |
| | | final char c = valueStr1.charAt(pos + normalStr.length()); |
| | | if (!isAcceptable(c)) { |
| | | return ConditionResult.FALSE; |
| | | } |
| | | } |
| | | |
| | | // If we've gotten here, then we can assume it is a match. |
| | | return ConditionResult.TRUE; |
| | | } |
| | | |
| | | private boolean isAcceptable(final char c) { |
| | | switch (c) { |
| | | case ' ': |
| | | case '.': |
| | |
| | | case '_': |
| | | case '#': |
| | | case '=': |
| | | // These are all acceptable. |
| | | break; |
| | | return true; |
| | | |
| | | default: |
| | | // Anything else is not. |
| | | return ConditionResult.FALSE; |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | // If we've gotten here, then we can assume it is a match. |
| | | return ConditionResult.TRUE; |
| | | } |
| | | }; |
| | | } |
| | | |
| | |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | | |
| | | final int bufferLength = buffer.length(); |
| | | if (bufferLength == 0) { |
| | | if (buffer.length() == 0) { |
| | | if (value.length() > 0) { |
| | | // This should only happen if the value is composed entirely of |
| | | // spaces. In that case, the normalized value is a single space. |
| | | return " ".intern(); |
| | | return " "; |
| | | } else { |
| | | // The value is empty, so it is already normalized. |
| | | return "".intern(); |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return buffer.toString(); |
| | | } |
| | |
| | | * @return A comparator that can be used to compare the attribute values |
| | | * normalized by this matching rule. |
| | | */ |
| | | public Comparator<ByteSequence> comparator(Schema schema); |
| | | Comparator<ByteSequence> comparator(Schema schema); |
| | | |
| | | /** |
| | | * Retrieves the normalized form of the provided assertion value, which is |
| | | * best suited for efficiently performing matching operations on that value. |
| | | * The assertion value is guarenteed to be valid against this matching |
| | | * The assertion value is guaranteed to be valid against this matching |
| | | * rule's assertion syntax. |
| | | * |
| | | * @param schema |
| | | * The schema in which this matching rule is defined. |
| | | * @param value |
| | | * @param assertionValue |
| | | * The syntax checked assertion value to be normalized. |
| | | * @return The normalized version of the provided assertion value. |
| | | * @throws DecodeException |
| | | * if an syntax error occured while parsing the value. |
| | | * if an syntax error occurred while parsing the value. |
| | | */ |
| | | public Assertion getAssertion(Schema schema, ByteSequence value) throws DecodeException; |
| | | Assertion getAssertion(Schema schema, ByteSequence assertionValue) throws DecodeException; |
| | | |
| | | /** |
| | | * Retrieves the normalized form of the provided assertion substring values, |
| | |
| | | * the end of the target value. |
| | | * @return The normalized version of the provided assertion value. |
| | | * @throws DecodeException |
| | | * if an syntax error occured while parsing the value. |
| | | * if an syntax error occurred while parsing the value. |
| | | */ |
| | | public Assertion getSubstringAssertion(Schema schema, ByteSequence subInitial, |
| | | Assertion getSubstringAssertion(Schema schema, ByteSequence subInitial, |
| | | List<? extends ByteSequence> subAnyElements, ByteSequence subFinal) |
| | | throws DecodeException; |
| | | |
| | | /** |
| | | * Retrieves the normalized form of the provided assertion value, which is |
| | | * best suited for efficiently performing greater than or equal matching |
| | | * operations on that value. The assertion value is guarenteed to be valid |
| | | * operations on that value. The assertion value is guaranteed to be valid |
| | | * against this matching rule's assertion syntax. |
| | | * |
| | | * @param schema |
| | |
| | | * The syntax checked assertion value to be normalized. |
| | | * @return The normalized version of the provided assertion value. |
| | | * @throws DecodeException |
| | | * if an syntax error occured while parsing the value. |
| | | * if an syntax error occurred while parsing the value. |
| | | */ |
| | | public Assertion getGreaterOrEqualAssertion(Schema schema, ByteSequence value) |
| | | Assertion getGreaterOrEqualAssertion(Schema schema, ByteSequence value) |
| | | throws DecodeException; |
| | | |
| | | /** |
| | | * Retrieves the normalized form of the provided assertion value, which is |
| | | * best suited for efficiently performing greater than or equal matching |
| | | * operations on that value. The assertion value is guarenteed to be valid |
| | | * operations on that value. The assertion value is guaranteed to be valid |
| | | * against this matching rule's assertion syntax. |
| | | * |
| | | * @param schema |
| | |
| | | * The syntax checked assertion value to be normalized. |
| | | * @return The normalized version of the provided assertion value. |
| | | * @throws DecodeException |
| | | * if an syntax error occured while parsing the value. |
| | | * if an syntax error occurred while parsing the value. |
| | | */ |
| | | public Assertion getLessOrEqualAssertion(Schema schema, ByteSequence value) |
| | | Assertion getLessOrEqualAssertion(Schema schema, ByteSequence value) |
| | | throws DecodeException; |
| | | |
| | | /** |
| | |
| | | * The attribute value to be normalized. |
| | | * @return The normalized version of the provided attribute value. |
| | | * @throws DecodeException |
| | | * if an syntax error occured while parsing the value. |
| | | * if an syntax error occurred while parsing the value. |
| | | */ |
| | | public ByteString normalizeAttributeValue(Schema schema, ByteSequence value) |
| | | ByteString normalizeAttributeValue(Schema schema, ByteSequence value) |
| | | throws DecodeException; |
| | | |
| | | } |
| | |
| | | * and referenced in RFC 2252. It allows for values with numeric digits and |
| | | * spaces, but ignores spaces when performing matching. |
| | | */ |
| | | final class NumericStringEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class NumericStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD); |
| | |
| | | * either an attribute/objectclass name or a numeric OID. NOTE: This matching |
| | | * rule requires a schema to lookup object identifiers in the descriptor form. |
| | | */ |
| | | final class ObjectIdentifierEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class ObjectIdentifierEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | static String resolveNames(final Schema schema, final String oid) { |
| | | if (!StaticUtils.isDigit(oid.charAt(0))) { |
| | | // Do an best effort attempt to normalize names to OIDs. |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | final String definition = value.toString(); |
| | | final String definition = assertionValue.toString(); |
| | | final SubstringReader reader = new SubstringReader(definition); |
| | | final String normalized = |
| | | resolveNames(schema, SchemaUtils.readOID(reader, schema |
| | |
| | | * objectclass descriptions) in which the "first component" is the first item |
| | | * after the opening parenthesis. |
| | | */ |
| | | final class ObjectIdentifierFirstComponentEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class ObjectIdentifierFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) |
| | | throws DecodeException { |
| | | final String definition = value.toString(); |
| | | final String definition = assertionValue.toString(); |
| | | final SubstringReader reader = new SubstringReader(definition); |
| | | final String normalized = |
| | | ObjectIdentifierEqualityMatchingRuleImpl.resolveNames(schema, SchemaUtils.readOID( |
| | |
| | | * will be used as the default equality matching rule for the binary and octet |
| | | * string syntaxes. |
| | | */ |
| | | final class OctetStringEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class OctetStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return value.toByteString(); |
| | | } |
| | |
| | | * associated syntax have been deprecated, this matching rule behaves exactly |
| | | * like the caseIgnoreMatch rule. |
| | | */ |
| | | final class PresentationAddressEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class PresentationAddressEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * associated syntax have been deprecated, this matching rule behaves exactly |
| | | * like the caseIgnoreMatch rule. |
| | | */ |
| | | final class ProtocolInformationEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class ProtocolInformationEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | prepareUnicode(buffer, value, TRIM, CASE_FOLD); |
| | |
| | | } |
| | | } |
| | | |
| | | // Replace any consecutive spaces with a single space. |
| | | for (int pos = bufferLength - 1; pos > 0; pos--) { |
| | | if (buffer.charAt(pos) == ' ') { |
| | | if (buffer.charAt(pos - 1) == ' ') { |
| | | buffer.delete(pos, pos + 1); |
| | | } |
| | | } |
| | | } |
| | | trimConsecutiveSpaces(buffer); |
| | | |
| | | return ByteString.valueOf(buffer.toString()); |
| | | } |
| | |
| | | * very rigorous format, this is widely ignored so this matching will compare |
| | | * only numeric digits and strip out everything else. |
| | | */ |
| | | final class TelephoneNumberEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class TelephoneNumberEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | final String valueString = value.toString(); |
| | | final int valueLength = valueString.length(); |
| | |
| | | * This class defines the uuidMatch matching rule defined in RFC 4530. It will |
| | | * be used as the default equality matching rule for the UUID syntax. |
| | | */ |
| | | final class UUIDEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class UUIDEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | if (value.length() != 36) { |
| | |
| | | * and will compare values with a distinguished name and optional bit string |
| | | * suffix. |
| | | */ |
| | | final class UniqueMemberEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class UniqueMemberEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return value.toByteString(); |
| | | } |
| | |
| | | * simply compare encoded hashed password values to see if they are exactly |
| | | * equal to each other. |
| | | */ |
| | | final class UserPasswordExactEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl { |
| | | final class UserPasswordExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl { |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | // The normalized form of this matching rule is exactly equal to the |
| | |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.OMR_OID_GENERIC_ENUM; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.testng.Assert; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ConditionResult.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * Enum syntax tests. |
| | | */ |
| | |
| | | final Schema schema = builder.toSchema(); |
| | | final Syntax syntax = schema.getSyntax("3.3.3"); |
| | | final MatchingRule rule = syntax.getOrderingMatchingRule(); |
| | | Assert.assertEquals(rule.getGreaterOrEqualAssertion(ByteString.valueOf("monday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("thursday"))), ConditionResult.TRUE); |
| | | Assert.assertEquals(rule.getLessOrEqualAssertion(ByteString.valueOf("monday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("thursday"))), |
| | | ConditionResult.FALSE); |
| | | Assert.assertEquals(rule.getGreaterOrEqualAssertion(ByteString.valueOf("tuesday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("monday"))), ConditionResult.FALSE); |
| | | Assert.assertEquals(rule.getLessOrEqualAssertion(ByteString.valueOf("tuesday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("monday"))), ConditionResult.TRUE); |
| | | Assert.assertEquals(rule.getGreaterOrEqualAssertion(ByteString.valueOf("tuesday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("tuesday"))), ConditionResult.TRUE); |
| | | Assert.assertEquals(rule.getLessOrEqualAssertion(ByteString.valueOf("tuesday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("tuesday"))), ConditionResult.TRUE); |
| | | Assert.assertEquals(rule.getAssertion(ByteString.valueOf("tuesday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("monday"))), ConditionResult.TRUE); |
| | | Assert.assertEquals(rule.getAssertion(ByteString.valueOf("monday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("thursday"))), |
| | | ConditionResult.FALSE); |
| | | Assert.assertEquals(rule.getAssertion(ByteString.valueOf("tuesday")).matches( |
| | | rule.normalizeAttributeValue(ByteString.valueOf("tuesday"))), ConditionResult.FALSE); |
| | | Assert.assertNotNull(schema.getMatchingRule(OMR_OID_GENERIC_ENUM + ".3.3.3")); |
| | | final ByteString monday = ByteString.valueOf("monday"); |
| | | final ByteString normMonday = rule.normalizeAttributeValue(monday); |
| | | final ByteString tuesday = ByteString.valueOf("tuesday"); |
| | | final ByteString normTuesday = rule.normalizeAttributeValue(tuesday); |
| | | final ByteString normThursday = rule.normalizeAttributeValue(ByteString.valueOf("thursday")); |
| | | assertEquals(rule.getGreaterOrEqualAssertion(monday).matches(normThursday), TRUE); |
| | | assertEquals(rule.getLessOrEqualAssertion(monday).matches(normThursday), FALSE); |
| | | assertEquals(rule.getGreaterOrEqualAssertion(tuesday).matches(normMonday), FALSE); |
| | | assertEquals(rule.getLessOrEqualAssertion(tuesday).matches(normMonday), TRUE); |
| | | assertEquals(rule.getGreaterOrEqualAssertion(tuesday).matches(normTuesday), TRUE); |
| | | assertEquals(rule.getLessOrEqualAssertion(tuesday).matches(normTuesday), TRUE); |
| | | assertEquals(rule.getAssertion(tuesday).matches(normMonday), TRUE); |
| | | assertEquals(rule.getAssertion(monday).matches(normThursday), FALSE); |
| | | assertEquals(rule.getAssertion(tuesday).matches(normTuesday), FALSE); |
| | | assertNotNull(schema.getMatchingRule(OMR_OID_GENERIC_ENUM + ".3.3.3")); |
| | | } |
| | | |
| | | @Test |
| | |
| | | } |
| | | |
| | | Assertion a = ruleInstance.getGreaterOrEqualAssertion(ByteString.valueOf(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), result >= 0 ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE); |
| | | Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result >= 0)); |
| | | |
| | | a = ruleInstance.getLessOrEqualAssertion(ByteString.valueOf(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), result <= 0 ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE); |
| | | Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result <= 0)); |
| | | |
| | | a = ruleInstance.getAssertion(ByteString.valueOf(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), result < 0 ? ConditionResult.TRUE |
| | | : ConditionResult.FALSE); |
| | | Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result < 0)); |
| | | } |
| | | |
| | | /** |