Package javax.naming.directory

Examples of javax.naming.directory.DirContext.modifyAttributes()


        // Now test remove of value ( bar ) that does not exist in cn
        mod = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( "cn", "bar" ) );
        try
        {
            ctx.modifyAttributes( RDN, new ModificationItem[]
                { mod } );
            fail();
        }
        catch ( NoSuchAttributeException nsae )
        {


        // Remove description Attribute
        Attribute attr = new BasicAttribute( "description" );
        Attributes attrs = new BasicAttributes( true );
        attrs.put( attr );
        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );

        // Verify, that attribute is deleted
        attrs = ctx.getAttributes( RDN );
        attr = attrs.get( "description" );
        assertNull( attr );

    {
        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );

        // add telephoneNumber to entry
        Attributes tn = new BasicAttributes( "telephoneNumber", "12345678", true );
        ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, tn );

        // Remove description and telephoneNumber to Attribute
        Attributes attrs = new BasicAttributes( true );
        attrs.put( new BasicAttribute( "description" ) );
        attrs.put( new BasicAttribute( "telephoneNumber" ) );

        // Remove description and telephoneNumber to Attribute
        Attributes attrs = new BasicAttributes( true );
        attrs.put( new BasicAttribute( "description" ) );
        attrs.put( new BasicAttribute( "telephoneNumber" ) );
        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );

        // Verify, that attributes are deleted
        attrs = ctx.getAttributes( RDN );
        assertNull( attrs.get( "description" ) );
        assertNull( attrs.get( "telephoneNumber" ) );

        Attributes attrs = new BasicAttributes( true );
        attrs.put( attr );

        try
        {
            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
            fail( "Deletion of required attribute should fail." );
        }
        catch ( SchemaViolationException e )
        {
            // expected behaviour

        Attributes attrs = new BasicAttributes( true );
        attrs.put( attr );

        try
        {
            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
            fail( "Deletion of Rdn attribute should fail." );
        }
        catch ( SchemaViolationException e )
        {
            // expected behaviour

        Attributes attrs = new BasicAttributes( true );
        attrs.put( attr );

        try
        {
            ctx.modifyAttributes( newRdn, DirContext.REMOVE_ATTRIBUTE, attrs );
            fail( "Deletion of Rdn attribute should fail." );
        }
        catch ( SchemaViolationException e )
        {
            // expected behaviour

        Attributes attrs = new BasicAttributes( true );
        attrs.put( attr );

        try
        {
            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
            fail( "Deletion of attribute, which is not present in the entry, should fail." );
        }
        catch ( NoSuchAttributeException e )
        {
            assertTrue( true );

        Attribute attr = new BasicAttribute( "telephoneNumber", "12345" );
        Attributes attrs = new BasicAttributes( true );
        attrs.put( attr );

        // Inject the new attribute
        ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, attrs );

        // Now try to remove a value which is not present
        Attribute attr2 = new BasicAttribute( "telephoneNumber", "7890" );
        Attributes attrs2 = new BasicAttributes( true );
        attrs2.put( attr2 );

        Attributes attrs2 = new BasicAttributes( true );
        attrs2.put( attr2 );

        try
        {
            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs2 );
            // We should get an exception
            fail();
        }
        catch ( NoSuchAttributeException nsae )
        {

TOP
Copyright © 2018 www.massapi.com. 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.