use of org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddNewNormalizer.
// =========================================================================
// MatchingRuleUse addition tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// NameForm addition tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// Normalizer addition tests
// -------------------------------------------------------------------------
@Test
public void testAddNewNormalizer() throws Exception {
SchemaManager schemaManager = loadSystem();
int nrSize = schemaManager.getNormalizerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
String oid = "0.0.0";
Normalizer normalizer = new NoOpNormalizer(oid);
assertTrue(schemaManager.add(normalizer));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(0, errors.size());
assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
Normalizer added = schemaManager.lookupNormalizerRegistry(oid);
assertNotNull(added);
assertEquals(normalizer.getClass().getName(), added.getFqcn());
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAlreadyExistingNormalizer.
@Test
public void testAddAlreadyExistingNormalizer() throws Exception {
SchemaManager schemaManager = loadSystem();
int nrSize = schemaManager.getNormalizerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
String oid = "0.0.0";
Normalizer normalizer = new NoOpNormalizer(oid);
assertTrue(schemaManager.add(normalizer));
Normalizer added = schemaManager.lookupNormalizerRegistry(oid);
assertNotNull(added);
assertEquals(normalizer.getClass().getName(), added.getFqcn());
List<Throwable> errors = schemaManager.getErrors();
assertEquals(0, errors.size());
assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
Normalizer normalizer2 = new NoOpNormalizer(oid);
assertFalse(schemaManager.add(normalizer2));
errors = schemaManager.getErrors();
assertEquals(1, errors.size());
assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
added = schemaManager.lookupNormalizerRegistry(oid);
assertNotNull(added);
assertEquals(normalizer.getClass().getName(), added.getFqcn());
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddNormalizerWithWrongFQCN.
/**
* Test that we can't add two Normalizers with the same class code.
*/
@Test
public void testAddNormalizerWithWrongFQCN() throws Exception {
SchemaManager schemaManager = loadSystem();
int nrSize = schemaManager.getNormalizerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
String oid = "0.0.0";
Normalizer normalizer = new NoOpNormalizer(oid);
// using java.sql.ResultSet cause it is very unlikely to get loaded
// in ADS, as the FQCN is not the one expected
normalizer.setFqcn("java.sql.ResultSet");
assertFalse(schemaManager.add(normalizer));
List<Throwable> errors = schemaManager.getErrors();
errors = schemaManager.getErrors();
assertEquals(1, errors.size());
assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
try {
schemaManager.lookupNormalizerRegistry(oid);
fail();
} catch (Exception e) {
// Expected
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer in project directory-ldap-api by apache.
the class MatchingRuleHelper method addToRegistries.
/**
* Inject the MatchingRule into the Registries, updating the references to
* other SchemaObject
*
* @param matchingRule The MatchingRule to add to the Registries
* @param errors The errors we got while adding the MatchingRule to the registries
* @param registries The Registries
* @throws LdapException If the addition failed
*/
@SuppressWarnings("rawtypes")
public static void addToRegistries(MutableMatchingRule matchingRule, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
matchingRule.unlock();
LdapComparator<?> ldapComparator = null;
Normalizer normalizer = null;
LdapSyntax ldapSyntax = null;
try {
// Gets the associated Comparator
ldapComparator = registries.getComparatorRegistry().lookup(matchingRule.getOid());
} catch (LdapException ne) {
// Default to a catch all comparator
ldapComparator = new ComparableComparator(matchingRule.getOid());
}
try {
// Gets the associated Normalizer
normalizer = registries.getNormalizerRegistry().lookup(matchingRule.getOid());
} catch (LdapException ne) {
// Default to the NoOp normalizer
normalizer = new NoOpNormalizer(matchingRule.getOid());
}
try {
// Get the associated LdapSyntax
ldapSyntax = registries.getLdapSyntaxRegistry().lookup(matchingRule.getSyntaxOid());
} catch (LdapException ne) {
// The Syntax is a mandatory element, it must exist.
String msg = I18n.err(I18n.ERR_13765_MR_MUST_REFER_EXISTING_SYNTAX);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.MR_NONEXISTENT_SYNTAX, msg, ne);
ldapSchemaException.setSourceObject(matchingRule);
ldapSchemaException.setRelatedId(matchingRule.getSyntaxOid());
errors.add(ldapSchemaException);
LOG.info(msg);
}
/**
* Add the MR references (using and usedBy) :
* MR -> C
* MR -> N
* MR -> S
*/
if (ldapComparator != null) {
registries.addReference(matchingRule, ldapComparator);
matchingRule.setLdapComparator(ldapComparator);
}
if (normalizer != null) {
registries.addReference(matchingRule, normalizer);
matchingRule.setNormalizer(normalizer);
}
if (ldapSyntax != null) {
registries.addReference(matchingRule, ldapSyntax);
matchingRule.setSyntax(ldapSyntax);
}
} finally {
matchingRule.lock();
}
}
}
use of org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer in project directory-ldap-api by apache.
the class DefaultAttributeTypeRegistry method addMappingFor.
/**
* {@inheritDoc}
*/
@Override
public void addMappingFor(AttributeType attributeType) throws LdapException {
MatchingRule equality = attributeType.getEquality();
OidNormalizer oidNormalizer;
String oid = attributeType.getOid();
if (equality == null) {
LOG.debug("Attribute {} does not have an EQUALITY MatchingRule : using NoopNormalizer", attributeType.getName());
oidNormalizer = new OidNormalizer(oid, new NoOpNormalizer(attributeType.getOid()));
} else {
oidNormalizer = new OidNormalizer(oid, equality.getNormalizer());
}
oidNormalizerMap.put(oid, oidNormalizer);
// Also inject the attributeType's short names in the map
for (String name : attributeType.getNames()) {
oidNormalizerMap.put(Strings.toLowerCaseAscii(name), oidNormalizer);
}
}
Aggregations