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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations