Search in sources :

Example 41 with MutableAttributeType

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

the class SchemaManagerAddTest method testAddAttributeTypeNameAlreadyExist.

/**
 * Try to inject an AttributeType with an already attributed name
 */
@Test
public void testAddAttributeTypeNameAlreadyExist() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.1.0");
    attributeType.setEqualityOid("2.5.13.1");
    attributeType.setOrderingOid("2.5.13.1");
    attributeType.setSubstringOid("2.5.13.1");
    attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    attributeType.setNames("Test", "cn");
    // It should fail
    assertFalse(schemaManager.add(attributeType));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    // The AT must not be there
    assertFalse(isATPresent(schemaManager, "1.1.1.0"));
    assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 42 with MutableAttributeType

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

the class SchemaManagerAddTest method testAddAttributeTypeNoEqualityMR.

/**
 * Try to inject an AttributeType without EQUALITY MR
 */
@Test
public void testAddAttributeTypeNoEqualityMR() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.8 ");
    attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
    // It should be OK
    assertTrue(schemaManager.add(attributeType));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertTrue(isATPresent(schemaManager, "1.1.0"));
    assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 43 with MutableAttributeType

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

the class SchemaManagerAddTest method testAddAttributeTypeAlreadyExist.

/**
 * Try to inject an AttributeType which already exist
 */
@Test
public void testAddAttributeTypeAlreadyExist() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("2.5.18.4");
    attributeType.setEqualityOid("2.5.13.1");
    attributeType.setOrderingOid("2.5.13.1");
    attributeType.setSubstringOid("2.5.13.1");
    // It should fail
    assertFalse(schemaManager.add(attributeType));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    // The AT must be there
    assertTrue(isATPresent(schemaManager, "2.5.18.4"));
    // Check that it hasen't changed
    AttributeType original = schemaManager.lookupAttributeTypeRegistry("2.5.18.4");
    assertEquals("distinguishedNameMatch", original.getEqualityOid());
    assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 44 with MutableAttributeType

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

the class SchemaManagerAddTest method testAddAttributeTypeSupCollectiveUser.

/**
 * Try to inject an AttributeType which is a subtype of a Collective AT
 */
@Test
public void testAddAttributeTypeSupCollectiveUser() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    // Create the collective attribute first
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setEqualityOid("2.5.13.1");
    attributeType.setOrderingOid(null);
    attributeType.setSubstringOid(null);
    attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
    attributeType.setCollective(true);
    // It should not fail
    assertTrue(schemaManager.add(attributeType));
    assertTrue(isATPresent(schemaManager, "1.1.0"));
    assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
    // Now try to create an AT which is a subtype of teh create collective attribute
    MutableAttributeType subType = new MutableAttributeType("1.1.1");
    subType.setEqualityOid("2.5.13.1");
    subType.setOrderingOid(null);
    subType.setSubstringOid(null);
    subType.setSuperiorOid("1.1.0");
    subType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    subType.setUsage(UsageEnum.USER_APPLICATIONS);
    subType.setCollective(false);
    // It should fail
    assertFalse(schemaManager.add(subType));
    assertFalse(isATPresent(schemaManager, "1.1.1"));
    assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 45 with MutableAttributeType

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

the class SchemaManagerAddTest method testAddAttributeTypeSupWithOwnSup.

/**
 * Try to inject an AttributeType with itself as a superior
 */
@Test
public void testAddAttributeTypeSupWithOwnSup() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setEqualityOid(null);
    attributeType.setOrderingOid(null);
    attributeType.setSubstringOid(null);
    attributeType.setSuperiorOid("1.1.0");
    attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
    // It should fail
    assertFalse(schemaManager.add(attributeType));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    assertFalse(isATPresent(schemaManager, "1.1.0"));
    assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) 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