Search in sources :

Example 51 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testSingleValue.

/**
 * Tests SINGLE-VALUE
 *
 * @throws ParseException
 */
@Test
public void testSingleValue() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // not single-value
    value = "( 1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertFalse(attributeType.isSingleValued());
    // single-value
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' SINGLE-VALUE)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isSingleValued());
    // single-value
    value = "(1.1 SYNTAX 1.1 SINGLE-VALUE)";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertTrue(attributeType.isSingleValued());
    // invalid
    value = "(1.1 SYNTAX 1.1 NAME 'test' DESC 'Descripton' SINGLE-VALU )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid SINGLE-VALUE 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 52 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testAddAttributeType.

/**
 * Tests the parse of a simple AttributeType
 */
@Test
public void testAddAttributeType() 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 )";
    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());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 53 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testSyntax.

/**
 * Tests SYNTAX
 *
 * @throws ParseException
 */
@Test
public void testSyntax() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    // no SYNTAX
    value = "( 1.1 SUP 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNull(attributeType.getSyntaxOid());
    assertEquals(0, attributeType.getSyntaxLength());
    // SYNTAX string
    value = "( 1.1 SYNTAX IA5String )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("IA5String", attributeType.getSyntaxOid());
    assertEquals(0, attributeType.getSyntaxLength());
    // SYNTAX numericoid
    value = "( 1.1 SYNTAX 1.2.3.4567.8.9.0 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getSyntaxOid());
    assertEquals(0, attributeType.getSyntaxLength());
    // quoted numericoid
    value = "( 1.1 SYNTAX '1.2.3.4567.8.9.0' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getSyntaxOid());
    assertEquals(0, attributeType.getSyntaxLength());
    // quoted numericoid
    value = "( 1.1 SYNTAX ('1.2.3.4567.8.9.0') )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getSyntaxOid());
    assertEquals(0, attributeType.getSyntaxLength());
    // SYNTAX numericoid and length, no spaces
    value = "(1.1 SYNTAX1.2.3.4567.8.9.0{1234567890})";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getSyntaxOid());
    assertEquals(1234567890, attributeType.getSyntaxLength());
    // SYNTAX, with tabs
    value = "\t(\t1.1\tSYNTAX\t1.2.3.4567.8.9.0\t{1234567890}\t)\t";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4567.8.9.0", attributeType.getSyntaxOid());
    assertEquals(1234567890, attributeType.getSyntaxLength());
    // SYNTAX numericoid and zero length
    value = "( 1.1 SYNTAX 1.2.3 {0} )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3", attributeType.getSyntaxOid());
    assertEquals(0, attributeType.getSyntaxLength());
    // quoted value
    value = "( 1.1 SYNTAX '1.2.3{32}' )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3", attributeType.getSyntaxOid());
    assertEquals(32, attributeType.getSyntaxLength());
    // quote value in parentheses
    value = "( 1.1 SYNTAX ( '1.2.3{32}' ) )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3", attributeType.getSyntaxOid());
    assertEquals(32, attributeType.getSyntaxLength());
    // empty length
    value = "( 1.1 SYNTAX 1.2.3.4{} )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid SYNTAX 1.2.3.4{} (empty length)");
    } catch (ParseException pe) {
    // expected
    }
    // leading zero in length
    value = "( 1.1 SYNTAX 1.2.3.4{01} )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertEquals("1.2.3.4", attributeType.getSyntaxOid());
    assertEquals(1, attributeType.getSyntaxLength());
    // invalid syntax length
    value = "( 1.1 SYNTAX 1.2.3.4{X} )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid SYNTAX 1.2.3.4{X} (invalid length)");
    } catch (ParseException pe) {
    // expected
    }
    // no syntax
    value = "( 1.1 SYNTAX {32} )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid SYNTAX {32} (no syntax)");
    } catch (ParseException pe) {
    // expected
    }
    // length overflow
    value = "( 1.1 SYNTAX 1.2.3.4{123456789012234567890} )";
    try {
        attributeType = parser.parseAttributeTypeDescription(value);
        fail("Exception expected, invalid SYNTAX 1.2.3.4{12345678901234567890} (length overflow)");
    } catch (NumberFormatException nfe) {
    // expected
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 54 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testRequiredElements.

/**
 * Test required elements.
 *
 * @throws ParseException
 */
@Test
public void testRequiredElements() throws ParseException {
    String value = null;
    AttributeType attributeType = null;
    value = "( 1.2.3.4.5.6.7.8.9.0 SYNTAX 1.1 SUP 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNotNull(attributeType.getSyntaxOid());
    assertNotNull(attributeType.getSuperiorOid());
    value = "( 1.2.3.4.5.6.7.8.9.0 SYNTAX 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNotNull(attributeType.getSyntaxOid());
    assertNull(attributeType.getSuperiorOid());
    value = "( 1.2.3.4.5.6.7.8.9.0 SUP 1.1 )";
    attributeType = parser.parseAttributeTypeDescription(value);
    assertNull(attributeType.getSyntaxOid());
    assertNotNull(attributeType.getSuperiorOid());
    if (!parser.isQuirksMode()) {
        value = "( 1.2.3.4.5.6.7.8.9.0 )";
        try {
            parser.parseAttributeTypeDescription(value);
            fail("Exception expected, SYNTAX or SUP is required");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 55 with AttributeType

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

the class AttributeTypeDescriptionSchemaParserTest method testQuirksMode.

/**
 * Tests quirks mode.
 */
@Test
public void testQuirksMode() throws ParseException {
    SchemaParserTestUtils.testQuirksMode(parser, "SYNTAX 1.1");
    try {
        String value = null;
        AttributeType attributeType = null;
        parser.setQuirksMode(true);
        // ensure all other test pass in quirks mode
        testNumericOid();
        testNames();
        testDescription();
        testObsolete();
        testSuperType();
        testEquality();
        testOrdering();
        testSubstring();
        testSyntax();
        testSingleValue();
        testCollective();
        testNoUserModification();
        testUsage();
        testExtensions();
        testFull();
        testUniqueElements();
        testRequiredElements();
        testCollecitveConstraint();
        testNoUserModificatonConstraint();
        testIgnoreElementOrder();
        testRfcUid();
        testAddAttributeType();
        testMultiThreaded();
        // NAME with special chars
        value = "( 1.2.3 SYNTAX te_st NAME 't-e_s.t;' )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals(1, attributeType.getNames().size());
        assertEquals("t-e_s.t;", attributeType.getNames().get(0));
        // SYNTAX with underscore
        value = "( 1.1 SYNTAX te_st )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals("te_st", attributeType.getSyntaxOid());
        // SUPERTYPE with underscore
        value = "( 1.1 SYNTAX 1.1 SUP te_st )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals("te_st", attributeType.getSuperiorOid());
        // EQUALITY with underscore
        value = "( 1.1 SYNTAX 1.1 EQUALITY te_st )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals("te_st", attributeType.getEqualityOid());
        // SUBSTR with underscore
        value = "( 1.1 SYNTAX 1.1 SUBSTR te_st )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals("te_st", attributeType.getSubstringOid());
        // ORDERING with underscore
        value = "( 1.1 SYNTAX 1.1 ORDERING te_st )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals("te_st", attributeType.getOrderingOid());
        // Netscape attribute
        value = "( nsAdminGroupName-oid NAME 'nsAdminGroupName' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'Netscape' )";
        attributeType = parser.parseAttributeTypeDescription(value);
        assertEquals("nsAdminGroupName-oid", attributeType.getOid());
        assertEquals(1, attributeType.getNames().size());
        assertEquals("nsAdminGroupName", attributeType.getNames().get(0));
    } finally {
        parser.setQuirksMode(false);
    }
}
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