Search in sources :

Example 61 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testSuperType.

/**
 * Test SUP and its value.
 *
 * @throws ParseException
 */
@Test
public void testSuperType() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // no SUP
    value = "( 1.1 SYNTAX 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNull(attributeType.getSuperiorOid());
    // SUP numericoid
    value = "( 1.1 SYNTAX 1.1 SUP 1.2.3.4.5.6.7.8.9.0 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", attributeType.getSuperiorOid());
    // SUP descr, no space
    value = "(1.1 SYNTAX1.1 SUPabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getSuperiorOid());
    // SUP descr, newline
    value = "\t(\t1.1\tSYNTAX\t1.1\tSUP\tabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789\t)\t";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getSuperiorOid());
    // quoted SUP value
    value = "( 1.1 SYNTAX 1.1 SUP 'name' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("name", attributeType.getSuperiorOid());
    // quoted SUP value
    value = "( 1.1 SYNTAX 1.1 SUP '1.2.3.4' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4", attributeType.getSuperiorOid());
    // quoted SUP value
    value = "( 1.1 SYNTAX 1.1 SUP ('1.2.3.4') )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4", attributeType.getSuperiorOid());
    // invalid character
    value = "( 1.1 SYNTAX 1.1 SUP 1.2.3.4.A )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid SUP '1.2.3.4.A' (invalid character)");
    } catch (ParseException pe) {
    // expected
    }
    // only single SUP allowed
    value = "( 1.1 SYNTAX 1.1 SUP ( name1 $ name2 ) )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, only single SUP allowed");
    } catch (ParseException pe) {
    // expected
    }
    // empty sup
    value = "( 1.1 SYNTAX 1.1 SUP )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, no SUP value");
    } catch (ParseException pe) {
    // expected
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 62 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testRfcUid.

// //////////////////////////////////////////////////////////////
// Some real-world attribute type definitions         //
// //////////////////////////////////////////////////////////////
@Test
public void testRfcUid() throws ParseException {
    String value = "( 0.9.2342.19200300.100.1.1 NAME ( 'uid' 'userid' ) DESC 'RFC1274: user identifier' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} USAGE userApplications )";
    AttributeType attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("0.9.2342.19200300.100.1.1", attributeType.getOid());
    assertEquals(2, attributeType.getNames().size());
    assertEquals("uid", attributeType.getNames().get(0));
    assertEquals("userid", attributeType.getNames().get(1));
    assertEquals("RFC1274: user identifier", attributeType.getDescription());
    assertNull(attributeType.getSuperiorOid());
    assertEquals("caseIgnoreMatch", attributeType.getEqualityOid());
    assertEquals("caseIgnoreSubstringsMatch", attributeType.getSubstringOid());
    assertNull(attributeType.getOrderingOid());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid());
    assertEquals(256, attributeType.getSyntaxLength());
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    assertFalse(attributeType.isObsolete());
    assertFalse(attributeType.isCollective());
    assertFalse(attributeType.isSingleValued());
    assertTrue(attributeType.isUserModifiable());
    assertEquals(0, attributeType.getExtensions().size());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 63 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testAttributeTypeWithSchemaExtension.

/**
 * Tests the parse of a simple AttributeType with the schema extension.
 */
@Test
public void testAttributeTypeWithSchemaExtension() throws ParseException {
    String substrate = "( 1.3.6.1.4.1.18060.0.4.0.2.10000 NAME ( 'bogus' 'bogusName' ) " + "DESC 'bogus description' SUP name SINGLE-VALUE X-SCHEMA 'blah' )";
    AttributeType desc = parser.parseAttributeTypeDescription(substrate);
    assertEquals("1.3.6.1.4.1.18060.0.4.0.2.10000", desc.getOid());
    assertEquals("bogus", desc.getNames().get(0));
    assertEquals("bogusName", desc.getNames().get(1));
    assertEquals("bogus description", desc.getDescription());
    assertEquals("name", desc.getSuperiorOid());
    assertEquals(true, desc.isSingleValued());
    assertEquals("blah", desc.getExtension("X-SCHEMA").get(0));
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 64 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType 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 65 with AttributeType

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

the class OpenLdapSchemaParserTest method testSimpleAttributeTypeNoLength.

@Test
public void testSimpleAttributeTypeNoLength() throws Exception {
    String attributeTypeData = "attributetype ( 2.5.4.14 NAME 'searchGuide'\n" + "        DESC 'RFC2256: search guide, obsoleted by enhancedSearchGuide'\n" + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.25 )";
    parser.parse(attributeTypeData);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    Map<String, AttributeType> mapAttributeTypes = mapAttributeTypes(attributeTypes);
    AttributeType attributeType = mapAttributeTypes.get("2.5.4.14");
    assertNotNull(attributeType);
    assertEquals("2.5.4.14", attributeType.getOid());
    assertEquals("searchGuide", attributeType.getName());
    assertEquals("RFC2256: search guide, obsoleted by enhancedSearchGuide", attributeType.getDescription());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.25", attributeType.getSyntaxOid());
}
Also used : 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)

Aggregations

AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)135 Test (org.junit.Test)68 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)42 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)25 ParseException (java.text.ParseException)15 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)15 Value (org.apache.directory.api.ldap.model.entry.Value)15 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)11 HashSet (java.util.HashSet)10 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)10 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)10 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)9 IOException (java.io.IOException)7 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)7 Before (org.junit.Before)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)6 ArrayList (java.util.ArrayList)5 Dn (org.apache.directory.api.ldap.model.name.Dn)4