Search in sources :

Example 86 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testCollective.

/**
 * Tests COLLECTIVE
 *
 * @throws ParseException
 */
@Test
public void testCollective() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // not collective
    value = "( 1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isCollective());
    // single-value
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' COLLECTIVE )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isCollective());
    // single-value
    value = "(1.1 SYNTAX 1.1 COLLECTIVE)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isCollective());
    // ivalid
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' COLLECTIV )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid COLLECTIVE 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 87 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testNoUserModificatonConstraint.

/**
 * Test no-user-modification constraint:
 * NO-USER-MODIFICATION requires an operational USAGE
 *
 * @throws ParseException
 */
@Test
public void testNoUserModificatonConstraint() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    value = "( 1.1 SYNTAX 1.1 NO-USER-MODIFICATION USAGE directoryOperation )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isUserModifiable());
    assertEquals(UsageEnum.DIRECTORY_OPERATION, attributeType.getUsage());
    value = "( 1.1 SYNTAX 1.1 NO-USER-MODIFICATION USAGE dSAOperation )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isUserModifiable());
    assertEquals(UsageEnum.DSA_OPERATION, attributeType.getUsage());
    value = "( 1.1 SYNTAX 1.1 NO-USER-MODIFICATION USAGE distributedOperation )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isUserModifiable());
    assertEquals(UsageEnum.DISTRIBUTED_OPERATION, attributeType.getUsage());
    if (!parser.isQuirksMode()) {
        value = "( 1.1 SYNTAX 1.1 NO-USER-MODIFICATION USAGE userApplications )";
        try {
            parser.parseAttributeTypeDescription(value);
            fail("Exception expected, NO-USER-MODIFICATION requires an operational USAGE");
        } catch (ParseException pe) {
        // expected
        }
        value = "( 1.1 SYNTAX 1.1 NO-USER-MODIFICATION )";
        try {
            parser.parseAttributeTypeDescription(value);
            fail("Exception expected, NO-USER-MODIFICATION requires an operational USAGE");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 88 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testSubstring.

/**
 * Tests SUBSTRING and its values.
 * Very similar to SUP, so here are less test cases.
 *
 * @throws ParseException
 */
@Test
public void testSubstring() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // no SUBSTR
    value = "( 1.1 SYNTAX 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNull(attributeType.getSubstringOid());
    // SUBSTR numericoid
    value = "( 1.1 SYNTAX 1.1 SUBSTR 1.2.3.4567.8.9.0 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getSubstringOid());
    // SUBSTR descr, no space
    value = "(1.1 SYNTAX1.1 SUBSTRabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getSubstringOid());
    // SUBSTR descr, newline
    value = "\r\n(\r\n1.1\r\nSYNTAX\r\n1.1\r\nSUBSTR\r\nabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789\r\n)\r\n";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getSubstringOid());
    // quoted value
    value = "( 1.1 SYNTAX 1.1 SUBSTR 'caseIgnoreSubstringsMatch' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("caseIgnoreSubstringsMatch", attributeType.getSubstringOid());
    // quote value in parentheses
    value = "( 1.1 SYNTAX 1.1 SUBSTR ('caseIgnoreSubstringsMatch') )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("caseIgnoreSubstringsMatch", attributeType.getSubstringOid());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 89 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testUsage.

/**
 * Tests usage
 *
 * @throws ParseException
 */
@Test
public void testUsage() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // DEFAULT is userApplications
    value = "( 1.1 SYNTAX 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    // userApplications
    value = "( 1.1 SYNTAX 1.1 USAGE userApplications )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
    // directoryOperation
    value = "( 1.1 SYNTAX 1.1 USAGE directoryOperation )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals(UsageEnum.DIRECTORY_OPERATION, attributeType.getUsage());
    // distributedOperation, tabs
    value = "\t(\t1.1\tSYNTAX\t1.1\tUSAGE\tdistributedOperation\t)\t";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals(UsageEnum.DISTRIBUTED_OPERATION, attributeType.getUsage());
    // dSAOperation, no space
    value = "(1.1 SYNTAX1.1 USAGEdSAOperation)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals(UsageEnum.DSA_OPERATION, attributeType.getUsage());
    // directoryOperation, case insensitivity
    value = "( 1.1 SYNTAX 1.1 USAGE DiReCtOrYoPeRaTiOn )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals(UsageEnum.DIRECTORY_OPERATION, attributeType.getUsage());
    // ivalid
    value = "( 1.1 SYNTAX 1.1 USAGE abc )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid USAGE 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 90 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testOrdering.

/**
 * Tests ORDERING and its values.
 * Very similar to SUP, so here are less test cases.
 *
 * @throws ParseException
 */
@Test
public void testOrdering() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // no ORDERING
    value = "( 1.1 SYNTAX 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNull(attributeType.getOrderingOid());
    // ORDERING numericoid
    value = "( 1.1 SYNTAX 1.1 ORDERING 1.2.3.4567.8.9.0 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getOrderingOid());
    // ORDERING descr, no space
    value = "(1.1 SYNTAX1.1 ORDERINGabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getOrderingOid());
    // ORDERING descr, newline
    value = "\r(\r1.1\rSYNTAX\r1.1\rORDERING\rabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789\r)\r";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getOrderingOid());
    // quoted value
    value = "( 1.1 SYNTAX 1.1 ORDERING 'generalizedTimeOrderingMatch' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("generalizedTimeOrderingMatch", attributeType.getOrderingOid());
    // quote value in parentheses
    value = "( 1.1 SYNTAX 1.1 ORDERING ('generalizedTimeOrderingMatch') )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("generalizedTimeOrderingMatch", attributeType.getOrderingOid());
}
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