Search in sources :

Example 6 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class NameFormDescriptionSchemaParserTest method testFull.

/**
 * Test full object class description.
 *
 * @throws ParseException
 */
@Test
public void testFull() throws ParseException, LdapException {
    String value = null;
    NameForm nf = 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 OC bcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789a MUST ( 3.4.5.6.7.8.9.0.1.2 $ cdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789ab ) MAY ( 4.5.6.7.8.9.0.1.2.3 $ defghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789abc ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
    nf = parser.parseNameFormDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", nf.getOid());
    assertEquals(2, nf.getNames().size());
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", nf.getNames().get(0));
    assertEquals("test", nf.getNames().get(1));
    assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", nf.getDescription());
    assertTrue(nf.isObsolete());
    assertEquals("bcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789a", nf.getStructuralObjectClassOid());
    assertEquals(2, nf.getMustAttributeTypeOids().size());
    assertEquals("3.4.5.6.7.8.9.0.1.2", nf.getMustAttributeTypeOids().get(0));
    assertEquals("cdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789ab", nf.getMustAttributeTypeOids().get(1));
    assertEquals(2, nf.getMayAttributeTypeOids().size());
    assertEquals("4.5.6.7.8.9.0.1.2.3", nf.getMayAttributeTypeOids().get(0));
    assertEquals("defghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789abc", nf.getMayAttributeTypeOids().get(1));
    assertEquals(2, nf.getExtensions().size());
    assertNotNull(nf.getExtension("X-TEST-a"));
    assertEquals(2, nf.getExtension("X-TEST-a").size());
    assertEquals("test1-1", nf.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", nf.getExtension("X-TEST-a").get(1));
    assertNotNull(nf.getExtension("X-TEST-b"));
    assertEquals(2, nf.getExtension("X-TEST-b").size());
    assertEquals("test2-1", nf.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", nf.getExtension("X-TEST-b").get(1));
}
Also used : NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Test(org.junit.Test)

Example 7 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm 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;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) HashSet(java.util.HashSet) Set(java.util.Set) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) HashMap(java.util.HashMap) Map(java.util.Map) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet)

Example 8 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class NameFormDescriptionSchemaParserTest method testMust.

/**
 * Test MUST and its values.
 *
 * @throws ParseException
 */
@Test
public void testMust() throws ParseException, LdapException {
    String value = null;
    NameForm nf = null;
    // MUST simple numericoid
    value = "( 1.1 OC o MUST 1.2.3 )";
    nf = parser.parseNameFormDescription(value);
    assertEquals(1, nf.getMustAttributeTypeOids().size());
    assertEquals("1.2.3", nf.getMustAttributeTypeOids().get(0));
    // MUST mulitple
    value = "(1.1 OC o MUST (cn$sn       $11.22.33.44.55         $  objectClass   ))";
    nf = parser.parseNameFormDescription(value);
    assertEquals(4, nf.getMustAttributeTypeOids().size());
    assertEquals("cn", nf.getMustAttributeTypeOids().get(0));
    assertEquals("sn", nf.getMustAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", nf.getMustAttributeTypeOids().get(2));
    assertEquals("objectClass", nf.getMustAttributeTypeOids().get(3));
    // no MUST values
    value = "( 1.1 OC o MUST )";
    try {
        nf = parser.parseNameFormDescription(value);
        fail("Exception expected, no MUST value");
    } catch (ParseException pe) {
    // expected
    }
    // MUST must only appear once
    value = "( 1.1 OC o MUST test1 MUST test2 )";
    try {
        nf = parser.parseNameFormDescription(value);
        fail("Exception expected, MUST appears twice");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // MUST is required
        value = "( 1.1 OC o )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, MUST is required");
        } catch (ParseException pe) {
        // expected
        }
        // invalid value
        value = "( 1.1 OC o MUST ( c_n ) )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, invalid value c_n");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : NameForm(org.apache.directory.api.ldap.model.schema.NameForm) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 9 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class NameFormDescriptionSchemaParserTest method testRequiredElements.

/**
 * Test required elements.
 *
 * @throws ParseException
 */
@Test
public void testRequiredElements() throws ParseException, LdapException {
    String value = null;
    NameForm nf = null;
    value = "( 1.2.3.4.5.6.7.8.9.0 OC o MUST m )";
    nf = parser.parseNameFormDescription(value);
    assertNotNull(nf.getStructuralObjectClassOid());
    assertEquals(1, nf.getMustAttributeTypeOids().size());
    if (!parser.isQuirksMode()) {
        value = "( 1.2.3.4.5.6.7.8.9.0 MUST m )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, OC is required");
        } catch (ParseException pe) {
        // expected
        }
        value = "( 1.2.3.4.5.6.7.8.9.0 OC o )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, MUST is required");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : NameForm(org.apache.directory.api.ldap.model.schema.NameForm) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

NameForm (org.apache.directory.api.ldap.model.schema.NameForm)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 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)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 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