jdk/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 13256 5886d7607acd
permissions -rw-r--r--
Initial load

/*
 * @test
 * @bug 4278121
 * @summary Ensure that calling unbind() on an unbound name returns
 *      successfully.
 */

import javax.naming.*;

public class UnbindIdempotent {

    public static void main(String[] args) throws Exception {

        // Create registry on port 1099 if one is not already running.
        try {
            java.rmi.registry.LocateRegistry.createRegistry(1099);
        } catch (java.rmi.RemoteException e) {
        }

        Context ictx = new InitialContext();
        Context rctx;
        try {
            rctx = (Context)ictx.lookup("rmi://localhost:1099");
        } catch (NamingException e) {
            // Unable to set up for test.
            return;
        }

        // Attempt to unbind a name that is not already bound.
        try {
            rctx.unbind("_bogus_4278121_");
        } catch (NameNotFoundException e) {
            throw new Exception("Test failed:  unbind() call not idempotent");
        }
    }
}