Search in sources :

Example 1 with Normalizer

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

the class SchemaManagerAddTest method testAddNewNormalizer.

// =========================================================================
// MatchingRuleUse addition tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// NameForm addition tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// Normalizer addition tests
// -------------------------------------------------------------------------
@Test
public void testAddNewNormalizer() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer(oid);
    assertTrue(schemaManager.add(normalizer));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    Normalizer added = schemaManager.lookupNormalizerRegistry(oid);
    assertNotNull(added);
    assertEquals(normalizer.getClass().getName(), added.getFqcn());
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 2 with Normalizer

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

the class SchemaManagerAddTest method testAddAlreadyExistingNormalizer.

@Test
public void testAddAlreadyExistingNormalizer() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer(oid);
    assertTrue(schemaManager.add(normalizer));
    Normalizer added = schemaManager.lookupNormalizerRegistry(oid);
    assertNotNull(added);
    assertEquals(normalizer.getClass().getName(), added.getFqcn());
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    Normalizer normalizer2 = new NoOpNormalizer(oid);
    assertFalse(schemaManager.add(normalizer2));
    errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    added = schemaManager.lookupNormalizerRegistry(oid);
    assertNotNull(added);
    assertEquals(normalizer.getClass().getName(), added.getFqcn());
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 3 with Normalizer

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

the class SchemaManagerAddTest method testAddNormalizerWithWrongFQCN.

/**
 * Test that we can't add two Normalizers with the same class code.
 */
@Test
public void testAddNormalizerWithWrongFQCN() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer(oid);
    // using java.sql.ResultSet cause it is very unlikely to get loaded
    // in ADS, as the FQCN is not the one expected
    normalizer.setFqcn("java.sql.ResultSet");
    assertFalse(schemaManager.add(normalizer));
    List<Throwable> errors = schemaManager.getErrors();
    errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    try {
        schemaManager.lookupNormalizerRegistry(oid);
        fail();
    } catch (Exception e) {
        // Expected
        assertTrue(true);
    }
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) IOException(java.io.IOException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 4 with Normalizer

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

the class SchemaManagerDelTest method testDeleteNonExistingNormalizer.

@Test
public void testDeleteNonExistingNormalizer() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    Normalizer nr = new BooleanNormalizer();
    nr.setOid("0.0");
    assertFalse(schemaManager.delete(nr));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 5 with Normalizer

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

the class SchemaManagerDelTest method testDeleteExistingNormalizerUsedByMatchingRule.

@Test
public void testDeleteExistingNormalizerUsedByMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    Normalizer nr = schemaManager.lookupNormalizerRegistry("2.5.13.0");
    // shouldn't be deleted cause there is a MR associated with it
    assertFalse(schemaManager.delete(nr));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    assertNotNull(schemaManager.lookupNormalizerRegistry("2.5.13.0"));
    assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Aggregations

Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)78 Test (org.junit.Test)59 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)20 DeepTrimNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimNormalizer)15 TelephoneNumberNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.TelephoneNumberNormalizer)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 NumericNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer)9 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)7 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)6 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)5 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)5 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)4 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)4 ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)4 BooleanNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3