jdk/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java
changeset 2 90ce3da70b43
child 13256 5886d7607acd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java	Sat Dec 01 00:00:00 2007 +0000
@@ -0,0 +1,36 @@
+/*
+ * @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");
+        }
+    }
+}