use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class DitStructureRuleDescriptionSchemaParserTest method testForm.
/**
* Tests FORM
*
* @throws ParseException
*/
@Test
public void testForm() throws ParseException {
String value = null;
DitStructureRule ditStructureRule = null;
// numeric oid
value = "( 1 FORM 1.2.3.4.5.6.7.8.9.0 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", ditStructureRule.getForm());
// numeric oid
value = "( 1 FORM 123.4567.890 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("123.4567.890", ditStructureRule.getForm());
// descr
value = "( 1 FORM abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditStructureRule.getForm());
// descr, no space
value = "(1 FORMabc)";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("abc", ditStructureRule.getForm());
// descr, tab
value = "\t(\t1\tFORM\tabc\t)\t";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("abc", ditStructureRule.getForm());
// quoted value
value = "( 1 FORM '1.2.3.4.5.6.7.8.9.0' )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", ditStructureRule.getForm());
// no quote allowed
value = "( 1 FORM ('test') )";
ditStructureRule = parser.parseDITStructureRuleDescription(value);
assertEquals("test", ditStructureRule.getForm());
// invalid character
value = "( 1 FORM 1.2.3.4.A )";
try {
ditStructureRule = parser.parseDITStructureRuleDescription(value);
fail("Exception expected, invalid FORM 1.2.3.4.A (invalid character)");
} catch (ParseException pe) {
// expected
}
// no multiple values
value = "( 1 FORM ( test1 test2 ) )";
try {
ditStructureRule = parser.parseDITStructureRuleDescription(value);
fail("Exception expected, FORM must be single valued");
} catch (ParseException pe) {
// expected
}
if (!parser.isQuirksMode()) {
// invalid start
value = "( 1 FORM -test ) )";
try {
ditStructureRule = parser.parseDITStructureRuleDescription(value);
fail("Exception expected, invalid FORM '-test' (starts with hypen)");
} catch (ParseException pe) {
// expected
}
}
}
use of org.apache.directory.api.ldap.model.schema.DitStructureRule in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadDitStructureRules.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadDitStructureRules(Schema... schemas) throws LdapException, IOException {
List<Entry> ditStructureRuleEntries = new ArrayList<>();
if (schemas == null) {
return ditStructureRuleEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof DitStructureRule) {
DitStructureRule ditStructureRule = (DitStructureRule) schemaObject;
Entry ditStructureRuleEntry = factory.convert(ditStructureRule, schema, null);
ditStructureRuleEntries.add(ditStructureRuleEntry);
}
}
}
return ditStructureRuleEntries;
}
Aggregations