Search in sources :

Example 31 with MatchingRule

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

the class SchemaManagerAddTest method testAddMatchingRuleNoSyntax.

/**
 * Try to inject a new MatchingRule without a syntax
 */
@Test
public void testAddMatchingRuleNoSyntax() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MatchingRule matchingRule = new MatchingRule("1.1.0");
    // It should fail (no syntax)
    assertFalse(schemaManager.add(matchingRule));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    assertFalse(isMRPresent(schemaManager, "1.1.0"));
    assertEquals(mrrSize, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) Test(org.junit.Test)

Example 32 with MatchingRule

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

the class SchemaManagerDelTest method testDeleteExistingMatchingRuleUsedByAttributeType.

@Test
public void testDeleteExistingMatchingRuleUsedByAttributeType() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int mrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    // AT with OID 2.5.18.4 has syntax 1.3.6.1.4.1.1466.115.121.1.12 which is used by MR 2.5.13.1
    MatchingRule mr = new MatchingRule("2.5.13.1");
    assertFalse(schemaManager.delete(mr));
    assertEquals(mrSize, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 33 with MatchingRule

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

the class SchemaManagerDelTest method testDeleteExistingComparatorUsedByRemovedMatchingRule.

/**
 * Check that a Comparator which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingComparatorUsedByRemovedMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String OID = "2.5.13.33";
    // Check that the MR and C are present
    assertTrue(isMatchingRulePresent(schemaManager, OID));
    assertTrue(isComparatorPresent(schemaManager, OID));
    // Now try to remove the C
    LdapComparator<?> lc = schemaManager.lookupComparatorRegistry(OID);
    // shouldn't be deleted cause there is a MR associated with it
    assertFalse(schemaManager.delete(lc));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using MR : it should be OK
    MatchingRule mr = new MatchingRule(OID);
    assertTrue(schemaManager.delete(mr));
    assertEquals(mrrSize - 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isMatchingRulePresent(schemaManager, OID));
    // and try to delete the Comparator again
    assertTrue(schemaManager.delete(lc));
    assertFalse(isComparatorPresent(schemaManager, OID));
    assertEquals(ctrSize - 1, schemaManager.getComparatorRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 34 with MatchingRule

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

the class SchemaManagerDelTest method testDeleteNonExistingMatchingRule.

@Test
public void testDeleteNonExistingMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int mrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MatchingRule mr = new MatchingRule("0.1.1");
    assertFalse(schemaManager.delete(mr));
    assertEquals(mrSize, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 35 with MatchingRule

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

the class MatchingRuleTest method testTelephoneNumberMatch.

@Test
public void testTelephoneNumberMatch() throws Exception {
    // matching rule: telephoneNumberMatch
    MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry("telephoneNumberMatch");
    assertEquals(TelephoneNumberNormalizer.class.getName(), mr1.getNormalizer().getClass().getName());
    assertEquals("+1234567890", mr1.getNormalizer().normalize(" +1 234-567 890 "));
    assertEquals(TelephoneNumberComparator.class.getName(), mr1.getLdapComparator().getClass().getName());
    assertEquals(0, mr1.getLdapComparator().compare(" +1 234-567 890 ", "+1234567890"));
    // matching rule: telephoneNumberSubstringsMatch
    MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry("telephoneNumberSubstringsMatch");
    assertEquals(TelephoneNumberNormalizer.class.getName(), mr2.getNormalizer().getClass().getName());
    assertEquals("+1234567890", mr2.getNormalizer().normalize(" +1 234-567 890 "));
    assertEquals(TelephoneNumberComparator.class.getName(), mr2.getLdapComparator().getClass().getName());
    assertEquals(0, mr2.getLdapComparator().compare(" +1 234-567 890 ", "+1234567890"));
    // test a real attribute: telephoneNumber
    AttributeType at = schemaManager.lookupAttributeTypeRegistry("telephoneNumber");
    assertNotNull(at.getEquality());
    assertEquals(TelephoneNumberNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName());
    assertEquals("+1234567890", at.getEquality().getNormalizer().normalize(" +1 234-567 890 "));
    assertEquals(TelephoneNumberComparator.class.getName(), at.getEquality().getLdapComparator().getClass().getName());
    assertEquals(0, at.getEquality().getLdapComparator().compare(" +1 234-567 890 ", "+1234567890"));
    assertNotNull(at.getSubstring());
    assertEquals(TelephoneNumberNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName());
    assertEquals("+1234567890", at.getSubstring().getNormalizer().normalize(" +1 234-567 890 "));
    assertNull(at.getOrdering());
}
Also used : TelephoneNumberNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.TelephoneNumberNormalizer) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) TelephoneNumberComparator(org.apache.directory.api.ldap.model.schema.comparators.TelephoneNumberComparator) 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