| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | * Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | @SuppressWarnings("javadoc") |
| | | public class AbstractSubstringMatchingRuleImplTest extends AbstractSchemaTestCase { |
| | | |
| | | private int subStringLength = 3; |
| | | |
| | | private static class FakeSubstringMatchingRuleImpl extends AbstractSubstringMatchingRuleImpl { |
| | | |
| | | FakeSubstringMatchingRuleImpl() { |
| | |
| | | } |
| | | |
| | | static IndexingOptions newIndexingOptions() { |
| | | return newIndexingOptions(3); |
| | | } |
| | | |
| | | static IndexingOptions newIndexingOptions(int subStringLength) { |
| | | final IndexingOptions options = mock(IndexingOptions.class); |
| | | when(options.substringKeySize()).thenReturn(3); |
| | | when(options.substringKeySize()).thenReturn(subStringLength); |
| | | return options; |
| | | } |
| | | |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | private String subStringIndexID(String matchingRule) { |
| | | return matchingRule + ":" + subStringLength; |
| | | } |
| | | |
| | | @Test(dataProvider = "validAssertions") |
| | | public void testValidAssertions(String attrValue, String assertionValue, ConditionResult expected) |
| | | throws Exception { |
| | |
| | | null, null, Collections.EMPTY_LIST, valueOfUtf8("this")); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(subStringLength))), |
| | | "intersect[" |
| | | + "exactMatch(" + SMR_CASE_EXACT_OID + ", value=='his'), " |
| | | + "exactMatch(" + SMR_CASE_EXACT_OID + ", value=='thi')" |
| | | + "exactMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", value=='his'), " |
| | | + "exactMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", value=='thi')" |
| | | + "]"); |
| | | } |
| | | |
| | |
| | | null, valueOfUtf8("abc"), Arrays.asList(toByteStrings("def", "ghi")), valueOfUtf8("jkl")); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(subStringLength))), |
| | | "intersect[" |
| | | + "rangeMatch(" + EMR_CASE_EXACT_OID + ", 'abc' <= value < 'abd'), " |
| | | + "exactMatch(" + SMR_CASE_EXACT_OID + ", value=='def'), " |
| | | + "exactMatch(" + SMR_CASE_EXACT_OID + ", value=='ghi'), " |
| | | + "exactMatch(" + SMR_CASE_EXACT_OID + ", value=='jkl'), " |
| | | + "exactMatch(" + SMR_CASE_EXACT_OID + ", value=='abc')" |
| | | + "exactMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", value=='def'), " |
| | | + "exactMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", value=='ghi'), " |
| | | + "exactMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", value=='jkl'), " |
| | | + "exactMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", value=='abc')" |
| | | + "]"); |
| | | } |
| | | |
| | |
| | | null, valueOfUtf8("aa"), Collections.EMPTY_LIST, null); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(subStringLength))), |
| | | "intersect[" |
| | | + "rangeMatch(" + EMR_CASE_EXACT_OID + ", 'aa' <= value < 'ab'), " |
| | | + "rangeMatch(" + SMR_CASE_EXACT_OID + ", 'aa' <= value < 'ab')" |
| | | + "rangeMatch(" + EMR_CASE_EXACT_OID + ", 'aa' <= value < 'ab'), " |
| | | + "rangeMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", 'aa' <= value < 'ab')" |
| | | + "]"); |
| | | } |
| | | |
| | |
| | | null, lower, Collections.EMPTY_LIST, null); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(subStringLength))), |
| | | // 0x00 is the nul byte, a.k.a. string terminator |
| | | // so everything after it is not part of the string |
| | | "intersect[" |
| | | + "rangeMatch(" + EMR_CASE_EXACT_OID + ", '" + lower + "' <= value < 'b\u0000'), " |
| | | + "rangeMatch(" + SMR_CASE_EXACT_OID + ", '" + lower + "' <= value < 'b\u0000')" |
| | | + "rangeMatch(" + subStringIndexID(SMR_CASE_EXACT_OID) + ", '" + lower + "' <= value < 'b\u0000')" |
| | | + "]"); |
| | | } |
| | | |