use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddMatchingRuleExistingATName.
/**
* Try to inject a new MatchingRule with an existing AT name
*/
@Test
public void testAddMatchingRuleExistingATName() throws Exception {
SchemaManager schemaManager = loadSystem();
int mrrSize = schemaManager.getMatchingRuleRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.0");
matchingRule.setNames("Test", "cn");
matchingRule.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
// It should not fail
assertTrue(schemaManager.add(matchingRule));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(0, errors.size());
// Check that the new MR has been injected
assertTrue(isMRPresent(schemaManager, "1.1.0"));
MatchingRule added = schemaManager.lookupMatchingRuleRegistry("1.1.0");
assertTrue(added.getNames().contains("cn"));
assertTrue(added.getNames().contains("Test"));
assertEquals(mrrSize + 1, schemaManager.getMatchingRuleRegistry().size());
assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddMatchingRuleExistingOID.
/**
* Try to inject a new MatchingRule with an existing OID
*/
@Test
public void testAddMatchingRuleExistingOID() throws Exception {
SchemaManager schemaManager = loadSystem();
int mrrSize = schemaManager.getMatchingRuleRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableMatchingRule matchingRule = new MutableMatchingRule("2.5.13.0");
matchingRule.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
// It should fail (oid already registered)
assertFalse(schemaManager.add(matchingRule));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
// Check that the existing MR has not been replaced
assertTrue(isMRPresent(schemaManager, "2.5.13.0"));
MatchingRule existing = schemaManager.lookupMatchingRuleRegistry("2.5.13.0");
assertEquals("objectIdentifierMatch", existing.getName());
assertEquals(mrrSize, schemaManager.getMatchingRuleRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class TestEntryUtils method getCaseIgnoringAttributeNoNumbersType.
/* no protection*/
static AttributeType getCaseIgnoringAttributeNoNumbersType() {
MutableAttributeType attributeType = new MutableAttributeType("1.1.3.1");
LdapSyntax syntax = new LdapSyntax("1.1.1.1", "", true);
syntax.setSyntaxChecker(new SyntaxChecker("1.1.2.1") {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
if (!(value instanceof String)) {
return false;
}
String strval = (String) value;
for (char c : strval.toCharArray()) {
if (Character.isDigit(c)) {
return false;
}
}
return true;
}
});
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2.1");
matchingRule.setSyntax(syntax);
matchingRule.setLdapComparator(new LdapComparator<String>(matchingRule.getOid()) {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public int compare(String o1, String o2) {
return (o1 == null ? (o2 == null ? 0 : -1) : (o2 == null ? 1 : o1.compareTo(o2)));
}
});
Normalizer normalizer = new Normalizer("1.1.1") {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public String normalize(String value) throws LdapException {
return normalize(value, AssertionType.ATTRIBUTE_VALUE);
}
public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
return Strings.toLowerCaseAscii(value);
}
};
matchingRule.setNormalizer(normalizer);
attributeType.setEquality(matchingRule);
attributeType.setSyntax(syntax);
return attributeType;
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class EntryUtils method getIA5StringAttributeType.
/* no protection*/
static AttributeType getIA5StringAttributeType() {
MutableAttributeType attributeType = new MutableAttributeType("1.1");
attributeType.addName("1.1");
LdapSyntax syntax = new LdapSyntax("1.1.1", "", true);
syntax.setSyntaxChecker(new SyntaxChecker("1.1.2") {
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
String strValue = Strings.deepTrim((String) value);
return (strValue == null) || (strValue.length() < 7);
}
});
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2");
matchingRule.setSyntax(syntax);
matchingRule.setLdapComparator(new LdapComparator<String>(matchingRule.getOid()) {
public static final long serialVersionUID = 1L;
public int compare(String o1, String o2) {
return ((o1 == null) ? (o2 == null ? 0 : -1) : (o2 == null ? 1 : o1.compareTo(o2)));
}
});
matchingRule.setNormalizer(new DeepTrimToLowerNormalizer(matchingRule.getOid()));
attributeType.setEquality(matchingRule);
attributeType.setSyntax(syntax);
return attributeType;
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class SchemaUtilsTest method getMatchingRules.
public static MatchingRule[] getMatchingRules() {
MutableMatchingRule[] mrs = new MutableMatchingRule[3];
mrs[0] = new MutableMatchingRule("2.5.13.2");
mrs[0].setSyntax(getSyntaxes()[1]);
mrs[0].addName("caseIgnoreMatch");
mrs[0].setDescription("Ignores case in strings");
mrs[1] = new MutableMatchingRule("2.5.13.4");
mrs[0].setSyntax(getSyntaxes()[2]);
mrs[1].addName("caseIgnoreSubstringsMatch");
mrs[1].setDescription("Ignores case in substrings");
mrs[2] = new MutableMatchingRule("2.5.13.1");
mrs[0].setSyntax(getSyntaxes()[0]);
mrs[2].addName("distinguishedNameMatch");
mrs[2].setDescription("distinguishedNameMatch");
return mrs;
}
Aggregations