Java Code Examples for org.apache.directory.api.ldap.model.entry.Entry#iterator()

The following examples show how to use org.apache.directory.api.ldap.model.entry.Entry#iterator() . 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: SchemaAwareEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for Iterator()
 */
@Test
public void testIterator() throws LdapException
{
    Entry entry = createEntry();

    Iterator<Attribute> iterator = entry.iterator();

    assertTrue( iterator.hasNext() );

    Set<String> expectedIds = new HashSet<String>();
    expectedIds.add( "objectclass" );
    expectedIds.add( "cn" );
    expectedIds.add( "sn" );
    expectedIds.add( "userpassword" );

    while ( iterator.hasNext() )
    {
        Attribute attribute = iterator.next();

        String id = attribute.getId();
        assertTrue( expectedIds.contains( id ) );
        expectedIds.remove( id );
    }

    assertEquals( 0, expectedIds.size() );
}
 
Example 2
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithoutValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_without_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertFalse( valueIterator.hasNext() );
}
 
Example 3
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with empty value
 */
@Test
public void testRequestWith1AttrEmptyValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_empty_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertFalse( valueIterator.hasNext() );
}
 
Example 4
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
}
 
Example 5
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with an Attr elements with value
 */
@Test
public void testRequestWith1AttrWithBase64Value()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_base64_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertFalse( value.isHumanReadable() );
    assertEquals( "DSMLv2.0 rocks!!", value.getString() );
}
 
Example 6
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 2 Attr elements with value
 */
@Test
public void testRequestWith2AttrWithValue()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_2_attr_with_value.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "person", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
Example 7
Source File: AddRequestTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a request with 1 Attr element with 2 Values
 */
@Test
public void testRequestWith1AttrWith2Values()
{
    Dsmlv2Parser parser = null;
    try
    {
        parser = newParser();

        parser.setInput( AddRequestTest.class.getResource( "request_with_1_attr_with_2_values.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddRequest addRequest = ( AddRequest ) parser.getBatchRequest().getCurrentRequest();

    Entry entry = addRequest.getEntry();
    assertEquals( 1, entry.size() );

    // Getting the Attribute
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );

    // Getting the Value
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "person", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
Example 8
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 0 Value
 */
@Test
public void testResponseWith1Attr0Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            SearchResultEntryTest.class.getResource( "response_with_1_attr_0_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "dc", attribute.getUpId() );
}
 
Example 9
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 1 Value
 */
@Test
public void testResponseWith1Attr1Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            SearchResultEntryTest.class.getResource( "response_with_1_attr_1_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "dc", attribute.getUpId() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "example", value.getString() );
}
 
Example 10
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 1 Base64 Value
 */
@Test
public void testResponseWith1Attr1Base64Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( SearchResultEntryTest.class.getResource( "response_with_1_attr_1_base64_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "cn", attribute.getUpId() );
    assertEquals( 1, attribute.size() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();

    String expected = new String( new byte[]
        { 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', 'L', ( byte ) 0xc3, ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n',
            'y' }, StandardCharsets.UTF_8 );
    assertEquals( expected, value.getString() );
}
 
Example 11
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 1 empty Value
 */
@Test
public void testResponseWith1Attr1EmptyValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( SearchResultEntryTest.class.getResource( "response_with_1_attr_1_empty_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "dc", attribute.getUpId() );
    assertEquals( 1, attribute.size() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "", value.getString() );
}
 
Example 12
Source File: SearchResultEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 1 Attr 2 Value
 */
@Test
public void testResponseWith1Attr2Value()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            SearchResultEntryTest.class.getResource( "response_with_1_attr_2_value.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    SearchResultEntry searchResultEntry = ( ( SearchResponse ) parser.getBatchResponse().getCurrentResponse()
        .getDecorated() )
        .getCurrentSearchResultEntry();

    Entry entry = searchResultEntry.getEntry();
    assertEquals( 1, entry.size() );

    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals( "objectclass", attribute.getUpId() );
    assertEquals( 2, attribute.size() );

    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue( valueIterator.hasNext() );
    Value value = valueIterator.next();
    assertEquals( "top", value.getString() );
    assertTrue( valueIterator.hasNext() );
    value = valueIterator.next();
    assertEquals( "domain", value.getString() );
    assertFalse( valueIterator.hasNext() );
}
 
Example 13
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void modify( Entry entry, ModificationOperation modOp ) throws LdapException
{
    if ( entry == null )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_04140_NULL_ENTRY_MODIFY ) );
        }
        
        throw new IllegalArgumentException( I18n.err( I18n.ERR_04133_NULL_MODIFIED_ENTRY ) );
    }

    ModifyRequest modReq = new ModifyRequestImpl();
    modReq.setName( entry.getDn() );

    Iterator<Attribute> itr = entry.iterator();

    while ( itr.hasNext() )
    {
        modReq.addModification( itr.next(), modOp );
    }

    ModifyResponse modifyResponse = modify( modReq );

    processResponse( modifyResponse );
}