Search in sources :

Example 6 with MutableAttributeType

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

the class SchemaManagerDelTest method testDeleteExistingMatchingRuleUsedByRemovedAttributeType.

/**
 * Check that a MatcingRule which has been used by a deleted AttributeType
 * can be removed
 */
@Test
public void testDeleteExistingMatchingRuleUsedByRemovedAttributeType() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String AT_OID = "2.5.18.9";
    String MR_OID = "2.5.13.13";
    // Check that the AT and MR are present
    assertTrue(isAttributeTypePresent(schemaManager, AT_OID));
    assertTrue(isMatchingRulePresent(schemaManager, MR_OID));
    // Now try to remove the MR
    MatchingRule matchingRule = schemaManager.lookupMatchingRuleRegistry(MR_OID);
    // shouldn't be deleted cause there is a AT associated with it
    assertFalse(schemaManager.delete(matchingRule));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using AT : it should be OK
    MutableAttributeType at = new MutableAttributeType(AT_OID);
    assertTrue(schemaManager.delete(at));
    assertEquals(atrSize - 1, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isAttributeTypePresent(schemaManager, AT_OID));
    // and try to delete the MatchingRule again
    assertTrue(schemaManager.delete(matchingRule));
    assertFalse(isMatchingRulePresent(schemaManager, MR_OID));
    assertEquals(mrrSize - 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize - 2, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) 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) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 7 with MutableAttributeType

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

the class SchemaManagerDelTest method testDeleteExistingSyntaxUsedByRemovedAttributeType.

/**
 * Check that a Syntax which has been used by a deleted AttributeType
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxUsedByRemovedAttributeType() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String AT_OID = "1.3.6.1.4.1.1466.101.120.16";
    String S_OID = "1.3.6.1.4.1.1466.115.121.1.54";
    // Check that the AT and S are present
    assertTrue(isAttributeTypePresent(schemaManager, AT_OID));
    assertTrue(isSyntaxPresent(schemaManager, S_OID));
    // Now try to remove the S
    LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry(S_OID);
    // shouldn't be deleted cause there is a AT associated with it
    assertFalse(schemaManager.delete(syntax));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using AT : it should be OK
    MutableAttributeType at = new MutableAttributeType(AT_OID);
    assertTrue(schemaManager.delete(at));
    assertEquals(atrSize - 1, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isAttributeTypePresent(schemaManager, AT_OID));
    // and try to delete the syntax again
    assertTrue(schemaManager.delete(syntax));
    assertFalse(isSyntaxPresent(schemaManager, S_OID));
    assertEquals(srSize - 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize - 2, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) 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 8 with MutableAttributeType

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

the class SchemaManagerDelTest method testDelAttributeTypeFromDisabledSchema.

/**
 * Delete an existing AT stored in some disabled schema
 */
@Test
public void testDelAttributeTypeFromDisabledSchema() throws Exception {
    SchemaManager schemaManager = loadSchema("Core");
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    // Try to delete an AT which is contained by a disabled schema
    MutableAttributeType attributeType = new MutableAttributeType("gecos");
    attributeType.setOid("1.3.6.1.1.1.1.2");
    // It should fail
    assertFalse(schemaManager.delete(attributeType));
    assertFalse(isAttributeTypePresent(schemaManager, "gecos"));
    assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize, 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 9 with MutableAttributeType

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

the class SchemaManagerDelTest method testDeleteNonExistingAttributeType.

// =========================================================================
// For each test, we will check many different things.
// If the test is successful, we want to know if the SchemaObject
// Registry has shrunk : its size must be one lower. If the SchemaObject
// is not loadable, then the GlobalOidRegistry must also have grown.
// =========================================================================
// AttributeType deletion tests
// -------------------------------------------------------------------------
// First, not defined descendant
// -------------------------------------------------------------------------
/**
 * Try to delete an AttributeType not existing in the schemaManager
 */
@Test
public void testDeleteNonExistingAttributeType() throws Exception {
    SchemaManager schemaManager = loadSchema("Core");
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setEqualityOid("2.5.13.1");
    attributeType.setOrderingOid(null);
    attributeType.setSubstringOid(null);
    // It should fail
    assertFalse(schemaManager.delete(attributeType));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize, 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 10 with MutableAttributeType

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

the class SchemaManagerDelTest method testDeleteExistingAttributeType.

/**
 * Delete an existing AT not referenced by any object
 */
@Test
public void testDeleteExistingAttributeType() throws Exception {
    // First inject such an AT
    SchemaManager schemaManager = loadSchema("Core");
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("generationQualifier");
    attributeType.setOid("2.5.4.44");
    // It should not fail
    assertTrue(schemaManager.delete(attributeType));
    assertFalse(isAttributeTypePresent(schemaManager, "generationQualifier"));
    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)

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