Search in sources :

Example 21 with MutableAttributeType

use of org.apache.directory.api.ldap.model.schema.MutableAttributeType 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)

Example 22 with MutableAttributeType

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

the class OpenLdapSchemaParserTest method testDescWithSpaces.

@Test
public void testDescWithSpaces() throws Exception {
    String attributeTypeData = "attributetype ( 1.3.6.1.4.1.8104.1.1.37 NAME 'versionNumber'\n" + "        DESC 'versionNumber ' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch\n" + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE)";
    parser.parse(attributeTypeData);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    Map<String, AttributeType> mapAttributeTypes = mapAttributeTypes(attributeTypes);
    AttributeType attributeType = mapAttributeTypes.get("1.3.6.1.4.1.8104.1.1.37");
    assertNotNull(attributeType);
    assertEquals("1.3.6.1.4.1.8104.1.1.37", attributeType.getOid());
    assertEquals("versionNumber", attributeType.getName());
    assertEquals("versionNumber ", attributeType.getDescription());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid());
    assertTrue(attributeType.isSingleValued());
}
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)

Example 23 with MutableAttributeType

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

the class OpenLdapSchemaParserTest method testAttributeTypeParseWithDescQuotes.

@Test
public void testAttributeTypeParseWithDescQuotes() throws Exception {
    String attributeTypeData = "# adding a comment  \n" + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n" + "        DESC 'RFC2256: \"knowledge\" information'\n" + "        EQUALITY caseIgnoreMatch\n" + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
    parser.parse(attributeTypeData);
    List<MutableAttributeType> attributeTypeList = parser.getAttributeTypes();
    Map<String, AttributeType> attributeTypes = mapAttributeTypes(attributeTypeList);
    AttributeType type = attributeTypes.get("2.5.4.2");
    assertNotNull(type);
    assertEquals("2.5.4.2", type.getOid());
    assertEquals("knowledgeInformation", type.getName());
    assertEquals("RFC2256: \"knowledge\" information", type.getDescription());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.15", type.getSyntaxOid());
    assertEquals(32768, type.getSyntaxLength());
}
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)

Example 24 with MutableAttributeType

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

the class OpenLdapSchemaParserTest method testOpenLdapObjectIdentifiereMacros.

@Test
public void testOpenLdapObjectIdentifiereMacros() throws Exception {
    InputStream input = getClass().getResourceAsStream("dyngroup.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(2, attributeTypes.size());
    assertEquals(2, objectClassTypes.size());
    assertEquals(8, objectIdentifierMacros.size());
    // check that all macros are resolved
    for (OpenLdapObjectIdentifierMacro macro : objectIdentifierMacros.values()) {
        assertTrue(macro.isResolved());
        assertNotNull(macro.getResolvedOid());
        assertTrue(macro.getResolvedOid().matches("[0-9]+(\\.[0-9]+)+"));
    }
    // check that OIDs in attribute types and object classes are resolved
    for (ObjectClass objectClass : objectClassTypes) {
        List<String> asList = objectClass.getNames();
        if (asList.contains("groupOfURLs")) {
            assertEquals("2.16.840.1.113730.3.2.33", objectClass.getOid());
        } else if (asList.contains("dgIdentityAux")) {
            assertEquals("1.3.6.1.4.1.4203.666.11.8.2.1", objectClass.getOid());
        } else {
            fail("object class 'groupOfURLs' or 'dgIdentityAux' expected");
        }
    }
    for (AttributeType attributeType : attributeTypes) {
        List<String> asList = attributeType.getNames();
        if (asList.contains("memberURL")) {
            assertEquals("2.16.840.1.113730.3.1.198", attributeType.getOid());
        } else if (asList.contains("dgIdentity")) {
            assertEquals("1.3.6.1.4.1.4203.666.11.8.1.1", attributeType.getOid());
        } else {
            fail("attribute type 'memberURL' or 'dgIdentity' expected");
        }
    }
}
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 25 with MutableAttributeType

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

the class AttributeTypeRegistryTest method testRegister.

@Test
public void testRegister() throws LdapException {
    MutableAttributeType at0 = new MutableAttributeType("1.1");
    at0.addName("t", "test", "Test", "T");
    atRegistry.register(at0);
    assertTrue(atRegistry.contains("1.1"));
    assertTrue(atRegistry.contains("t"));
    assertTrue(atRegistry.contains("T"));
    assertTrue(atRegistry.contains("tEsT"));
    assertEquals("1.1", atRegistry.getOidByName("T"));
    try {
        atRegistry.register(at0);
        fail();
    } catch (LdapException ne) {
        assertTrue(true);
    }
}
Also used : MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Aggregations

MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)55 Test (org.junit.Test)37 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)24 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)24 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)18 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)17 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)7 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)6 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)6 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)4 ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)4 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)2