Search in sources :

Example 36 with MatchingRule

use of org.apache.directory.api.ldap.model.schema.MatchingRule in project directory-ldap-api by apache.

the class MatchingRuleTest method testIntegerMatch.

@Test
public void testIntegerMatch() throws Exception {
    MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry("integerMatch");
    assertEquals(NumericNormalizer.class.getName(), mr1.getNormalizer().getClass().getName());
    assertEquals("1234567890", mr1.getNormalizer().normalize(" 1 234 567 890 "));
    // assertEquals( IntegerComparator.class.getName(), mr1.getLdapComparator().getClass().getName() );
    // assertEquals( 0, mr1.getLdapComparator().compare( " 1 234 567 890 ", "1234567890" ) );
    MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry("integerOrderingMatch");
    assertEquals(NumericNormalizer.class.getName(), mr2.getNormalizer().getClass().getName());
    assertEquals("1234567890", mr2.getNormalizer().normalize(" 1 234 567 890 "));
    assertEquals(IntegerComparator.class.getName(), mr2.getLdapComparator().getClass().getName());
    assertEquals(0, mr2.getLdapComparator().compare(1234567890L, 1234567890L));
    assertTrue(mr2.getLdapComparator().compare(123L, 234L) < 0);
    assertTrue(mr2.getLdapComparator().compare(1234L, 234L) > 0);
    // test a real attribute type: uidNumber
    AttributeType at = schemaManager.lookupAttributeTypeRegistry("uidNumber");
    assertNotNull(at.getEquality());
    assertEquals(NumericNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName());
    assertEquals("123", at.getEquality().getNormalizer().normalize(" 1 2 3 "));
    // assertEquals( 0, at.getEquality().getLdapComparator().compare( " 1 2 3 ", "123" ) );
    assertNull(at.getSubstring());
    assertNull(at.getOrdering());
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) IntegerComparator(org.apache.directory.api.ldap.model.schema.comparators.IntegerComparator) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Aggregations

MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)36 Test (org.junit.Test)21 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)9 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 ParseException (java.text.ParseException)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)4 LdapComparator (org.apache.directory.api.ldap.model.schema.LdapComparator)3 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2