Search in sources :

Example 36 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testRfcSimpleSecurityObject.

@Test
public void testRfcSimpleSecurityObject() throws ParseException, NamingException {
    String value = "( 0.9.2342.19200300.100.4.19 NAME 'simpleSecurityObject' DESC 'RFC1274: simple security object' SUP top AUXILIARY MUST userPassword )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("0.9.2342.19200300.100.4.19", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("simpleSecurityObject", objectClass.getNames().get(0));
    assertEquals("RFC1274: simple security object", objectClass.getDescription());
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("top", objectClass.getSuperiorOids().get(0));
    assertEquals(ObjectClassTypeEnum.AUXILIARY, objectClass.getType());
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("userPassword", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals(0, objectClass.getMayAttributeTypeOids().size());
    assertEquals(0, objectClass.getExtensions().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 37 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testFull.

/**
 * Test full object class description.
 *
 * @throws ParseException
 */
@Test
public void testFull() throws ParseException, NamingException {
    String value = null;
    ObjectClass objectClass = 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 SUP ( 2.3.4.5.6.7.8.9.0.1 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) STRUCTURAL 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 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", objectClass.getOid());
    assertEquals(2, objectClass.getNames().size());
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", objectClass.getNames().get(0));
    assertEquals("test", objectClass.getNames().get(1));
    assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", objectClass.getDescription());
    assertTrue(objectClass.isObsolete());
    assertEquals(2, objectClass.getSuperiorOids().size());
    assertEquals("2.3.4.5.6.7.8.9.0.1", objectClass.getSuperiorOids().get(0));
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", objectClass.getSuperiorOids().get(1));
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    assertEquals(2, objectClass.getMustAttributeTypeOids().size());
    assertEquals("3.4.5.6.7.8.9.0.1.2", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", objectClass.getMustAttributeTypeOids().get(1));
    assertEquals(2, objectClass.getMayAttributeTypeOids().size());
    assertEquals("4.5.6.7.8.9.0.1.2.3", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", objectClass.getMayAttributeTypeOids().get(1));
    assertEquals(2, objectClass.getExtensions().size());
    assertNotNull(objectClass.getExtension("X-TEST-a"));
    assertEquals(2, objectClass.getExtension("X-TEST-a").size());
    assertEquals("test1-1", objectClass.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", objectClass.getExtension("X-TEST-a").get(1));
    assertNotNull(objectClass.getExtension("X-TEST-b"));
    assertEquals(2, objectClass.getExtension("X-TEST-b").size());
    assertEquals("test2-1", objectClass.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", objectClass.getExtension("X-TEST-b").get(1));
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 38 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testSunAlias.

@Test
public void testSunAlias() throws ParseException, NamingException {
    String value = "( 2.5.6.1 NAME 'alias' DESC 'Standard LDAP objectclass' SUP top ABSTRACT MUST aliasedObjectName X-ORIGIN 'RFC 2256' )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("2.5.6.1", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("alias", objectClass.getNames().get(0));
    assertEquals("Standard LDAP objectclass", objectClass.getDescription());
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("top", objectClass.getSuperiorOids().get(0));
    assertEquals(ObjectClassTypeEnum.ABSTRACT, objectClass.getType());
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("aliasedObjectName", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals(0, objectClass.getMayAttributeTypeOids().size());
    assertEquals(1, objectClass.getExtensions().size());
    assertNotNull(objectClass.getExtension("X-ORIGIN"));
    assertEquals(1, objectClass.getExtension("X-ORIGIN").size());
    assertEquals("RFC 2256", objectClass.getExtension("X-ORIGIN").get(0));
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 39 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testMay.

/**
 * Test MAY and its values.
 * Very similar to SUP, so here are less test cases.
 *
 * @throws ParseException
 */
@Test
public void testMay() throws ParseException {
    String value = null;
    ObjectClass objectClass = null;
    // no MAY
    value = "( 1.1 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(0, objectClass.getMayAttributeTypeOids().size());
    // MAY simple numericoid
    value = "( 1.1 MAY 1.2.3 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getMayAttributeTypeOids().size());
    assertEquals("1.2.3", objectClass.getMayAttributeTypeOids().get(0));
    // MAY multiple
    value = "(1.1 MAY(cn$sn       $11.22.33.44.55\n$  objectClass   ))";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(4, objectClass.getMayAttributeTypeOids().size());
    assertEquals("cn", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("sn", objectClass.getMayAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", objectClass.getMayAttributeTypeOids().get(2));
    assertEquals("objectClass", objectClass.getMayAttributeTypeOids().get(3));
    // MAY multiple, no $ separator, quoted
    value = "(1.1 MAY('cn' sn\t'11.22.33.44.55'\nobjectClass))";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(4, objectClass.getMayAttributeTypeOids().size());
    assertEquals("cn", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("sn", objectClass.getMayAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", objectClass.getMayAttributeTypeOids().get(2));
    assertEquals("objectClass", objectClass.getMayAttributeTypeOids().get(3));
    if (!parser.isQuirksMode()) {
        // invalid value
        value = "( 1.1 MAY ( c_n ) )";
        try {
            objectClass = parser.parseObjectClassDescription(value);
            fail("Exception expected, invalid value c_n");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 40 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testSuperior.

/**
 * Test SUP and its values.
 *
 * @throws ParseException
 */
@Test
public void testSuperior() throws ParseException, NamingException {
    String value = null;
    ObjectClass objectClass = null;
    // no SUP
    value = "( 1.1 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(0, objectClass.getSuperiorOids().size());
    // SUP simple numericoid
    value = "( 1.1 SUP 1.2.3 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("1.2.3", objectClass.getSuperiorOids().get(0));
    // SUP simple descr
    value = "( 1.1 SUP top )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("top", objectClass.getSuperiorOids().get(0));
    // SUP single numericoid
    value = "( 1.1 SUP ( 1.2.3.4.5 ) )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("1.2.3.4.5", objectClass.getSuperiorOids().get(0));
    // SUP single descr
    value = "( 1.1 SUP ( A-Z-0-9 ) )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("A-Z-0-9", objectClass.getSuperiorOids().get(0));
    // SUP multi numericoid
    value = "( 1.1 SUP ( 1.2.3 $ 1.2.3.4.5 ) )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(2, objectClass.getSuperiorOids().size());
    assertEquals("1.2.3", objectClass.getSuperiorOids().get(0));
    assertEquals("1.2.3.4.5", objectClass.getSuperiorOids().get(1));
    // SUP multi descr
    value = "( 1.1 SUP ( top1 $ top2 ) )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(2, objectClass.getSuperiorOids().size());
    assertEquals("top1", objectClass.getSuperiorOids().get(0));
    assertEquals("top2", objectClass.getSuperiorOids().get(1));
    // SUP multi mixed, tabs
    value = "\t(\t1.1\tSUP\t(\ttop1\t$\t1.2.3.4\t$\ttop2\t)\t)\t";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(3, objectClass.getSuperiorOids().size());
    assertEquals("top1", objectClass.getSuperiorOids().get(0));
    assertEquals("1.2.3.4", objectClass.getSuperiorOids().get(1));
    assertEquals("top2", objectClass.getSuperiorOids().get(2));
    // SUP multi mixed, no space
    value = "(1.1 SUP(TOP-1$1.2.3.4$TOP-2))";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(3, objectClass.getSuperiorOids().size());
    assertEquals("TOP-1", objectClass.getSuperiorOids().get(0));
    assertEquals("1.2.3.4", objectClass.getSuperiorOids().get(1));
    assertEquals("TOP-2", objectClass.getSuperiorOids().get(2));
    // SUP multi mixed many spaces
    value = "(          1.1          SUP          (          top1          $          1.2.3.4$top2          )          )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(3, objectClass.getSuperiorOids().size());
    assertEquals("top1", objectClass.getSuperiorOids().get(0));
    assertEquals("1.2.3.4", objectClass.getSuperiorOids().get(1));
    assertEquals("top2", objectClass.getSuperiorOids().get(2));
    // quoted value
    value = "( 1.1 SUP 'top' )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("top", objectClass.getSuperiorOids().get(0));
    // quoted value
    value = "( 1.1 SUP '1.2.3.4' )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("1.2.3.4", objectClass.getSuperiorOids().get(0));
    // no $ separator
    value = "( 1.1 SUP ( top1 top2 ) )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(2, objectClass.getSuperiorOids().size());
    assertEquals("top1", objectClass.getSuperiorOids().get(0));
    assertEquals("top2", objectClass.getSuperiorOids().get(1));
    // invalid character
    value = "( 1.1 SUP 1.2.3.4.A )";
    try {
        objectClass = parser.parseObjectClassDescription(value);
        fail("Exception expected, invalid SUP '1.2.3.4.A' (invalid character)");
    } catch (ParseException pe) {
    // expected
    }
    // empty sup
    value = "( 1.1 SUP )";
    try {
        objectClass = parser.parseObjectClassDescription(value);
        fail("Exception expected, no SUP value");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // invalid start
        value = "( 1.1 SUP ( top1 $ -top2 ) )";
        try {
            objectClass = parser.parseObjectClassDescription(value);
            fail("Exception expected, invalid SUP '-top' (starts with hypen)");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) ParseException(java.text.ParseException) 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