类javax.naming.directory.InvalidAttributeValueException源码实例Demo

下面列出了怎么用javax.naming.directory.InvalidAttributeValueException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method getString()
 */
@Test
public void testGetString() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    attr1.add( ( String ) null );
    assertEquals( null, attr1.getString() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( "a", "b" );
    assertEquals( "a", attr2.getString() );

    Attribute attr3 = new DefaultAttribute( "test" );

    attr3.add( BYTES1, BYTES2 );

    assertEquals( "ab", attr3.getString() );
}
 
源代码2 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method clear()
 */
@Test
public void testClear() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( 0, attr1.size() );

    attr1.add( ( String ) null );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.isHumanReadable() );
    attr1.clear();
    assertTrue( attr1.isHumanReadable() );
    assertEquals( 0, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );
    attr2.add( BYTES1, BYTES2 );
    assertEquals( 2, attr2.size() );
    assertFalse( attr2.isHumanReadable() );
    attr2.clear();
    assertFalse( attr2.isHumanReadable() );
    assertEquals( 0, attr2.size() );
}
 
源代码3 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method size()
 */
@Test
public void testSize() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( 0, attr1.size() );

    attr1.add( ( String ) null );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( "a", "b" );
    assertEquals( 2, attr2.size() );

    attr2.clear();
    assertEquals( 0, attr2.size() );
}
 
源代码4 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method toString()
 */
@Test
public void testToString() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( "test: (null)", attr1.toString() );

    attr1.add( "a" );
    assertEquals( "test: a", attr1.toString() );

    attr1.add( "b" );
    assertEquals( "test: a\ntest: b", attr1.toString() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( BYTES1 );
    assertEquals( "test: 0x61 0x62 ", attr2.toString() );

    attr2.add( BYTES3 );
    assertEquals( "test: 0x61 0x62 \ntest: 0x63 ", attr2.toString() );
}
 
源代码5 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method getBytes()
 */
@Test
public void testGetBytes() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    attr1.add( ( byte[] ) null );
    assertNull( attr1.getBytes() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( BYTES1, BYTES2 );
    assertTrue( Arrays.equals( BYTES1, attr2.getBytes() ) );

    Attribute attr3 = new DefaultAttribute( "test" );

    attr3.add( "a", "b" );

    try
    {
        attr3.getBytes();
        fail();
    }
    catch ( LdapInvalidAttributeValueException ivae )
    {
        assertTrue( true );
    }
}
 
源代码6 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method get()
 */
@Test
public void testGet() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    attr1.add( ( String ) null );
    assertEquals( NULL_STRING_VALUE, attr1.get() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( "a", "b", "c" );
    assertEquals( "a", attr2.get().getString() );

    attr2.remove( "a" );
    assertEquals( "b", attr2.get().getString() );

    attr2.remove( "b" );
    assertEquals( "c", attr2.get().getString() );

    attr2.remove( "c" );
    assertNull( attr2.get() );

    Attribute attr3 = new DefaultAttribute( "test" );

    attr3.add( BYTES1, BYTES2, BYTES3 );
    assertTrue( Arrays.equals( BYTES1, attr3.get().getBytes() ) );

    attr3.remove( BYTES1 );
    assertTrue( Arrays.equals( BYTES2, attr3.get().getBytes() ) );

    attr3.remove( BYTES2 );
    assertTrue( Arrays.equals( BYTES3, attr3.get().getBytes() ) );

    attr3.remove( BYTES3 );
    assertNull( attr2.get() );
}
 
源代码7 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method remove( byte... )
 */
@Test
public void testRemoveByteArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertFalse( attr1.remove( BYTES1 ) );

    attr1.add( BYTES1, BYTES2, BYTES3 );
    assertTrue( attr1.remove( BYTES1 ) );
    assertEquals( 2, attr1.size() );

    assertTrue( attr1.remove( BYTES2, BYTES3 ) );
    assertEquals( 0, attr1.size() );

    assertFalse( attr1.remove( BYTES4 ) );

    attr1.clear();
    attr1.add( BYTES1, BYTES2, BYTES3 );
    assertFalse( attr1.remove( BYTES3, BYTES4 ) );
    assertEquals( 2, attr1.size() );

    attr1.clear();
    attr1.add( BYTES1, ( byte[] ) null, BYTES2 );
    assertTrue( attr1.remove( ( byte[] ) null, BYTES1 ) );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( "ab", "b", "c" );

    assertFalse( attr2.remove( ( byte[] ) null ) );
    assertTrue( attr2.remove( BYTES1, BYTES2 ) );
    assertFalse( attr2.remove( BYTES4 ) );
}
 
源代码8 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method remove( String... )
 */
@Test
public void testRemoveStringArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertFalse( attr1.remove( "a" ) );

    attr1.add( "a", "b", "c" );
    assertTrue( attr1.remove( "a" ) );
    assertEquals( 2, attr1.size() );

    assertTrue( attr1.remove( "b", "c" ) );
    assertEquals( 0, attr1.size() );

    assertFalse( attr1.remove( "d" ) );

    attr1.clear();
    attr1.add( "a", "b", "c" );
    assertFalse( attr1.remove( "b", "e" ) );
    assertEquals( 2, attr1.size() );

    attr1.clear();
    attr1.add( "a", ( String ) null, "b" );
    assertTrue( attr1.remove( ( String ) null, "a" ) );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( BYTES1, BYTES2, BYTES3 );

    assertFalse( attr2.remove( ( String ) null ) );
    assertTrue( attr2.remove( "ab", "c" ) );
    assertFalse( attr2.remove( "d" ) );
}
 
源代码9 项目: mamute   文件: LDAPApi.java
private byte[] getAvatarImage(LDAPResource ldap, Entry entry) throws LdapException {
	if (avatarImageAttr != null && avatarImageAttr.length() > 0) {
		try {
			return ldap.getByteAttribute(entry, avatarImageAttr);
		} catch (InvalidAttributeValueException ex) {
			throw new LdapException("Invalid attribute value while looking up " + avatarImageAttr, ex);
		}
	}
	return null;
}
 
源代码10 项目: mamute   文件: LDAPApi.java
private byte[] getByteAttribute(Entry entry, String attribute) throws LdapException, InvalidAttributeValueException {
	Attribute value = entry.get(attribute);
	if (value != null) {
		return value.getBytes();
	}
	return null;
}
 
源代码11 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method add(Value...)
 */
@Test
public void testAddValueArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    int nbAdded = attr1.add( new Value( ( String ) null ) );
    assertEquals( 1, nbAdded );
    assertTrue( attr1.isHumanReadable() );
    assertEquals( NULL_STRING_VALUE, attr1.get() );

    Attribute attr2 = new DefaultAttribute( "test" );

    nbAdded = attr2.add( new Value( ( byte[] ) null ) );
    assertEquals( 1, nbAdded );
    assertFalse( attr2.isHumanReadable() );
    assertEquals( NULL_BINARY_VALUE, attr2.get() );

    Attribute attr3 = new DefaultAttribute( "test" );

    nbAdded = attr3.add( new Value( "a" ), new Value( "b" ) );
    assertEquals( 2, nbAdded );
    assertTrue( attr3.isHumanReadable() );
    assertTrue( attr3.contains( "a" ) );
    assertTrue( attr3.contains( "b" ) );

    Attribute attr4 = new DefaultAttribute( "test" );

    nbAdded = attr4.add( new Value( BYTES1 ), new Value( BYTES2 ) );
    assertEquals( 2, nbAdded );
    assertFalse( attr4.isHumanReadable() );
    assertTrue( attr4.contains( BYTES1 ) );
    assertTrue( attr4.contains( BYTES2 ) );

    Attribute attr5 = new DefaultAttribute( "test" );

    nbAdded = attr5.add( new Value( "c" ), new Value( BYTES1 ) );
    assertEquals( 2, nbAdded );
    assertTrue( attr5.isHumanReadable() );
    assertTrue( attr5.contains( "ab" ) );
    assertTrue( attr5.contains( "c" ) );

    Attribute attr6 = new DefaultAttribute( "test" );

    nbAdded = attr6.add( new Value( BYTES1 ), new Value( "c" ) );
    assertEquals( 2, nbAdded );
    assertFalse( attr6.isHumanReadable() );
    assertTrue( attr6.contains( BYTES1 ) );
    assertTrue( attr6.contains( BYTES3 ) );

    Attribute attr7 = new DefaultAttribute( "test" );

    nbAdded = attr7.add( new Value( ( byte[] ) null ), new Value( "c" ) );
    assertEquals( 2, nbAdded );
    assertFalse( attr7.isHumanReadable() );
    assertTrue( attr7.contains( NULL_BINARY_VALUE ) );
    assertTrue( attr7.contains( BYTES3 ) );

    Attribute attr8 = new DefaultAttribute( "test" );

    nbAdded = attr8.add( new Value( ( String ) null ), new Value( BYTES1 ) );
    assertEquals( 2, nbAdded );
    assertTrue( attr8.isHumanReadable() );
    assertTrue( attr8.contains( NULL_STRING_VALUE ) );
    assertTrue( attr8.contains( "ab" ) );
}
 
源代码12 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method add( String... )
 */
@Test
public void testAddStringArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );
    assertEquals( 0, attr1.size() );

    int nbAdded = attr1.add( ( String ) null );
    assertEquals( 1, nbAdded );
    assertTrue( attr1.isHumanReadable() );
    assertEquals( NULL_STRING_VALUE, attr1.get() );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    nbAdded = attr2.add( "" );
    assertEquals( 1, nbAdded );
    assertTrue( attr2.isHumanReadable() );
    assertEquals( "", attr2.getString() );
    assertEquals( 1, attr2.size() );

    Attribute attr3 = new DefaultAttribute( "test" );

    nbAdded = attr3.add( "t" );
    assertEquals( 1, nbAdded );
    assertTrue( attr3.isHumanReadable() );
    assertEquals( "t", attr3.getString() );

    Attribute attr4 = new DefaultAttribute( "test" );

    nbAdded = attr4.add( "a", "b", "c", "d" );
    assertEquals( 4, nbAdded );
    assertTrue( attr4.isHumanReadable() );
    assertEquals( "a", attr4.getString() );
    assertTrue( attr4.contains( "a" ) );
    assertTrue( attr4.contains( "b" ) );
    assertTrue( attr4.contains( "c" ) );
    assertTrue( attr4.contains( "d" ) );

    nbAdded = attr4.add( "e" );
    assertEquals( 1, nbAdded );
    assertTrue( attr4.isHumanReadable() );
    assertEquals( "a", attr4.getString() );
    assertTrue( attr4.contains( "a" ) );
    assertTrue( attr4.contains( "b" ) );
    assertTrue( attr4.contains( "c" ) );
    assertTrue( attr4.contains( "d" ) );
    assertTrue( attr4.contains( "e" ) );

    nbAdded = attr4.add( BYTES1 );
    assertEquals( 0, nbAdded );
    assertTrue( attr4.isHumanReadable() );
    assertEquals( "a", attr4.getString() );
    assertTrue( attr4.contains( "a" ) );
    assertTrue( attr4.contains( "b" ) );
    assertTrue( attr4.contains( "c" ) );
    assertTrue( attr4.contains( "d" ) );
    assertTrue( attr4.contains( "e" ) );
    assertFalse( attr4.contains( "ab" ) );

    Attribute attr5 = new DefaultAttribute( "test" );

    nbAdded = attr5.add( "a", "b", ( String ) null, "d" );
    assertEquals( 4, nbAdded );
    assertTrue( attr5.isHumanReadable() );
    assertTrue( attr5.contains( "a" ) );
    assertTrue( attr5.contains( "b" ) );
    assertTrue( attr5.contains( ( String ) null ) );
    assertTrue( attr5.contains( "d" ) );

    Attribute attr6 = new DefaultAttribute( "test" );

    nbAdded = attr6.add( "a", ( String ) null );
    assertEquals( 2, nbAdded );
    assertTrue( attr6.isHumanReadable() );
    assertTrue( attr6.contains( "a" ) );
    assertTrue( attr6.contains( ( String ) null ) );

    Attribute attr7 = new DefaultAttribute( "test" );

    attr7.add( "a", "b" );
    assertEquals( 2, attr7.size() );

    assertEquals( 1, attr7.add( "b", "c" ) );
    assertEquals( 3, attr7.size() );
    assertTrue( attr7.contains( "a", "b", "c" ) );
}
 
源代码13 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method add( byte[]... )
 */
@Test
public void testAddByteArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );
    assertEquals( 0, attr1.size() );

    int nbAdded = attr1.add( ( byte[] ) null );
    assertEquals( 1, nbAdded );
    assertFalse( attr1.isHumanReadable() );
    assertTrue( Arrays.equals( NULL_BINARY_VALUE.getBytes(), attr1.getBytes() ) );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    nbAdded = attr2.add( Strings.EMPTY_BYTES );
    assertEquals( 1, nbAdded );
    assertFalse( attr2.isHumanReadable() );
    assertTrue( Arrays.equals( Strings.EMPTY_BYTES, attr2.getBytes() ) );
    assertEquals( 1, attr2.size() );

    Attribute attr3 = new DefaultAttribute( "test" );

    nbAdded = attr3.add( BYTES1 );
    assertEquals( 1, nbAdded );
    assertFalse( attr3.isHumanReadable() );
    assertTrue( Arrays.equals( BYTES1, attr3.getBytes() ) );

    Attribute attr4 = new DefaultAttribute( "test" );

    nbAdded = attr4.add( BYTES1, BYTES2, BYTES3, BYTES4 );
    assertEquals( 4, nbAdded );
    assertFalse( attr4.isHumanReadable() );
    assertTrue( attr4.contains( BYTES1 ) );
    assertTrue( attr4.contains( BYTES2 ) );
    assertTrue( attr4.contains( BYTES3 ) );
    assertTrue( attr4.contains( BYTES4 ) );

    Attribute attr5 = new DefaultAttribute( "test" );

    nbAdded = attr5.add( BYTES1, BYTES2, ( byte[] ) null, BYTES3 );
    assertEquals( 4, nbAdded );
    assertFalse( attr5.isHumanReadable() );
    assertTrue( attr5.contains( BYTES1 ) );
    assertTrue( attr5.contains( BYTES2 ) );
    assertTrue( attr5.contains( ( byte[] ) null ) );
    assertTrue( attr5.contains( BYTES3 ) );

    Attribute attr6 = new DefaultAttribute( "test" );

    nbAdded = attr6.add( BYTES1, ( byte[] ) null );
    assertEquals( 2, nbAdded );
    assertFalse( attr6.isHumanReadable() );
    assertTrue( attr6.contains( "ab" ) );
    assertTrue( attr6.contains( ( byte[] ) null ) );
}
 
源代码14 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method contains( Value... )
 */
@Test
public void testContainsValueArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( 0, attr1.size() );
    assertFalse( attr1.contains( STR_VALUE1 ) );
    assertFalse( attr1.contains( NULL_STRING_VALUE ) );

    attr1.add( ( String ) null );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.contains( NULL_STRING_VALUE ) );

    attr1.remove( ( String ) null );
    assertFalse( attr1.contains( NULL_STRING_VALUE ) );
    assertEquals( 0, attr1.size() );

    attr1.add( "a", "b", "c" );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( STR_VALUE1 ) );
    assertTrue( attr1.contains( STR_VALUE2 ) );
    assertTrue( attr1.contains( STR_VALUE3 ) );
    assertTrue( attr1.contains( STR_VALUE1, STR_VALUE3 ) );
    assertFalse( attr1.contains( STR_VALUE4 ) );
    assertFalse( attr1.contains( NULL_STRING_VALUE ) );
    assertTrue( attr1.contains( STR_VALUE1, BIN_VALUE2 ) );

    Attribute attr2 = new DefaultAttribute( "test" );
    assertEquals( 0, attr2.size() );
    assertFalse( attr2.contains( BYTES1 ) );
    assertFalse( attr2.contains( NULL_BINARY_VALUE ) );

    attr2.add( ( byte[] ) null );
    assertEquals( 1, attr2.size() );
    assertTrue( attr2.contains( NULL_BINARY_VALUE ) );

    attr2.remove( ( byte[] ) null );
    assertFalse( attr2.contains( NULL_BINARY_VALUE ) );
    assertEquals( 0, attr2.size() );

    attr2.add( BYTES1, BYTES2, BYTES3 );
    assertEquals( 3, attr2.size() );
    assertTrue( attr2.contains( BIN_VALUE1 ) );
    assertTrue( attr2.contains( BIN_VALUE2 ) );
    assertTrue( attr2.contains( BIN_VALUE3 ) );
    assertFalse( attr2.contains( NULL_BINARY_VALUE ) );
    assertTrue( attr2.contains( STR_VALUE2, BIN_VALUE1 ) );
}
 
源代码15 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method contains( String... )
 */
@Test
public void testContainsStringArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( 0, attr1.size() );
    assertFalse( attr1.contains( "a" ) );
    assertFalse( attr1.contains( ( String ) null ) );

    attr1.add( ( String ) null );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.contains( ( String ) null ) );

    attr1.remove( ( String ) null );
    assertFalse( attr1.contains( ( String ) null ) );
    assertEquals( 0, attr1.size() );

    attr1.add( "a", "b", "c" );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( "a" ) );
    assertTrue( attr1.contains( "b" ) );
    assertTrue( attr1.contains( "c" ) );
    assertFalse( attr1.contains( "e" ) );
    assertFalse( attr1.contains( ( String ) null ) );

    Attribute attr2 = new DefaultAttribute( "test" );
    assertEquals( 0, attr2.size() );
    assertFalse( attr2.contains( BYTES1 ) );
    assertFalse( attr2.contains( ( byte[] ) null ) );

    attr2.add( ( byte[] ) null );
    assertEquals( 1, attr2.size() );
    assertTrue( attr2.contains( ( byte[] ) null ) );

    attr2.remove( ( byte[] ) null );
    assertFalse( attr2.contains( ( byte[] ) null ) );
    assertEquals( 0, attr2.size() );

    attr2.add( BYTES1, BYTES2, BYTES3 );
    assertEquals( 3, attr2.size() );
    assertTrue( attr2.contains( "ab" ) );
    assertTrue( attr2.contains( "b" ) );
    assertTrue( attr2.contains( "c" ) );
    assertFalse( attr2.contains( ( String ) null ) );
}
 
源代码16 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method contains( byte... )
 */
@Test
public void testContainsByteArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( 0, attr1.size() );
    assertFalse( attr1.contains( BYTES1 ) );
    assertFalse( attr1.contains( ( byte[] ) null ) );

    attr1.add( ( byte[] ) null );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.contains( ( byte[] ) null ) );

    attr1.remove( ( byte[] ) null );
    assertFalse( attr1.contains( ( byte[] ) null ) );
    assertEquals( 0, attr1.size() );

    attr1.add( BYTES1, BYTES2, BYTES3 );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( BYTES1 ) );
    assertTrue( attr1.contains( BYTES2 ) );
    assertTrue( attr1.contains( BYTES3 ) );
    assertFalse( attr1.contains( BYTES4 ) );
    assertFalse( attr1.contains( ( byte[] ) null ) );

    Attribute attr2 = new DefaultAttribute( "test" );
    assertEquals( 0, attr2.size() );
    assertFalse( attr2.contains( "a" ) );
    assertFalse( attr2.contains( ( String ) null ) );

    attr2.add( ( String ) null );
    assertEquals( 1, attr2.size() );
    assertTrue( attr2.contains( ( String ) null ) );

    attr2.remove( ( String ) null );
    assertFalse( attr2.contains( ( String ) null ) );
    assertEquals( 0, attr2.size() );

    attr2.add( "ab", "b", "c" );
    assertEquals( 3, attr2.size() );
    assertTrue( attr2.contains( BYTES1 ) );
    assertTrue( attr2.contains( BYTES2 ) );
    assertTrue( attr2.contains( BYTES3 ) );
    assertFalse( attr2.contains( ( byte[] ) null ) );
}
 
源代码17 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method remove( Value... )
 */
@Test
public void testRemoveValueArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertFalse( attr1.remove( STR_VALUE1 ) );
    assertFalse( attr1.remove( STR_VALUE1 ) );

    attr1.add( "a", "b", "c" );
    assertTrue( attr1.remove( STR_VALUE1 ) );
    assertEquals( 2, attr1.size() );

    assertTrue( attr1.remove( STR_VALUE2, STR_VALUE3 ) );
    assertEquals( 0, attr1.size() );

    assertFalse( attr1.remove( STR_VALUE4 ) );

    attr1.clear();
    attr1.add( "a", "b", "c" );
    assertFalse( attr1.remove( STR_VALUE2, STR_VALUE4 ) );
    assertEquals( 2, attr1.size() );

    attr1.clear();
    attr1.add( "a", ( String ) null, "b" );
    assertTrue( attr1.remove( NULL_STRING_VALUE, STR_VALUE1 ) );
    assertEquals( 1, attr1.size() );

    attr1.clear();
    attr1.add( "a", ( String ) null, "b" );
    attr1.add( BYTES3 );
    assertTrue( attr1.remove( NULL_STRING_VALUE, STR_VALUE1 ) );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    assertFalse( attr2.remove( BIN_VALUE1 ) );

    attr2.clear();
    attr2.add( BYTES1, BYTES2, BYTES3 );
    assertTrue( attr2.remove( BIN_VALUE1 ) );
    assertEquals( 2, attr2.size() );

    assertTrue( attr2.remove( BIN_VALUE2, BIN_VALUE3 ) );
    assertEquals( 0, attr2.size() );

    assertFalse( attr2.remove( BIN_VALUE4 ) );

    attr2.clear();
    attr2.add( BYTES1, BYTES2, BYTES3 );
    assertFalse( attr2.remove( BIN_VALUE2, STR_VALUE4 ) );
    assertEquals( 2, attr2.size() );

    attr2.clear();
    attr2.add( BYTES1, ( byte[] ) null, BYTES3 );
    assertFalse( attr2.remove( NULL_STRING_VALUE, BIN_VALUE1 ) );
    assertEquals( 2, attr2.size() );

    attr2.clear();
    attr2.add( BYTES1, ( byte[] ) null, BYTES2 );
    attr2.add( "c" );
    assertEquals( 4, attr2.size() );
    assertFalse( attr2.remove( NULL_STRING_VALUE, BIN_VALUE1, STR_VALUE3 ) );
    assertEquals( 3, attr2.size() );
}
 
源代码18 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method put( String... )
 */
@Test
public void testPutStringArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    int nbAdded = attr1.add( ( String ) null );
    assertEquals( 1, nbAdded );
    assertTrue( attr1.isHumanReadable() );
    assertEquals( NULL_STRING_VALUE, attr1.get() );

    Attribute attr2 = new DefaultAttribute( "test" );

    nbAdded = attr2.add( "" );
    assertEquals( 1, nbAdded );
    assertTrue( attr2.isHumanReadable() );
    assertEquals( "", attr2.getString() );

    Attribute attr3 = new DefaultAttribute( "test" );

    nbAdded = attr3.add( "t" );
    assertEquals( 1, nbAdded );
    assertTrue( attr3.isHumanReadable() );
    assertEquals( "t", attr3.getString() );

    Attribute attr4 = new DefaultAttribute( "test" );

    nbAdded = attr4.add( "a", "b", "c", "d" );
    assertEquals( 4, nbAdded );
    assertTrue( attr4.isHumanReadable() );
    assertTrue( attr4.contains( "a" ) );
    assertTrue( attr4.contains( "b" ) );
    assertTrue( attr4.contains( "c" ) );
    assertTrue( attr4.contains( "d" ) );

    Attribute attr5 = new DefaultAttribute( "test" );

    nbAdded = attr5.add( "a", "b", ( String ) null, "d" );
    assertEquals( 4, nbAdded );
    assertTrue( attr5.isHumanReadable() );
    assertTrue( attr5.contains( "a" ) );
    assertTrue( attr5.contains( "b" ) );
    assertTrue( attr5.contains( ( String ) null ) );
    assertTrue( attr5.contains( "d" ) );

    Attribute attr6 = new DefaultAttribute( "test" );

    nbAdded = attr6.add( "a", ( String ) null );
    assertEquals( 2, nbAdded );
    assertTrue( attr6.isHumanReadable() );
    assertTrue( attr6.contains( "a" ) );
    assertTrue( attr6.contains( ( String ) null ) );
}
 
源代码19 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method put( byte[]... )
 */
@Test
public void testPutByteArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    int nbAdded = attr1.add( ( byte[] ) null );
    assertEquals( 1, nbAdded );
    assertFalse( attr1.isHumanReadable() );
    assertTrue( Arrays.equals( NULL_BINARY_VALUE.getBytes(), attr1.getBytes() ) );

    Attribute attr2 = new DefaultAttribute( "test" );

    nbAdded = attr2.add( Strings.EMPTY_BYTES );
    assertEquals( 1, nbAdded );
    assertFalse( attr2.isHumanReadable() );
    assertTrue( Arrays.equals( Strings.EMPTY_BYTES, attr2.getBytes() ) );

    Attribute attr3 = new DefaultAttribute( "test" );

    nbAdded = attr3.add( BYTES1 );
    assertEquals( 1, nbAdded );
    assertFalse( attr3.isHumanReadable() );
    assertTrue( Arrays.equals( BYTES1, attr3.getBytes() ) );

    Attribute attr4 = new DefaultAttribute( "test" );

    nbAdded = attr4.add( BYTES1, BYTES2 );
    assertEquals( 2, nbAdded );
    assertFalse( attr4.isHumanReadable() );
    assertTrue( attr4.contains( BYTES1 ) );
    assertTrue( attr4.contains( BYTES2 ) );

    nbAdded = attr4.add( BYTES3, BYTES4 );
    assertEquals( 2, nbAdded );
    assertFalse( attr4.isHumanReadable() );
    assertTrue( attr4.contains( BYTES3 ) );
    assertTrue( attr4.contains( BYTES4 ) );

    Attribute attr5 = new DefaultAttribute( "test" );

    nbAdded = attr5.add( BYTES1, BYTES2, ( byte[] ) null, BYTES3 );
    assertEquals( 4, nbAdded );
    assertFalse( attr5.isHumanReadable() );
    assertTrue( attr5.contains( BYTES1 ) );
    assertTrue( attr5.contains( BYTES2 ) );
    assertTrue( attr5.contains( ( byte[] ) null ) );
    assertTrue( attr5.contains( BYTES3 ) );

    Attribute attr6 = new DefaultAttribute( "test" );

    nbAdded = attr6.add( BYTES1, ( byte[] ) null );
    assertEquals( 2, nbAdded );
    assertFalse( attr6.isHumanReadable() );
    assertTrue( attr6.contains( "ab" ) );
    assertTrue( attr6.contains( ( byte[] ) null ) );
}
 
源代码20 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method put( Value... )
 */
@Test
public void testPutValueArray() throws InvalidAttributeValueException, LdapException
{
    Attribute attr1 = new DefaultAttribute( "test" );

    assertEquals( 0, attr1.size() );

    attr1.add( NULL_STRING_VALUE );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.contains( NULL_STRING_VALUE ) );

    attr1.clear();
    attr1.add( STR_VALUE1, STR_VALUE2, STR_VALUE3 );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( STR_VALUE1 ) );
    assertTrue( attr1.contains( STR_VALUE2 ) );
    assertTrue( attr1.contains( STR_VALUE3 ) );

    attr1.clear();
    attr1.add( STR_VALUE1, NULL_STRING_VALUE, STR_VALUE3 );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( STR_VALUE1 ) );
    assertTrue( attr1.contains( NULL_STRING_VALUE ) );
    assertTrue( attr1.contains( STR_VALUE3 ) );

    attr1.clear();
    attr1.add( STR_VALUE1, NULL_STRING_VALUE, BIN_VALUE3 );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( STR_VALUE1 ) );
    assertTrue( attr1.contains( NULL_STRING_VALUE ) );
    assertTrue( attr1.contains( STR_VALUE3 ) );

    Attribute attr2 = new DefaultAttribute( "test" );
    assertEquals( 0, attr2.size() );

    attr2.add( NULL_BINARY_VALUE );
    assertEquals( 1, attr2.size() );
    assertTrue( attr2.contains( NULL_BINARY_VALUE ) );

    attr2.clear();
    attr2.add( BIN_VALUE1, BIN_VALUE2, BIN_VALUE3 );
    assertEquals( 3, attr2.size() );
    assertTrue( attr2.contains( BIN_VALUE1 ) );
    assertTrue( attr2.contains( BIN_VALUE2 ) );
    assertTrue( attr2.contains( BIN_VALUE3 ) );

    attr2.clear();
    attr2.add( BIN_VALUE1, NULL_BINARY_VALUE, STR_VALUE3 );
    assertEquals( 3, attr2.size() );
    assertTrue( attr2.contains( BIN_VALUE1 ) );
    assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
    assertTrue( attr2.contains( BIN_VALUE3 ) );
}
 
源代码21 项目: directory-ldap-api   文件: AttributeTest.java
/**
 * Test method hashCode()
 */
@Test
public void testHashCode() throws InvalidAttributeValueException, LdapException
{
    Attribute attr = new DefaultAttribute();
    assertEquals( 37, attr.hashCode() );

    Attribute attr1 = new DefaultAttribute( "test" );
    Attribute attr2 = new DefaultAttribute( "test" );

    assertEquals( attr1.hashCode(), attr2.hashCode() );

    attr1.add( "a", "b", "c" );
    attr2.add( "a", "b", "c" );
    assertEquals( attr1.hashCode(), attr2.hashCode() );

    attr1.add( "d" );
    attr2.add( "d" );
    assertEquals( attr1.hashCode(), attr2.hashCode() );

    attr1.add( NULL_STRING_VALUE );
    attr2.add( NULL_STRING_VALUE );
    assertEquals( attr1.hashCode(), attr2.hashCode() );

    // Order mess up the hashCode
    attr1.clear();
    attr2.clear();
    attr1.add( "a", "b", "c" );
    attr2.add( "c", "b", "a" );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    Attribute attr3 = new DefaultAttribute( "test" );
    Attribute attr4 = new DefaultAttribute( "test" );

    attr3.add( BYTES1, BYTES2 );
    attr4.add( BYTES1, BYTES2 );
    assertEquals( attr3.hashCode(), attr4.hashCode() );

    attr3.add( BYTES3 );
    attr4.add( BYTES3 );
    assertEquals( attr3.hashCode(), attr4.hashCode() );

    attr3.add( NULL_BINARY_VALUE );
    attr4.add( NULL_BINARY_VALUE );
    assertEquals( attr3.hashCode(), attr4.hashCode() );

    // Order mess up the hashCode
    attr3.clear();
    attr4.clear();
    attr3.add( BYTES1, BYTES2 );
    attr4.add( BYTES2, BYTES1 );
    assertNotSame( attr3.hashCode(), attr4.hashCode() );
}
 
 类所在包
 同包方法