use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class DitStructureRuleDescriptionSchemaParserTest method testFull.
/**
* Test full object class description.
*
* @throws ParseException
*/
@Test
public void testFull() throws ParseException {
String value = null;
DitStructureRule ditStructureRule = null;
value = "( 1234567890 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577' OBSOLETE FORM 2.3.4.5.6.7.8.9.0.1 SUP ( 1 1234567890 5 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals(1234567890, ditStructureRule.getRuleId());
assertEquals(2, ditStructureRule.getNames().size());
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditStructureRule.getNames().get(0));
assertEquals("test", ditStructureRule.getNames().get(1));
assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", ditStructureRule.getDescription());
assertTrue(ditStructureRule.isObsolete());
assertEquals("2.3.4.5.6.7.8.9.0.1", ditStructureRule.getForm());
assertEquals(3, ditStructureRule.getSuperRules().size());
assertEquals(Integer.valueOf(1), ditStructureRule.getSuperRules().get(0));
assertEquals(Integer.valueOf(1234567890), ditStructureRule.getSuperRules().get(1));
assertEquals(Integer.valueOf(5), ditStructureRule.getSuperRules().get(2));
assertEquals(2, ditStructureRule.getExtensions().size());
assertNotNull(ditStructureRule.getExtension("X-TEST-a"));
assertEquals(2, ditStructureRule.getExtension("X-TEST-a").size());
assertEquals("test1-1", ditStructureRule.getExtension("X-TEST-a").get(0));
assertEquals("test1-2", ditStructureRule.getExtension("X-TEST-a").get(1));
assertNotNull(ditStructureRule.getExtension("X-TEST-b"));
assertEquals(2, ditStructureRule.getExtension("X-TEST-b").size());
assertEquals("test2-1", ditStructureRule.getExtension("X-TEST-b").get(0));
assertEquals("test2-2", ditStructureRule.getExtension("X-TEST-b").get(1));
}
use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class DitStructureRuleDescriptionSchemaParserTest method testRequiredElements.
/**
* Test required elements.
*
* @throws ParseException
*/
@Test
public void testRequiredElements() throws ParseException {
String value = null;
DitStructureRule ditStructureRule = null;
value = "( 1 FORM 1.1 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertNotNull(ditStructureRule.getForm());
value = "( 1 )";
try {
parser.parseDITStructureRuleDescription(value);
fail("Exception expected, FORM is required");
} catch (ParseException pe) {
// expected
}
}
use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class Registries method clone.
/**
* Clone the Registries. This is done in two steps :
* - first clone the SchemaObjetc registries
* - second restore the relation between them
*/
// False positive
@Override
public Registries clone() throws CloneNotSupportedException {
// First clone the structure
Registries clone = (Registries) super.clone();
// Now, clone the oidRegistry
clone.globalOidRegistry = globalOidRegistry.copy();
// We have to clone every SchemaObject registries now
clone.attributeTypeRegistry = attributeTypeRegistry.copy();
clone.comparatorRegistry = comparatorRegistry.copy();
clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
clone.matchingRuleRegistry = matchingRuleRegistry.copy();
clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
clone.nameFormRegistry = nameFormRegistry.copy();
clone.normalizerRegistry = normalizerRegistry.copy();
clone.objectClassRegistry = objectClassRegistry.copy();
clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
// Store all the SchemaObjects into the globalOid registry
for (AttributeType attributeType : clone.attributeTypeRegistry) {
clone.globalOidRegistry.put(attributeType);
}
for (DitContentRule ditContentRule : clone.ditContentRuleRegistry) {
clone.globalOidRegistry.put(ditContentRule);
}
for (DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry) {
clone.globalOidRegistry.put(ditStructureRule);
}
for (MatchingRule matchingRule : clone.matchingRuleRegistry) {
clone.globalOidRegistry.put(matchingRule);
}
for (MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry) {
clone.globalOidRegistry.put(matchingRuleUse);
}
for (NameForm nameForm : clone.nameFormRegistry) {
clone.globalOidRegistry.put(nameForm);
}
for (ObjectClass objectClass : clone.objectClassRegistry) {
clone.globalOidRegistry.put(objectClass);
}
for (LdapSyntax syntax : clone.ldapSyntaxRegistry) {
clone.globalOidRegistry.put(syntax);
}
// Clone the schema list
clone.loadedSchemas = new HashMap<>();
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
// We don't clone the schemas
clone.loadedSchemas.put(entry.getKey(), loadedSchemas.get(entry.getKey()));
}
// Clone the Using and usedBy structures
// They will be empty
clone.using = new HashMap<>();
clone.usedBy = new HashMap<>();
// Last, rebuild the using and usedBy references
clone.buildReferences();
// Now, check the registries. We don't care about errors
clone.checkRefInteg();
clone.schemaObjects = new HashMap<>();
// SchemaObjects
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
Set<SchemaObjectWrapper> objects = new HashSet<>();
for (SchemaObjectWrapper schemaObjectWrapper : entry.getValue()) {
SchemaObject original = schemaObjectWrapper.get();
try {
if (!(original instanceof LoadableSchemaObject)) {
SchemaObject copy = clone.globalOidRegistry.getSchemaObject(original.getOid());
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(copy);
objects.add(newWrapper);
} else {
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(original);
objects.add(newWrapper);
}
} catch (LdapException ne) {
// Nothing to do
}
}
clone.schemaObjects.put(entry.getKey(), objects);
}
return clone;
}
use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class DefaultDitStructureRuleRegistry method unregisterSchemaElements.
/**
* {@inheritDoc}
*/
@Override
public void unregisterSchemaElements(String schemaName) {
if (schemaName == null) {
return;
}
// with the give schemaName
for (DitStructureRule ditStructureRule : this) {
if (schemaName.equalsIgnoreCase(ditStructureRule.getSchemaName())) {
int ruleId = ditStructureRule.getRuleId();
SchemaObject removed = byRuleId.remove(ruleId);
if (DEBUG) {
LOG.debug("Removed {} with ruleId {} from the registry", removed, ruleId);
}
}
}
}
use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class DitStructureRuleDescriptionSchemaParserTest method testNumericRuleId.
/**
* Test ruleid
*
* @throws ParseException
*/
@Test
public void testNumericRuleId() throws ParseException {
String value = null;
DitStructureRule ditStructureRule = null;
// null test
value = null;
try {
parser.parseDITStructureRuleDescription(value);
fail("Exception expected, null");
} catch (ParseException pe) {
// expected
}
// no ruleid
value = "( )";
try {
parser.parseDITStructureRuleDescription(value);
fail("Exception expected, no ruleid");
} catch (ParseException pe) {
// expected
}
// simple
value = "( 1 FORM 1.1 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals(1, ditStructureRule.getRuleId());
// simple
value = "( 1234567890 FORM 1.1 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals(1234567890, ditStructureRule.getRuleId());
// simple with spaces
value = "( 1234567890 FORM 1.1 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals(1234567890, ditStructureRule.getRuleId());
// non-numeric not allowed
value = "( test FORM 1.1 )";
try {
parser.parseDITStructureRuleDescription(value);
fail("Exception expected, invalid ruleid test (non-numeric)");
} catch (ParseException pe) {
// expected
}
// oid not allowed
value = "( 1.2.3.4 FORM 1.1 )";
try {
parser.parseDITStructureRuleDescription(value);
fail("Exception expected, invalid ruleid 1.2.3.4 (oid)");
} catch (ParseException pe) {
// expected
}
// quotes not allowed
value = "( '1234567890' FORM 1.1 )";
try {
parser.parse(value);
fail("Exception expected, invalid ruleid '1234567890' (quoted)");
} catch (ParseException pe) {
// expected
}
}
Aggregations