use of org.apache.directory.api.ldap.model.schema.DitContentRule in project directory-ldap-api by apache.
the class DitContentRuleDescriptionSchemaParserTest method testMust.
/**
* Test MUST and its values.
* Very similar to AUX, so here are less test cases.
*
* @throws ParseException
*/
@Test
public void testMust() throws ParseException {
String value = null;
DitContentRule ditContentRule = null;
// no MUST
value = "( 1.1 )";
ditContentRule = parser.parseDITContentRuleDescription(value);
assertEquals(0, ditContentRule.getMustAttributeTypeOids().size());
// MUST simple numericoid
value = "( 1.1 MUST 1.2.3 )";
ditContentRule = parser.parseDITContentRuleDescription(value);
assertEquals(1, ditContentRule.getMustAttributeTypeOids().size());
assertEquals("1.2.3", ditContentRule.getMustAttributeTypeOids().get(0));
// MUST mulitple
value = "(1.1 MUST (cn\rsn $11.22.33.44.55 objectClass\t))";
ditContentRule = parser.parseDITContentRuleDescription(value);
assertEquals(4, ditContentRule.getMustAttributeTypeOids().size());
assertEquals("cn", ditContentRule.getMustAttributeTypeOids().get(0));
assertEquals("sn", ditContentRule.getMustAttributeTypeOids().get(1));
assertEquals("11.22.33.44.55", ditContentRule.getMustAttributeTypeOids().get(2));
assertEquals("objectClass", ditContentRule.getMustAttributeTypeOids().get(3));
// no MUST values
value = "( 1.1 MUST )";
try {
ditContentRule = parser.parseDITContentRuleDescription(value);
fail("Exception expected, no MUST value");
} catch (ParseException pe) {
// expected
}
if (!parser.isQuirksMode()) {
// invalid value
value = "( 1.1 MUST ( c_n ) )";
try {
ditContentRule = parser.parseDITContentRuleDescription(value);
fail("Exception expected, invalid value c_n");
} catch (ParseException pe) {
// expected
}
}
}
use of org.apache.directory.api.ldap.model.schema.DitContentRule in project directory-ldap-api by apache.
the class DitContentRuleDescriptionSchemaParserTest method testFull.
/**
* Test full object class description.
*
* @throws ParseException
*/
@Test
public void testFull() throws ParseException {
String value = null;
DitContentRule ditContentRule = null;
value = "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577' OBSOLETE AUX ( 2.3.4.5.6.7.8.9.0.1 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) MUST ( 3.4.5.6.7.8.9.0.1.2 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) MAY ( 4.5.6.7.8.9.0.1.2.3 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) NOT ( 5.6.7.8.9.0.1.2.3.4 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
ditContentRule = parser.parseDITContentRuleDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", ditContentRule.getOid());
assertEquals(2, ditContentRule.getNames().size());
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditContentRule.getNames().get(0));
assertEquals("test", ditContentRule.getNames().get(1));
assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", ditContentRule.getDescription());
assertTrue(ditContentRule.isObsolete());
assertEquals(2, ditContentRule.getAuxObjectClassOids().size());
assertEquals("2.3.4.5.6.7.8.9.0.1", ditContentRule.getAuxObjectClassOids().get(0));
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditContentRule.getAuxObjectClassOids().get(1));
assertEquals(2, ditContentRule.getMustAttributeTypeOids().size());
assertEquals("3.4.5.6.7.8.9.0.1.2", ditContentRule.getMustAttributeTypeOids().get(0));
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditContentRule.getMustAttributeTypeOids().get(1));
assertEquals(2, ditContentRule.getMayAttributeTypeOids().size());
assertEquals("4.5.6.7.8.9.0.1.2.3", ditContentRule.getMayAttributeTypeOids().get(0));
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditContentRule.getMayAttributeTypeOids().get(1));
assertEquals(2, ditContentRule.getNotAttributeTypeOids().size());
assertEquals("5.6.7.8.9.0.1.2.3.4", ditContentRule.getNotAttributeTypeOids().get(0));
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", ditContentRule.getNotAttributeTypeOids().get(1));
assertEquals(2, ditContentRule.getExtensions().size());
assertNotNull(ditContentRule.getExtension("X-TEST-a"));
assertEquals(2, ditContentRule.getExtension("X-TEST-a").size());
assertEquals("test1-1", ditContentRule.getExtension("X-TEST-a").get(0));
assertEquals("test1-2", ditContentRule.getExtension("X-TEST-a").get(1));
assertNotNull(ditContentRule.getExtension("X-TEST-b"));
assertEquals(2, ditContentRule.getExtension("X-TEST-b").size());
assertEquals("test2-1", ditContentRule.getExtension("X-TEST-b").get(0));
assertEquals("test2-2", ditContentRule.getExtension("X-TEST-b").get(1));
}
use of org.apache.directory.api.ldap.model.schema.DitContentRule in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadDitContentRules.
private void loadDitContentRules(Attribute ditContentRules) throws LdapException {
if (ditContentRules == null) {
return;
}
for (Value value : ditContentRules) {
String desc = value.getValue();
try {
DitContentRule ditContentRule = DCR_DESCR_SCHEMA_PARSER.parseDITContentRuleDescription(desc);
updateSchemas(ditContentRule);
} catch (ParseException pe) {
throw new LdapException(pe);
}
}
}
use of org.apache.directory.api.ldap.model.schema.DitContentRule in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadDitContentRules.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadDitContentRules(Schema... schemas) throws LdapException, IOException {
List<Entry> ditContentRuleEntries = new ArrayList<>();
if (schemas == null) {
return ditContentRuleEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof DitContentRule) {
DitContentRule ditContentRule = (DitContentRule) schemaObject;
Entry ditContentRuleEntry = factory.convert(ditContentRule, schema, null);
ditContentRuleEntries.add(ditContentRuleEntry);
}
}
}
return ditContentRuleEntries;
}
Aggregations