use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeSupDifferentUsage.
/**
* Try to inject an AttributeType with a superior and different USAGE
*/
@Test
public void testAddAttributeTypeSupDifferentUsage() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid(null);
attributeType.setOrderingOid(null);
attributeType.setSubstringOid(null);
attributeType.setSuperiorOid("2.5.18.4");
attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithExistingOid.
/**
* Addition of an OC with an existing OID
*/
@Test
public void testAddObjectClassNoSuperiorWithExistingOid() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
ObjectClass objectClass = new ObjectClass("2.5.17.0");
assertFalse(schemaManager.add(objectClass));
assertEquals(1, schemaManager.getErrors().size());
Throwable error = schemaManager.getErrors().get(0);
assertTrue(error instanceof LdapSchemaException);
ObjectClass added = schemaManager.lookupObjectClassRegistry("2.5.17.0");
assertNotNull(added);
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeNoSupCollectiveOperational.
/**
* Try to inject an AttributeType which is Collective, but an operational AT
*/
@Test
public void testAddAttributeTypeNoSupCollectiveOperational() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid("2.5.13.1");
attributeType.setOrderingOid(null);
attributeType.setSubstringOid(null);
attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
attributeType.setUsage(UsageEnum.DIRECTORY_OPERATION);
attributeType.setCollective(true);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeCollectiveOperationalSigleValue.
/**
* Try to inject a single valued AttributeType which is Collective
*/
@Test
public void testAddAttributeTypeCollectiveOperationalSigleValue() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid("2.5.13.1");
attributeType.setOrderingOid(null);
attributeType.setSubstringOid(null);
attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
attributeType.setCollective(true);
attributeType.setSingleValued(true);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaEntityFactory method classLoadSyntaxChecker.
/**
* Class load a syntaxChecker instance
*/
private SyntaxChecker classLoadSyntaxChecker(SchemaManager schemaManager, String oid, String className, Attribute byteCode) throws LdapException {
// Try to class load the syntaxChecker
Class<?> clazz;
SyntaxChecker syntaxChecker;
String byteCodeStr = StringConstants.EMPTY;
if (byteCode == null) {
try {
clazz = Class.forName(className);
} catch (ClassNotFoundException cnfe) {
LOG.error(I18n.err(I18n.ERR_16048_CANNOT_FIND_SC_CTOR, className));
throw new LdapSchemaException(I18n.err(I18n.ERR_16049_CANNOT_FIND_SC_CLASS, cnfe.getMessage()));
}
} else {
classLoader.setAttribute(byteCode);
try {
clazz = classLoader.loadClass(className);
} catch (ClassNotFoundException cnfe) {
LOG.error(I18n.err(I18n.ERR_16050_CANNOT_LOAD_SC_CTOR, className));
throw new LdapSchemaException(I18n.err(I18n.ERR_16051_CANNOT_LOAD_SC_CLASS, cnfe.getMessage()));
}
byteCodeStr = new String(Base64.encode(byteCode.getBytes()));
}
// Create the syntaxChecker instance
try {
Method builder = clazz.getMethod("builder", null);
syntaxChecker = (SyntaxChecker) ((SCBuilder) builder.invoke(null, null)).setOid(oid).build();
} catch (NoSuchMethodException nsme) {
LOG.error(I18n.err(I18n.ERR_16052_CANNOT_INST_SC_CTOR, className));
throw new LdapSchemaException(I18n.err(I18n.ERR_16053_CANNOT_INST_SC_CLASS, nsme.getMessage()));
} catch (InvocationTargetException | IllegalAccessException e) {
LOG.error(I18n.err(I18n.ERR_16054_CANNOT_ACCESS_SC_CTOR, className));
throw new LdapSchemaException(I18n.err(I18n.ERR_16055_CANNOT_ACCESS_SC_CLASS, e.getMessage()));
}
// Update the common fields
syntaxChecker.setBytecode(byteCodeStr);
syntaxChecker.setFqcn(className);
// Inject the SchemaManager for the comparator who needs it
syntaxChecker.setSchemaManager(schemaManager);
return syntaxChecker;
}
Aggregations