use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method loadNewSchema.
/**
* Test that we can load a new schema
*/
@Test
public void loadNewSchema() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
Schema dummy = new DefaultSchema(loader, "dummy");
assertTrue(schemaManager.load(dummy));
assertTrue(schemaManager.getErrors().isEmpty());
assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
assertEquals(0, schemaManager.getComparatorRegistry().size());
assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
assertEquals(0, schemaManager.getNormalizerRegistry().size());
assertEquals(0, schemaManager.getObjectClassRegistry().size());
assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(0, schemaManager.getGlobalOidRegistry().size());
assertEquals(1, schemaManager.getRegistries().getLoadedSchemas().size());
assertNotNull(schemaManager.getRegistries().getLoadedSchema("dummy"));
}
use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method updateSchemas.
private void updateSchemas(SchemaObject schemaObject) {
String schemaName = schemaObject.getSchemaName();
Schema schema;
if (Strings.isEmpty(schemaName) || "null".equals(schemaName)) {
schemaName = "default";
schema = schemaMap.get(schemaName);
} else {
schema = schemaMap.get(schemaName);
}
if (schema == null) {
schema = new DefaultSchema(this, schemaName);
schemaMap.put(schemaName, schema);
}
schema.getContent().add(new SchemaObjectWrapper(schemaObject));
}
use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method loadNewSchemaBadDependencies.
/**
* Test that we can't load a new schema with bad dependencies
*/
@Test
public void loadNewSchemaBadDependencies() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
Schema dummy = new DefaultSchema(loader, "dummy");
dummy.addDependencies("bad");
assertFalse(schemaManager.load(dummy));
assertFalse(schemaManager.getErrors().isEmpty());
assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
assertEquals(0, schemaManager.getComparatorRegistry().size());
assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
assertEquals(0, schemaManager.getNormalizerRegistry().size());
assertEquals(0, schemaManager.getObjectClassRegistry().size());
assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(0, schemaManager.getGlobalOidRegistry().size());
assertEquals(0, schemaManager.getRegistries().getLoadedSchemas().size());
assertNull(schemaManager.getRegistries().getLoadedSchema("dummy"));
}
use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method testLoadSchemasWithDepsCoreInetOrgPersonAndBad.
// ---------------------------------------------------------------------------
// Test the load( Schema... ) method
// ---------------------------------------------------------------------------
/**
* test loading the "InetOrgPerson", "core" and an empty schema. The empty schema
* should be present in the registries, as it's a vaid schema
*/
@Test
public void testLoadSchemasWithDepsCoreInetOrgPersonAndBad() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
Schema system = loader.getSchema("system");
Schema core = loader.getSchema("core");
Schema empty = new DefaultSchema(loader, "empty");
Schema cosine = loader.getSchema("cosine");
Schema inetOrgPerson = loader.getSchema("InetOrgPerson");
assertTrue(schemaManager.load(system, core, empty, cosine, inetOrgPerson));
assertTrue(schemaManager.getErrors().isEmpty());
assertEquals(142, schemaManager.getAttributeTypeRegistry().size());
assertEquals(36, schemaManager.getComparatorRegistry().size());
assertEquals(42, schemaManager.getMatchingRuleRegistry().size());
assertEquals(35, schemaManager.getNormalizerRegistry().size());
assertEquals(50, schemaManager.getObjectClassRegistry().size());
assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(66, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(300, schemaManager.getGlobalOidRegistry().size());
assertEquals(5, schemaManager.getRegistries().getLoadedSchemas().size());
assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("core"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("empty"));
}
use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.
the class SchemaEntityFactory method getSchema.
/**
* {@inheritDoc}
*/
@Override
public Schema getSchema(Entry entry) throws LdapException {
String name;
String owner;
String[] dependencies = EMPTY_ARRAY;
boolean isDisabled = false;
if (entry == null) {
throw new IllegalArgumentException(I18n.err(I18n.ERR_16016_NULL_ENTRY));
}
if (entry.get(SchemaConstants.CN_AT) == null) {
throw new IllegalArgumentException(I18n.err(I18n.ERR_16017_INVALID_CN_AT));
}
name = entry.get(SchemaConstants.CN_AT).getString();
if (entry.get(SchemaConstants.CREATORS_NAME_AT) == null) {
throw new IllegalArgumentException(I18n.err(I18n.ERR_16018_INVALID_AT, SchemaConstants.CREATORS_NAME_AT));
}
owner = entry.get(SchemaConstants.CREATORS_NAME_AT).getString();
if (entry.get(MetaSchemaConstants.M_DISABLED_AT) != null) {
String value = entry.get(MetaSchemaConstants.M_DISABLED_AT).getString();
value = Strings.upperCase(value);
isDisabled = "TRUE".equalsIgnoreCase(value);
}
if (entry.get(MetaSchemaConstants.M_DEPENDENCIES_AT) != null) {
Set<String> depsSet = new HashSet<>();
Attribute depsAttr = entry.get(MetaSchemaConstants.M_DEPENDENCIES_AT);
for (Value value : depsAttr) {
depsSet.add(value.getValue());
}
dependencies = depsSet.toArray(EMPTY_ARRAY);
}
return new DefaultSchema(null, name, owner, dependencies, isDisabled);
}
Aggregations