Java Code Examples for org.apache.directory.api.ldap.model.entry.DefaultAttribute#add()
The following examples show how to use
org.apache.directory.api.ldap.model.entry.DefaultAttribute#add() .
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 public void testGetAttribute() throws Exception { AttributeType at = TestEntryUtils.getIA5StringAttributeType(); DefaultAttribute attr = new DefaultAttribute( at ); attr.add( "Test1" ); attr.add( "Test2" ); attr.add( "Test3" ); assertEquals( "1.1", attr.getId() ); assertEquals( 3, attr.size() ); assertTrue( attr.contains( "Test1" ) ); assertTrue( attr.contains( "Test2" ) ); assertTrue( attr.contains( "Test3" ) ); }
Example 2
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the contains() method */ @Test public void testContains() throws Exception { AttributeType at = TestEntryUtils.getIA5StringAttributeType(); DefaultAttribute attr = new DefaultAttribute( at ); attr.add( "Test 1" ); attr.add( "Test 2" ); attr.add( "Test 3" ); assertTrue( attr.contains( "test 1" ) ); assertTrue( attr.contains( "Test 2" ) ); assertTrue( attr.contains( "TEST 3" ) ); }
Example 3
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the serialization of a complete server attribute */ @Test public void testSerializeCompleteAttribute() throws LdapException, IOException, ClassNotFoundException { DefaultAttribute dsa = new DefaultAttribute( atCN ); dsa.setUpId( "CommonName" ); dsa.add( "test1", "test2" ); DefaultAttribute dsaSer = deserializeValue( serializeValue( dsa ), atCN ); assertEquals( dsa.toString(), dsaSer.toString() ); assertEquals( "2.5.4.3", dsaSer.getId() ); assertEquals( "CommonName", dsaSer.getUpId() ); assertEquals( "test1", dsaSer.getString() ); assertTrue( dsaSer.contains( "test2", "test1" ) ); assertTrue( dsaSer.isHumanReadable() ); }
Example 4
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the serialization of a server attribute with a null value */ @Test public void testSerializeAttributeNullValue() throws LdapException, IOException, ClassNotFoundException { DefaultAttribute dsa = new DefaultAttribute( atDC ); dsa.setUpId( "DomainComponent" ); dsa.add( ( String ) null ); DefaultAttribute dsaSer = deserializeValue( serializeValue( dsa ), atDC ); assertEquals( dsa.toString(), dsaSer.toString() ); assertEquals( "0.9.2342.19200300.100.1.25", dsaSer.getId() ); assertEquals( "DomainComponent", dsaSer.getUpId() ); assertNull( dsaSer.getString() ); assertEquals( 1, dsaSer.size() ); assertTrue( dsaSer.contains( ( String ) null ) ); assertTrue( dsaSer.isHumanReadable() ); }
Example 5
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Test the serialization of a server attribute with a binary value */ @Test public void testSerializeAttributeBinaryValue() throws LdapException, IOException, ClassNotFoundException { DefaultAttribute dsa = new DefaultAttribute( atPwd ); byte[] password = Strings.getBytesUtf8( "secret" ); dsa.add( password ); DefaultAttribute dsaSer = deserializeValue( serializeValue( dsa ), atPwd ); assertEquals( dsa.toString(), dsaSer.toString() ); assertEquals( "2.5.4.35", dsaSer.getId() ); assertEquals( "userPassword", dsaSer.getUpId() ); assertTrue( Arrays.equals( dsa.getBytes(), dsaSer.getBytes() ) ); assertEquals( 1, dsaSer.size() ); assertTrue( dsaSer.contains( password ) ); assertFalse( dsaSer.isHumanReadable() ); }
Example 6
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
@Test public void testAddTwoValue() throws Exception { AttributeType at = TestEntryUtils.getIA5StringAttributeType(); DefaultAttribute attr = new DefaultAttribute( at ); // Add String values attr.add( "test" ); attr.add( "test2" ); assertEquals( 2, attr.size() ); assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() ); Set<String> expected = new HashSet<String>(); expected.add( "test" ); expected.add( "test2" ); for ( Value val : attr ) { if ( expected.contains( val.getString() ) ) { expected.remove( val.getString() ); } else { fail(); } } assertEquals( 0, expected.size() ); }
Example 7
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
@Test public void testAddOneValue() throws Exception { AttributeType at = TestEntryUtils.getIA5StringAttributeType(); DefaultAttribute attr = new DefaultAttribute( at ); // Add a String value attr.add( "test" ); assertEquals( 1, attr.size() ); assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() ); Value value = attr.get(); assertTrue( value instanceof Value ); assertEquals( "test", ( ( Value ) value ).getString() ); // Add a binary value assertEquals( 0, attr.add( new byte[] { 0x01 } ) ); // Add a Value Value ssv = new Value( at, "test2" ); attr.add( ssv ); assertEquals( 2, attr.size() ); Set<String> expected = new HashSet<String>(); expected.add( "test" ); expected.add( "test2" ); for ( Value val : attr ) { if ( expected.contains( val.getString() ) ) { expected.remove( val.getString() ); } else { fail(); } } assertEquals( 0, expected.size() ); }
Example 8
Source File: SchemaAwareAttributeTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
@Test public void testAddNullValue() throws Exception { AttributeType at = TestEntryUtils.getIA5StringAttributeType(); DefaultAttribute attr = new DefaultAttribute( at ); // Add a null value attr.add( new Value( at, (String)null ) ); assertEquals( 1, attr.size() ); assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() ); Value value = attr.get(); assertTrue( value instanceof Value ); assertNull( ( ( Value ) value ).getString() ); }
Example 9
Source File: MyVDCursor.java From MyVirtualDirectory with Apache License 2.0 | 3 votes |
@Override public Entry get() throws CursorException { try { LDAPEntry nentry = null; if (buffer != null) { nentry = buffer.getEntry(); buffer = null; } else { nentry = res.next().getEntry(); } Entry entry = new DefaultEntry(); entry.setDn(nentry.getDN()); LDAPAttributeSet attrs = nentry.getAttributeSet(); for (Object o : attrs) { LDAPAttribute a = (LDAPAttribute) o; String oid = ""; AttributeType at; byte[][] vals = a.getByteValueArray(); DefaultAttribute attr = new DefaultAttribute(a.getName()); attr.add(vals); entry.add(attr); } return entry; } catch (Exception e) { throw new CursorException(e); } }