use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testParseOpenLdapInetOrgPersonSchema.
@Test
public void testParseOpenLdapInetOrgPersonSchema() throws Exception {
InputStream input = getClass().getResourceAsStream("inetorgperson.schema");
parser.parse(input);
List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
assertEquals(9, attributeTypes.size());
assertEquals(1, objectClassTypes.size());
assertEquals(0, objectIdentifierMacros.size());
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class LdapNetworkConnection method addSchema.
/**
* parses the given schema file present in OpenLDAP schema format
* and adds all the SchemaObjects present in it to the SchemaManager
*
* @param schemaFile the schema file in OpenLDAP schema format
* @throws LdapException in case of any errors while parsing
*/
public void addSchema(File schemaFile) throws LdapException {
try {
if (schemaManager == null) {
loadSchema();
}
if (schemaManager == null) {
throw new LdapException("Cannot load the schema");
}
OpenLdapSchemaParser olsp = new OpenLdapSchemaParser();
olsp.setQuirksMode(true);
olsp.parse(schemaFile);
Registries registries = schemaManager.getRegistries();
List<Throwable> errors = new ArrayList<>();
for (AttributeType atType : olsp.getAttributeTypes()) {
registries.buildReference(errors, atType);
registries.getAttributeTypeRegistry().register(atType);
}
for (ObjectClass oc : olsp.getObjectClassTypes()) {
registries.buildReference(errors, oc);
registries.getObjectClassRegistry().register(oc);
}
LOG.info("successfully loaded the schema from file {}", schemaFile.getAbsolutePath());
} catch (Exception e) {
LOG.error(I18n.err(I18n.ERR_03206_FAIL_LOAD_SCHEMA_FILE, schemaFile.getAbsolutePath()));
throw new LdapException(e);
}
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithExistingOCName.
/**
* Addition of an OC with an existing OC name
*/
@Test
public void testAddObjectClassNoSuperiorWithExistingOCName() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
ObjectClass objectClass = new ObjectClass("1.1.0");
objectClass.setNames("Test", "referral");
assertFalse(schemaManager.add(objectClass));
assertEquals(1, schemaManager.getErrors().size());
Throwable error = schemaManager.getErrors().get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.0"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithATName.
/**
* Addition of an OC with an AT name
*/
@Test
public void testAddObjectClassNoSuperiorWithATName() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
ObjectClass objectClass = new ObjectClass("1.1.1");
objectClass.setNames("Test", "cn");
assertTrue(schemaManager.add(objectClass));
assertEquals(0, schemaManager.getErrors().size());
ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
assertNotNull(added);
assertTrue(added.getNames().contains("Test"));
assertTrue(added.getNames().contains("cn"));
assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsValid.
// -------------------------------------------------------------------------
// Then, with superiors
// -------------------------------------------------------------------------
/**
* Addition of a valid OC with some superiors
*/
@Test
public void testAddObjectClassSuperiorsValid() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.STRUCTURAL);
objectClass.addSuperiorOids("alias", "referral", "top");
assertTrue(schemaManager.add(objectClass));
assertEquals(0, schemaManager.getErrors().size());
ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
assertNotNull(added);
assertTrue(added.getNames().contains("Test"));
assertNotNull(added.getSuperiors());
assertEquals(3, added.getSuperiors().size());
Set<String> expectedSups = new HashSet<String>();
expectedSups.add("alias");
expectedSups.add("referral");
expectedSups.add("top");
for (ObjectClass addedOC : added.getSuperiors()) {
assertTrue(expectedSups.contains(addedOC.getName()));
expectedSups.remove(addedOC.getName());
}
assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Aggregations