Search in sources :

Example 26 with LdapSyntax

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

the class SchemaManagerAddTest method testAddValidSyntax.

// =========================================================================
// Syntax addition tests
// -------------------------------------------------------------------------
/**
 * Try to inject a new valid Syntax, with no SC : the associated SC
 * will be the default OctetString SC
 */
@Test
public void testAddValidSyntax() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    LdapSyntax syntax = new LdapSyntax("1.1.0");
    // It should not fail
    assertTrue(schemaManager.add(syntax));
    LdapSyntax added = schemaManager.lookupLdapSyntaxRegistry("1.1.0");
    assertNotNull(added);
    assertEquals(OctetStringSyntaxChecker.class.getName(), added.getSyntaxChecker().getClass().getName());
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertTrue(isSyntaxPresent(schemaManager, "1.1.0"));
    assertEquals(sSize + 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : OctetStringSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker) 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) Test(org.junit.Test)

Example 27 with LdapSyntax

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

the class SchemaManagerAddTest method testAddSyntaxExistingOid.

/**
 * Try to inject a Syntax with an existing OID
 */
@Test
public void testAddSyntaxExistingOid() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    LdapSyntax syntax = new LdapSyntax("2.5.4.3");
    // It should fail
    assertFalse(schemaManager.add(syntax));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) 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) Test(org.junit.Test)

Example 28 with LdapSyntax

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

the class SchemaManagerDelTest method testDeleteExistingSyntaxCheckerUsedByRemovedSyntax.

/**
 * Check that a SyntaxChecker which has been used by a deleted Syntax
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxCheckerUsedByRemovedSyntax() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String OID = "1.3.6.1.4.1.1466.115.121.1.33";
    // Check that the S and SC are present
    assertTrue(isSyntaxCheckerPresent(schemaManager, OID));
    assertTrue(isSyntaxPresent(schemaManager, OID));
    // Now try to remove the SC
    SyntaxChecker sc = schemaManager.lookupSyntaxCheckerRegistry(OID);
    // shouldn't be deleted cause there is a S associated with it
    assertFalse(schemaManager.delete(sc));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using S : it should be OK
    LdapSyntax syntax = new LdapSyntax(OID);
    assertTrue(schemaManager.delete(syntax));
    assertEquals(srSize - 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isSyntaxPresent(schemaManager, OID));
    // and try to delete the SC again
    assertTrue(schemaManager.delete(sc));
    assertFalse(isSyntaxCheckerPresent(schemaManager, OID));
    assertEquals(scrSize - 1, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : BooleanSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) 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) Test(org.junit.Test)

Example 29 with LdapSyntax

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

the class SchemaManagerDelTest method testDeleteExistingSyntax.

// =========================================================================
// Syntax deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingSyntax() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    // delete a existing syntax not used by AT and MR
    LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry("1.3.6.1.4.1.1466.115.121.1.10");
    assertTrue(schemaManager.delete(syntax));
    assertEquals(sSize - 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    // add a syntax and then delete (should behave same as above )
    syntax = new LdapSyntax("0.1.1");
    assertTrue(schemaManager.add(syntax));
    assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    syntax = schemaManager.lookupLdapSyntaxRegistry("0.1.1");
    assertTrue(schemaManager.delete(syntax));
    try {
        schemaManager.lookupLdapSyntaxRegistry("0.1.1");
        fail("shouldn't find the syntax");
    } catch (Exception e) {
    // expected behaviour
    }
    assertEquals(sSize - 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : 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) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 30 with LdapSyntax

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

the class SchemaManagerDelTest method testDeleteNonExistingSyntax.

@Test
public void testDeleteNonExistingSyntax() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    LdapSyntax syntax = new LdapSyntax("0.1.1");
    assertFalse(schemaManager.delete(syntax));
    assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : 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) Test(org.junit.Test)

Aggregations

LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)34 Test (org.junit.Test)12 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)10 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)9 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)9 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)9 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)4 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)4 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)4 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)3 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)2 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2