use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAlreadyExistingSyntaxChecker.
@Test
public void testAddAlreadyExistingSyntaxChecker() throws Exception {
SchemaManager schemaManager = loadSystem();
int nrSize = schemaManager.getSyntaxCheckerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
String oid = "0.0.0";
SyntaxChecker syntaxChecker = RegexSyntaxChecker.builder().setOid(oid).build();
assertTrue(schemaManager.add(syntaxChecker));
SyntaxChecker added = schemaManager.lookupSyntaxCheckerRegistry(oid);
assertNotNull(added);
assertEquals(syntaxChecker.getClass().getName(), added.getFqcn());
List<Throwable> errors = schemaManager.getErrors();
assertEquals(0, errors.size());
assertEquals(nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
SyntaxChecker syntaxChecker2 = RegexSyntaxChecker.builder().setOid(oid).build();
assertFalse(schemaManager.add(syntaxChecker2));
errors = schemaManager.getErrors();
assertEquals(1, errors.size());
assertEquals(nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
added = schemaManager.lookupSyntaxCheckerRegistry(oid);
assertNotNull(added);
assertEquals(syntaxChecker.getClass().getName(), added.getFqcn());
}
use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class SchemaManagerDelTest method testDeleteNonExistingSyntaxChecker.
@Test
public void testDeleteNonExistingSyntaxChecker() throws Exception {
SchemaManager schemaManager = loadSchema("system");
int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
SyntaxChecker sc = BooleanSyntaxChecker.builder().setOid("0.0").build();
assertFalse(schemaManager.delete(sc));
List<Throwable> errors = schemaManager.getErrors();
assertFalse(errors.isEmpty());
assertEquals(scrSize, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class SchemaManagerDelTest method testDeleteExistingSyntaxChecker.
// =========================================================================
// SyntaxChecker deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingSyntaxChecker() throws Exception {
SchemaManager schemaManager = loadSchema("system");
int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
SyntaxChecker sc = BooleanSyntaxChecker.builder().setOid("0.1.1").build();
assertTrue(schemaManager.add(sc));
assertEquals(scrSize + 1, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
sc = schemaManager.lookupSyntaxCheckerRegistry("0.1.1");
assertNotNull(sc);
assertTrue(schemaManager.delete(sc));
try {
schemaManager.lookupSyntaxCheckerRegistry("0.1.1");
fail();
} catch (Exception e) {
// expected
}
assertEquals(scrSize, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class SchemaEntityFactory method getSyntaxChecker.
/**
* {@inheritDoc}
*/
@Override
public SyntaxChecker getSyntaxChecker(SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription, Registries targetRegistries, String schemaName) throws LdapException {
checkDescription(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// The Comparator OID
String oid = getOid(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// Get the schema
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is not loaded. We can't create the requested SyntaxChecker
String msg = I18n.err(I18n.ERR_16019_CANNOT_ADD_SC, syntaxCheckerDescription.getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
// The FQCN
String fqcn = getFqcn(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// get the byteCode
Attribute byteCode = getByteCode(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// Class load the SyntaxChecker
SyntaxChecker syntaxChecker = classLoadSyntaxChecker(schemaManager, oid, fqcn, byteCode);
// Update the common fields
setSchemaObjectProperties(syntaxChecker, syntaxCheckerDescription, schema);
return syntaxChecker;
}
use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class DefaultSchemaManager method addSyntaxCheckers.
/**
*Add
* Register all the Schema's SyntaxCheckers
*/
private void addSyntaxCheckers(Schema schema, Registries registries) throws LdapException, IOException {
if (schema.getSchemaLoader() == null) {
return;
}
for (Entry entry : schema.getSchemaLoader().loadSyntaxCheckers(schema)) {
SyntaxChecker syntaxChecker = factory.getSyntaxChecker(this, entry, registries, schema.getSchemaName());
addSchemaObject(registries, syntaxChecker, schema);
}
}
Aggregations