Java Code Examples for org.apache.directory.api.ldap.model.schema.SchemaManager#lookupComparatorRegistry()

The following examples show how to use org.apache.directory.api.ldap.model.schema.SchemaManager#lookupComparatorRegistry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializableComparator.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * @param schemaManager the schemaManager to set
 */
@SuppressWarnings("unchecked")
@Override
public void setSchemaManager( SchemaManager schemaManager )
{
    if ( wrapped == null )
    {
        try
        {
            wrapped = ( Comparator<E> )
                schemaManager.lookupComparatorRegistry( matchingRuleOid );
        }
        catch ( LdapException ne )
        {
            // Not found : get the default comparator
            wrapped = ( Comparator<E> )
                new ComparableComparator<>( matchingRuleOid );
        }
    }

    ( ( LdapComparator<E> ) wrapped ).setSchemaManager( schemaManager );
    this.schemaManager = schemaManager;
}
 
Example 2
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteExistingComaparatorUsedByMatchingRule() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    LdapComparator<?> lc = schemaManager.lookupComparatorRegistry( "2.5.13.0" );

    // shouldn't be deleted cause there is a MR associated with it
    assertFalse( schemaManager.delete( lc ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertFalse( errors.isEmpty() );
    assertTrue( errors.get( 0 ) instanceof LdapProtocolErrorException );

    assertNotNull( schemaManager.lookupComparatorRegistry( "2.5.13.0" ) );
    assertEquals( ctrSize, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 3
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddNewComparator() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    LdapComparator<?> lc = new BooleanComparator( oid );

    assertTrue( schemaManager.add( lc ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );

    assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );

    assertNotNull( added );
    assertEquals( lc.getClass().getName(), added.getFqcn() );
}
 
Example 4
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
private boolean isComparatorPresent( SchemaManager schemaManager, String oid )
{
    try
    {
        LdapComparator<?> comparator = schemaManager.lookupComparatorRegistry( oid );

        return comparator != null;
    }
    catch ( LdapException ne )
    {
        return false;
    }
}
 
Example 5
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteExistingComparator() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    LdapComparator<?> lc = new BooleanComparator( "0.1.1" );
    assertTrue( schemaManager.add( lc ) );

    assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    lc = schemaManager.lookupComparatorRegistry( "0.1.1" );
    assertNotNull( lc );
    assertTrue( schemaManager.delete( lc ) );

    try
    {
        schemaManager.lookupComparatorRegistry( "0.1.1" );
        fail();
    }
    catch ( Exception e )
    {
        // expected
    }

    assertEquals( ctrSize, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 6
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddAlreadyExistingComparator() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    LdapComparator<?> bc = new BooleanComparator( oid );

    assertTrue( schemaManager.add( bc ) );

    LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );

    assertNotNull( added );
    assertEquals( bc.getClass().getName(), added.getFqcn() );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );
    assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    LdapComparator<?> lc = new CsnComparator( oid );

    assertFalse( schemaManager.add( lc ) );

    errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );

    assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    added = schemaManager.lookupComparatorRegistry( oid );

    assertNotNull( added );
    assertEquals( bc.getClass().getName(), added.getFqcn() );
}
 
Example 7
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test that we can't add two comparators with the same class code.
 */
@Test
public void testAddComparatorWithWrongFQCN() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    LdapComparator<?> lc = new BooleanComparator( oid );

    // using java.sql.ResultSet cause it is very unlikely to get loaded
    // in ADS, as the FQCN is not the one expected
    lc.setFqcn( "java.sql.ResultSet" );

    assertFalse( schemaManager.add( lc ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );

    assertEquals( ctrSize, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    try
    {
        schemaManager.lookupComparatorRegistry( oid );
        fail();
    }
    catch ( Exception e )
    {
        // Expected
        assertTrue( true );
    }
}
 
Example 8
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Check that a Comparator which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingComparatorUsedByRemovedMatchingRule() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String OID = "2.5.13.33";

    // Check that the MR and C are present
    assertTrue( isMatchingRulePresent( schemaManager, OID ) );
    assertTrue( isComparatorPresent( schemaManager, OID ) );

    // Now try to remove the C
    LdapComparator<?> lc = schemaManager.lookupComparatorRegistry( OID );

    // shouldn't be deleted cause there is a MR associated with it
    assertFalse( schemaManager.delete( lc ) );

    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( OID );
    assertTrue( schemaManager.delete( mr ) );

    assertEquals( mrrSize - 1, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );

    assertFalse( isMatchingRulePresent( schemaManager, OID ) );

    // and try to delete the Comparator again
    assertTrue( schemaManager.delete( lc ) );

    assertFalse( isComparatorPresent( schemaManager, OID ) );
    assertEquals( ctrSize - 1, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
}