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

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


     * Test method remove( Value... )
     */
    @Test
    public void testRemoveValueArray() throws Exception
    {
        Attribute attr1 = new DefaultAttribute( atEMail );

        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 );
        assertFalse( attr1.remove( NULL_STRING_VALUE, STR_VALUE1, BIN_VALUE3 ) );
        assertEquals( 1, attr1.size() );

        Attribute attr2 = new DefaultAttribute( atPwd );

        assertFalse( attr2.remove( BIN_VALUE1 ) );

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


     * Test method remove( byte... )
     */
    @Test
    public void testRemoveByteArray() throws Exception
    {
        Attribute attr1 = new DefaultAttribute( atPwd );

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

     * Test method remove( String... )
     */
    @Test
    public void testRemoveStringArray() throws Exception
    {
        Attribute attr1 = new DefaultAttribute( atEMail );

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

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

     * Test method toString
     */
    @Test
    public void testToString() throws LdapException
    {
        Attribute attr = new DefaultAttribute( atEMail );

        assertEquals( "    email: (null)\n", attr.toString() );

        attr.setUpId( "EMail" );
        assertEquals( "    EMail: (null)\n", attr.toString() );

        attr.add( ( String ) null );
        assertEquals( "    EMail: ''\n", attr.toString() );

        attr.clear();
        attr.add( "a", "b" );
        assertEquals( "    EMail: a\n    EMail: b\n", attr.toString() );
    }
View Full Code Here

     * Test method instanceOf()
     */
    @Test
    public void testInstanceOf() throws Exception
    {
        Attribute attr = new DefaultAttribute( atCN );

        assertTrue( attr.isInstanceOf( atCN ) );
        assertTrue( attr.isInstanceOf( atName ) );
        assertFalse( attr.isInstanceOf( atSN ) );
    }
View Full Code Here

     * Test method setUpId( String, AttributeType )
     */
    @Test
    public void testSetUpIdStringAttributeType() throws Exception
    {
        Attribute attr = new DefaultAttribute( atSN );

        attr.setUpId( null, atCN );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  ", atCN );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  CN  ", atCN );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "  CN  ", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  CommonName  ", atCN );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "  CommonName  ", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  2.5.4.3  ", atCN );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "  2.5.4.3  ", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        // Check with wrong IDs
        try
        {
            attr.setUpId( "sn", atCN );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        try
        {
            attr.setUpId( "  2.5.4.4  ", atCN );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
View Full Code Here

     * Test method setUpId( String ) inherited from ClientAttribute
     */
    @Test
    public void testSetUpIdString() throws Exception
    {
        Attribute attr = new DefaultAttribute( atCN );

        attr.setUpId( "cn" );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  CN  " );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "  CN  ", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  CommonName  " );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "  CommonName  ", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        attr.setUpId( "  2.5.4.3  " );
        assertEquals( "  2.5.4.3  ", attr.getUpId() );
        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( atCN, attr.getAttributeType() );

        // Now check wrong IDs
        attr = new DefaultAttribute( atCN );

        try
        {
            attr.setUpId( "sn" );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            // Expected
        }

        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        try
        {
            attr.setUpId( "  SN  " );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            // Expected
        }

        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        try
        {
            attr.setUpId( "  surname  " );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            // Expected
        }

        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );

        try
        {
            attr.setUpId( "  2.5.4.4  " );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            // Expected
        }

        assertEquals( "2.5.4.3", attr.getId() );
        assertEquals( "cn", attr.getUpId() );
        assertEquals( atCN, attr.getAttributeType() );
    }
View Full Code Here

     * Test method setAttributeType( AttributeType )
     */
    @Test
    public void testSetAttributeType() throws Exception
    {
        Attribute attr = new DefaultAttribute( atCN );

        try
        {
            attr.apply( null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        attr.apply( atSN );

        assertTrue( attr.isInstanceOf( atSN ) );
        assertEquals( "2.5.4.4", attr.getId() );
        assertEquals( "sn", attr.getUpId() );
    }
View Full Code Here

     * Test method getAttributeType()
     */
    @Test
    public void testGetAttributeType() throws Exception
    {
        Attribute attr = new DefaultAttribute( atSN );
        assertEquals( atSN, attr.getAttributeType() );
    }
View Full Code Here

TOP

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

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.