Search in sources :

Example 1 with MatchingRule

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

the class SchemaManagerAddTest method testAddMatchingRuleExistingATName.

/**
 * Try to inject a new MatchingRule with an existing AT name
 */
@Test
public void testAddMatchingRuleExistingATName() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.0");
    matchingRule.setNames("Test", "cn");
    matchingRule.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    // It should not fail
    assertTrue(schemaManager.add(matchingRule));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    // Check that the new MR has been injected
    assertTrue(isMRPresent(schemaManager, "1.1.0"));
    MatchingRule added = schemaManager.lookupMatchingRuleRegistry("1.1.0");
    assertTrue(added.getNames().contains("cn"));
    assertTrue(added.getNames().contains("Test"));
    assertEquals(mrrSize + 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) Test(org.junit.Test)

Example 2 with MatchingRule

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

the class SchemaManagerAddTest method testAddMatchingRuleExistingOID.

/**
 * Try to inject a new MatchingRule with an existing OID
 */
@Test
public void testAddMatchingRuleExistingOID() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableMatchingRule matchingRule = new MutableMatchingRule("2.5.13.0");
    matchingRule.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    // It should fail (oid already registered)
    assertFalse(schemaManager.add(matchingRule));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    // Check that the existing MR has not been replaced
    assertTrue(isMRPresent(schemaManager, "2.5.13.0"));
    MatchingRule existing = schemaManager.lookupMatchingRuleRegistry("2.5.13.0");
    assertEquals("objectIdentifierMatch", existing.getName());
    assertEquals(mrrSize, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) 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) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) Test(org.junit.Test)

Example 3 with MatchingRule

use of org.apache.directory.api.ldap.model.schema.MatchingRule 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 4 with MatchingRule

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

the class SchemaManagerDelTest method testDeleteExistingMatchingRule.

// =========================================================================
// DitContentRule deletion tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// DitStructureRule deletion tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// MatchingRule deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int mrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MatchingRule mr = new MatchingRule("2.5.13.33");
    assertTrue(schemaManager.delete(mr));
    assertEquals(mrSize - 1, schemaManager.getMatchingRuleRegistry().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) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 5 with MatchingRule

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

the class SchemaManagerDelTest method testDeleteExistingSyntaxUsedByRemovedMatchingRule.

/**
 * Check that a Syntax which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxUsedByRemovedMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String MR_OID = "2.5.13.11";
    String S_OID = "1.3.6.1.4.1.1466.115.121.1.41";
    // Check that the MR and S are present
    assertTrue(isMatchingRulePresent(schemaManager, MR_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 MR 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 MR : it should be OK
    MatchingRule mr = new MatchingRule(MR_OID);
    assertTrue(schemaManager.delete(mr));
    assertEquals(mrrSize - 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isMatchingRulePresent(schemaManager, MR_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) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Aggregations

MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)36 Test (org.junit.Test)21 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)9 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 ParseException (java.text.ParseException)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)4 LdapComparator (org.apache.directory.api.ldap.model.schema.LdapComparator)3 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2