Search in sources :

Example 56 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testNoUserModification.

/**
 * Tests NO-USER-MODIFICATION
 *
 * @throws ParseException
 */
@Test
public void testNoUserModification() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // not NO-USER-MODIFICATION
    value = "( 1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isUserModifiable());
    // NO-USER-MODIFICATION
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' NO-USER-MODIFICATION USAGE directoryOperation )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isUserModifiable());
    // NO-USER-MODIFICATION
    value = "(1.1 SYNTAX 1.1 NO-USER-MODIFICATION USAGE directoryOperation )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isUserModifiable());
    // ivalid
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' NO-USER-MODIFICATIO USAGE directoryOperation )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid NO-USER-MODIFICATION 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 57 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testNoqualityMR.

/**
 * Tests without EQUALITY
 *
 * @throws ParseException
 */
@Test
public void testNoqualityMR() throws ParseException {
    String value = "( 2.5.4.58 NAME 'attributeCertificateAttribute' " + "DESC 'attribute certificate use ;binary' " + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 ) ";
    AttributeType attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("2.5.4.58", attributeType.getOid());
    assertEquals(1, attributeType.getNames().size());
    assertEquals("attributeCertificateAttribute", attributeType.getNames().get(0));
    assertEquals("attribute certificate use ;binary", attributeType.getDescription());
    assertNull(attributeType.getSuperiorOid());
    assertNull(attributeType.getEqualityOid());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.8", attributeType.getSyntaxOid());
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    assertEquals(0, attributeType.getExtensions().size());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 58 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testCollecitveConstraint.

/**
 * Test collective constraint:
 * COLLECTIVE requires USAGE userApplications
 *
 * @throws ParseException
 */
@Test
public void testCollecitveConstraint() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    value = "( 1.1 SYNTAX 1.1 COLLECTIVE )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isCollective());
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    value = "( 1.1 SYNTAX 1.1 COLLECTIVE USAGE userApplications )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isCollective());
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    if (!parser.isQuirksMode()) {
        value = "( 1.1 SYNTAX 1.1 COLLECTIVE USAGE directoryOperation )";
        try {
            parser.parseAttributeTypeDescription(value);
            fail("Exception expected, COLLECTIVE requires USAGE userApplications");
        } catch (ParseException pe) {
        // expected
        }
        value = "( 1.1 SYNTAX 1.1 COLLECTIVE USAGE dSAOperation )";
        try {
            parser.parseAttributeTypeDescription(value);
            fail("Exception expected, COLLECTIVE requires USAGE userApplications");
        } catch (ParseException pe) {
        // expected
        }
        value = "( 1.1 SYNTAX 1.1 COLLECTIVE USAGE distributedOperation )";
        try {
            parser.parseAttributeTypeDescription(value);
            fail("Exception expected, COLLECTIVE requires USAGE userApplications");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 59 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testIgnoreElementOrder.

/**
 * Ensure that element order is ignored
 *
 * @throws ParseException
 */
@Test
public void testIgnoreElementOrder() throws ParseException {
    String value = "( 2.5.4.3 SUP name SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE userApplications DESC 'RFC2256: common name(s) for which the entity is known by'  EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch NAME ( 'cn' 'commonName' )  )";
    AttributeType attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("2.5.4.3", attributeType.getOid());
    assertEquals(2, attributeType.getNames().size());
    assertEquals("cn", attributeType.getNames().get(0));
    assertEquals("commonName", attributeType.getNames().get(1));
    assertEquals("RFC2256: common name(s) for which the entity is known by", attributeType.getDescription());
    assertEquals("name", attributeType.getSuperiorOid());
    assertEquals("caseIgnoreMatch", attributeType.getEqualityOid());
    assertEquals("caseIgnoreSubstringsMatch", attributeType.getSubstringOid());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid());
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    assertEquals(0, attributeType.getExtensions().size());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 60 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testATWithSpacesInDesc.

/**
 * Tests with spaces in DESC
 *
 * @throws ParseException
 */
@Test
public void testATWithSpacesInDesc() throws ParseException {
    String value = "( 1.3.18.0.2.4.216 NAME 'SAFDfpDataClass' DESC '  ' " + "EQUALITY 2.5.13.2 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE )";
    AttributeType attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.3.18.0.2.4.216", attributeType.getOid());
    assertEquals(1, attributeType.getNames().size());
    assertEquals("SAFDfpDataClass", attributeType.getNames().get(0));
    assertEquals("  ", attributeType.getDescription());
    assertNull(attributeType.getSuperiorOid());
    assertEquals("2.5.13.2", attributeType.getEqualityOid());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid());
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    assertTrue(attributeType.isSingleValued());
    assertEquals(0, attributeType.getExtensions().size());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) 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