Search in sources :

Example 21 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testMicrosoftAds2000Locality.

@Test
public void testMicrosoftAds2000Locality() throws ParseException, NamingException {
    String value = "( 2.5.6.3 NAME 'locality' SUP top STRUCTURAL MUST (l ) MAY (st $ street $ searchGuide $ seeAlso ) )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("2.5.6.3", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("locality", objectClass.getNames().get(0));
    assertNull(objectClass.getDescription());
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("top", objectClass.getSuperiorOids().get(0));
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("l", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals(4, objectClass.getMayAttributeTypeOids().size());
    assertEquals("st", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("street", objectClass.getMayAttributeTypeOids().get(1));
    assertEquals("searchGuide", objectClass.getMayAttributeTypeOids().get(2));
    assertEquals("seeAlso", objectClass.getMayAttributeTypeOids().get(3));
    assertEquals(0, objectClass.getExtensions().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 22 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testKind.

/**
 * Tests kind (ABSTRACT, AUXILIARY, STRUCTURAL)
 *
 * @throws ParseException
 */
@Test
public void testKind() throws ParseException {
    String value = null;
    ObjectClass objectClass = null;
    // DEFAULT is STRUCTURAL
    value = "( 1.1 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    // ABSTRACT
    value = "( 1.1 ABSTRACT )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(ObjectClassTypeEnum.ABSTRACT, objectClass.getType());
    // AUXILIARY, tab
    value = "\t(\t1.1\tAUXILIARY\t)\t";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(ObjectClassTypeEnum.AUXILIARY, objectClass.getType());
    // STRUCTURAL, no space
    value = "(1.1 STRUCTURAL)";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    // STRUCTURAL, case-insensitive
    value = "(1.1 sTrUcTuRaL )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    // invalid
    value = "( 1.1 FOO )";
    try {
        objectClass = parser.parseObjectClassDescription(value);
        fail("Exception expected, invalid KIND value");
    } catch (ParseException pe) {
    // expected
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 23 with ObjectClass

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

the class OpenLdapSchemaParserTest method testParseOpenLdapCollectiveSchema.

@Test
public void testParseOpenLdapCollectiveSchema() throws Exception {
    InputStream input = getClass().getResourceAsStream("collective.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(13, attributeTypes.size());
    assertEquals(0, objectClassTypes.size());
    assertEquals(0, objectIdentifierMacros.size());
    for (AttributeType attributeTypeLiteral : attributeTypes) {
        assertTrue(attributeTypeLiteral.isCollective());
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) OpenLdapObjectIdentifierMacro(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro) InputStream(java.io.InputStream) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 24 with ObjectClass

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

the class OpenLdapSchemaParserTest method testObjectClassWithExtensionsParse.

@Test
public void testObjectClassWithExtensionsParse() throws Exception {
    String objectClassData = "objectclass ( 2.5.6.6 NAME 'person'\n" + "        DESC 'RFC2256: a person'\n" + "        SUP top STRUCTURAL\n" + "        MUST ( sn $ cn )\n" + "        MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) \n" + "        X-extension 'test' X-otherExtension ( 'test1' 'test2' ) )";
    parser.parse(objectClassData);
    List<ObjectClass> objectClassesList = parser.getObjectClassTypes();
    Map<String, ObjectClass> objectClasses = mapObjectClasses(objectClassesList);
    ObjectClass objectClass = objectClasses.get("2.5.6.6");
    assertNotNull(objectClass);
    assertEquals("2.5.6.6", objectClass.getOid());
    assertEquals("person", objectClass.getName());
    assertEquals("RFC2256: a person", objectClass.getDescription());
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    assertEquals("sn", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals("cn", objectClass.getMustAttributeTypeOids().get(1));
    assertEquals("userPassword", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("telephoneNumber", objectClass.getMayAttributeTypeOids().get(1));
    assertEquals("seeAlso", objectClass.getMayAttributeTypeOids().get(2));
    assertEquals("description", objectClass.getMayAttributeTypeOids().get(3));
    Map<String, List<String>> extensions = objectClass.getExtensions();
    assertNotNull(extensions);
    List<String> ext1 = objectClass.getExtension("X-extension");
    assertNotNull(ext1);
    assertEquals(1, ext1.size());
    assertTrue(ext1.contains("test"));
    List<String> ext2 = objectClass.getExtension("X-otherExtension");
    assertNotNull(ext2);
    assertEquals(2, ext2.size());
    assertTrue(ext2.contains("test1"));
    assertTrue(ext2.contains("test2"));
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) List(java.util.List) Test(org.junit.Test)

Example 25 with ObjectClass

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

the class OpenLdapSchemaParserTest method testObjectClassParse.

@Test
public void testObjectClassParse() throws Exception {
    String objectClassData = "objectclass ( 2.5.6.6 NAME 'person'\n" + "        DESC 'RFC2256: a person'\n" + "        SUP top STRUCTURAL\n" + "        MUST ( sn $ cn )\n" + "        MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) )";
    parser.parse(objectClassData);
    List<ObjectClass> objectClassesList = parser.getObjectClassTypes();
    Map<String, ObjectClass> objectClasses = mapObjectClasses(objectClassesList);
    ObjectClass objectClass = objectClasses.get("2.5.6.6");
    assertNotNull(objectClass);
    assertEquals("2.5.6.6", objectClass.getOid());
    assertEquals("person", objectClass.getName());
    assertEquals("RFC2256: a person", objectClass.getDescription());
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    assertEquals("sn", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals("cn", objectClass.getMustAttributeTypeOids().get(1));
    assertEquals("userPassword", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("telephoneNumber", objectClass.getMayAttributeTypeOids().get(1));
    assertEquals("seeAlso", objectClass.getMayAttributeTypeOids().get(2));
    assertEquals("description", objectClass.getMayAttributeTypeOids().get(3));
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Aggregations

ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)53 Test (org.junit.Test)34 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)10 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)9 MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)6 ParseException (java.text.ParseException)5 HashSet (java.util.HashSet)5 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 LdapNoSuchAttributeException (org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)3 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)3 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2