Java Code Examples for org.apache.directory.api.ldap.model.entry.Attribute#setUpId()

The following examples show how to use org.apache.directory.api.ldap.model.entry.Attribute#setUpId() . 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: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method getId()
 */
@Test
public void testGetId()
{
    Attribute attr = new DefaultAttribute( atCN );

    assertEquals( "2.5.4.3", attr.getId() );

    attr.setUpId( "  CN  " );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( "  CN  ", attr.getUpId() );

    attr.setUpId( "  CommonName  " );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( "  CommonName  ", attr.getUpId() );

    attr.setUpId( "  2.5.4.3  " );
    assertEquals( "2.5.4.3", attr.getId() );
}
 
Example 2
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method getUpId
 */
@Test
public void testGetUpId()
{
    Attribute attr = new DefaultAttribute( atCN );

    assertNotNull( attr.getUpId() );
    assertEquals( "cn", attr.getUpId() );

    attr.setUpId( "CN" );
    assertEquals( "CN", attr.getUpId() );

    attr.setUpId( "  Cn  " );
    assertEquals( "  Cn  ", attr.getUpId() );

    attr.setUpId( "  2.5.4.3  " );
    assertEquals( "  2.5.4.3  ", attr.getUpId() );
}
 
Example 3
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method toString
 */
@Test
public void testToString() throws LdapException
{
    Attribute attr = new DefaultAttribute( atEMail );

    assertEquals( "email: (null)", attr.toString() );

    attr.setUpId( "EMail" );
    assertEquals( "EMail: (null)", attr.toString() );

    attr.add( ( String ) null );
    assertEquals( "EMail: ''", attr.toString() );

    attr.clear();
    attr.add( "a", "b" );
    assertEquals( "EMail: a\nEMail: b", attr.toString() );
}
 
Example 4
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test method testClone()
 */
@Test
public void testClone() throws LdapException
{
    Attribute attr = new DefaultAttribute( atDC );

    Attribute clone = attr.clone();

    assertEquals( attr, clone );
    attr.setUpId( "DomainComponent" );
    assertEquals( "0.9.2342.19200300.100.1.25", clone.getId() );

    attr.add( "a", ( String ) null, "b" );
    clone = attr.clone();
    assertEquals( attr, clone );

    attr.remove( "a" );
    assertNotSame( attr, clone );

    clone = attr.clone();
    assertEquals( attr, clone );
}
 
Example 5
Source File: RangedAttributeInterceptor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private Entry prepareEntry(Entry e) {
    Attribute attr = e.get(name);
    if (attr != null) {
        int start = (min != null)? min : 0;
        start = (start < attr.size())? start : attr.size() - 1;
        int end = (max != null && max < attr.size() - 1)? max : attr.size() - 1;
        if (start != 0 || end != attr.size() - 1) {
            // some values should be stripped out
            Iterator<Value> it = attr.iterator();
            Set<Value> valuesToRemove = new HashSet<>(end - start + 1);
            for (int i = 0; i < attr.size(); i++) {
                Value v = it.next();
                if (i < start || i > end) {
                    valuesToRemove.add(v);
                }
            }
            attr.setUpId(attr.getUpId() + ";range=" + start + "-" + ((end == attr.size() - 1)? "*" : end));
            attr.remove(valuesToRemove.toArray(new Value[0]));
        } else if (min != null) {
            // range explicitly requested although no value stripped
            attr.setUpId(attr.getUpId() + ";range=0-*");
        }
    }
    return e;
}
 
Example 6
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test method SetId(String)
 */
@Test
public void testSetId()
{
    Attribute attr = new DefaultAttribute( atCN );

    attr.setUpId( "Cn" );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( "Cn", attr.getUpId() );

    attr.setUpId( " CN " );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( " CN ", attr.getUpId() );

    attr.setUpId( " 2.5.4.3 " );
    assertEquals( " 2.5.4.3 ", attr.getUpId() );
    assertEquals( "2.5.4.3", attr.getId() );

    attr.setUpId( " commonName " );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( " commonName ", attr.getUpId() );

    attr.setUpId( null );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( "cn", attr.getUpId() );

    attr.setUpId( "" );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( "cn", attr.getUpId() );

    attr.setUpId( "  " );
    assertEquals( "2.5.4.3", attr.getId() );
    assertEquals( "cn", attr.getUpId() );

    try
    {
        attr.setUpId( " SN " );
        fail();
    }
    catch ( IllegalArgumentException iae )
    {
        assertTrue( true );
    }
}
 
Example 7
Source File: SchemaAwareAttributeTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test method testEquals()
 */
@Test
public void testEquals() throws LdapException
{
    Attribute attr1 = new DefaultAttribute( atCN );

    assertFalse( attr1.equals( null ) );

    Attribute attr2 = new DefaultAttribute( atCN );

    assertTrue( attr1.equals( attr2 ) );

    attr2.setUpId( "CN" );
    assertTrue( attr1.equals( attr2 ) );

    attr1.setUpId( "CommonName" );
    assertTrue( attr1.equals( attr2 ) );

    attr1.setUpId( "CN" );
    assertTrue( attr1.equals( attr2 ) );

    attr1.add( "a", "b", "c" );
    attr2.add( "c", "b", "a" );
    assertTrue( attr1.equals( attr2 ) );

    assertTrue( attr1.equals( attr2 ) );

    Attribute attr3 = new DefaultAttribute( atPwd );
    Attribute attr4 = new DefaultAttribute( atPwd );

    attr3.add( nullBinaryValue );
    attr4.add( nullBinaryValue );
    assertTrue( attr3.equals( attr4 ) );

    Attribute attr5 = new DefaultAttribute( atPwd );
    Attribute attr6 = new DefaultAttribute( atDC );
    assertFalse( attr5.equals( attr6 ) );

    attr5.add( nullBinaryValue );
    attr6.add( nullStringValue );
    assertFalse( attr5.equals( attr6 ) );

    Attribute attr7 = new DefaultAttribute( atCN );
    Attribute attr8 = new DefaultAttribute( atPwd );

    attr7.add( "a" );
    attr8.add( BYTES2 );
    assertFalse( attr7.equals( attr8 ) );

    Attribute attr9 = new DefaultAttribute( atCN );
    Attribute attr10 = new DefaultAttribute( atPwd );

    attr9.add( "a" );
    attr9.add( BYTES2 );
    attr10.add( "a", "b" );
    assertFalse( attr9.equals( attr10 ) );

    Attribute attr11 = new DefaultAttribute( atPwd, BYTES1 );
    Attribute attr12 = new DefaultAttribute( atPwd, BYTES1 );

    assertTrue( attr11.get().equals( attr12.get() ) );
    assertTrue( attr12.get().equals( attr11.get() ) );

    Attribute attr13 = new DefaultAttribute( "userPassword", BYTES1 );

    assertTrue( attr11.get().equals( attr13.get() ) );
    assertTrue( attr13.get().equals( attr11.get() ) );

    Attribute attr14 = new DefaultAttribute( "userPassword", BYTES1 );

    assertTrue( attr14.get().equals( attr13.get() ) );
    assertTrue( attr13.get().equals( attr14.get() ) );
}