Package org.apache.directory.shared.ldap.model.entry

Examples of org.apache.directory.shared.ldap.model.entry.DefaultAttribute


     * Test method contains( Value... ) throws LdapException
     */
    @Test
    public void testContainsValueArray() throws LdapException
    {
        Attribute attr1 = new DefaultAttribute( atEMail );

        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 ) );

        Attribute attr2 = new DefaultAttribute( atPwd );
        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 ) );
    }
View Full Code Here


     *            the id for the attribute
     * @return the AttributeImpl assembled for testing
     */
    private Attribute getAttribute( String id ) throws LdapException
    {
        Attribute attr = new DefaultAttribute( id );
        attr.add( "value0" );
        attr.add( "value1" );
        attr.add( "value2" );
        return attr;
    }
View Full Code Here

        try
        {
            oIn = new ObjectInputStream( in );

            DefaultAttribute value = new DefaultAttribute( at );
            value.readExternal( oIn );

            return value;
        }
        catch ( IOException ioe )
        {
View Full Code Here

     * Test method isValid( SyntaxChecker )
     */
    @Test
    public void testIsValidSyntaxChecker() throws LdapException
    {
        Attribute attr = new DefaultAttribute( "test" );

        attr.add( "test", "another test" );

        assertTrue( attr.isValid( atCN ) );

        attr.add( "test an invalid '\uFFFD' char" );
        assertFalse( attr.isValid( atCN ) );
    }
View Full Code Here

    @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 StringValue );
        assertEquals( "test", ( ( StringValue ) value ).getString() );

        // Add a binary value
        assertEquals( 0, attr.add( new byte[]
            { 0x01 } ) );

        // Add a Value
        Value<?> ssv = new StringValue( at, "test2" );

        attr.add( ssv );

        assertEquals( 2, attr.size() );

        Set<String> expected = new HashSet<String>();
        expected.add( "test" );
        expected.add( "test2" );
View Full Code Here

    @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" );
View Full Code Here

    @Test
    public void testAddNullValue() throws Exception
    {
        AttributeType at = TestEntryUtils.getIA5StringAttributeType();

        DefaultAttribute attr = new DefaultAttribute( at );

        // Add a null value
        attr.add( new StringValue( at, null ) );

        assertEquals( 1, attr.size() );

        assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() );

        Value<?> value = attr.get();

        assertTrue( value instanceof StringValue );
        assertNull( ( ( StringValue ) value ).getValue() );
    }
View Full Code Here

    @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" ) );
    }
View Full Code Here

    @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" ) );
    }
View Full Code Here

     * Test method getBytes()
     */
    @Test
    public void testGetBytes() throws LdapInvalidAttributeValueException
    {
        Attribute attr1 = new DefaultAttribute( atPwd );

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

        Attribute attr2 = new DefaultAttribute( atPwd );

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

        Attribute attr3 = new DefaultAttribute( atCN );

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

        try
        {
            attr3.getBytes();
            fail();
        }
        catch ( LdapInvalidAttributeValueException ivae )
        {
            assertTrue( true );
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.entry.DefaultAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.