Search in sources :

Example 6 with DitContentRule

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
        }
    }
}
Also used : DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 7 with DitContentRule

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));
}
Also used : DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) Test(org.junit.Test)

Example 8 with DitContentRule

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);
        }
    }
}
Also used : Value(org.apache.directory.api.ldap.model.entry.Value) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 9 with DitContentRule

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;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule)

Aggregations

DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)9 ParseException (java.text.ParseException)5 Test (org.junit.Test)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 NameForm (org.apache.directory.api.ldap.model.schema.NameForm)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1