Java Code Examples for org.apache.directory.api.ldap.model.entry.Attribute#iterator()
The following examples show how to use
org.apache.directory.api.ldap.model.entry.Attribute#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: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test method iterator() */ @Test public void testIterator() throws LdapException { Attribute attr1 = new DefaultAttribute( atCN ); attr1.add( "a", "b", "c" ); Iterator<Value> iter = attr1.iterator(); assertTrue( iter.hasNext() ); String[] values = new String[] { "a", "b", "c" }; int pos = 0; for ( Value val : attr1 ) { assertTrue( val instanceof Value ); assertEquals( values[pos++], val.getString() ); } }
Example 2
Source File: RangedAttributeInterceptor.java From keycloak with Apache License 2.0 | 6 votes |
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 3
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test method getAll() */ @Test public void testIterator2() throws LdapException { Attribute attr = new DefaultAttribute( atEMail ); Iterator<Value> iterator = attr.iterator(); assertFalse( iterator.hasNext() ); attr.add( nullStringValue ); iterator = attr.iterator(); assertTrue( iterator.hasNext() ); Value value = iterator.next(); assertEquals( nullStringValue, value ); attr.clear(); iterator = attr.iterator(); assertFalse( iterator.hasNext() ); attr.add( "a", "b", "c" ); iterator = attr.iterator(); assertTrue( iterator.hasNext() ); assertEquals( "a", iterator.next().getString() ); assertEquals( "b", iterator.next().getString() ); assertEquals( "c", iterator.next().getString() ); assertFalse( iterator.hasNext() ); }
Example 4
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: AddRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 10
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 13
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 14
Source File: SearchResultEntryTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test parsing of a response with 2 Attr 1 Value */ @Test public void testResponseWith2Attr1Value() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( SearchResultEntryTest.class.getResource( "response_with_2_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( 2, entry.size() ); Attribute objectClassAttribute = entry.get( "objectclass" ); assertEquals( 1, objectClassAttribute.size() ); Iterator<Value> valueIterator = objectClassAttribute.iterator(); assertTrue( valueIterator.hasNext() ); Value value = valueIterator.next(); assertEquals( "top", value.getString() ); assertFalse( valueIterator.hasNext() ); Attribute dcAttribute = entry.get( "dc" ); assertEquals( 1, objectClassAttribute.size() ); valueIterator = dcAttribute.iterator(); assertTrue( valueIterator.hasNext() ); value = valueIterator.next(); assertEquals( "example", value.getString() ); assertFalse( valueIterator.hasNext() ); }