UnbindIdempotent.java revision 5267
1178N/A/*
1178N/A * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
1178N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1178N/A *
1178N/A * This code is free software; you can redistribute it and/or modify it
1178N/A * under the terms of the GNU General Public License version 2 only, as
1178N/A * published by the Free Software Foundation.
1178N/A *
1178N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1178N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1178N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1178N/A * version 2 for more details (a copy is included in the LICENSE file that
1178N/A * accompanied this code).
1178N/A *
1178N/A * You should have received a copy of the GNU General Public License version
1178N/A * 2 along with this work; if not, write to the Free Software Foundation,
1178N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
1178N/A * questions.
1178N/A */
1178N/A
1178N/A/*
1178N/A * @test
1178N/A * @bug 4278121
1178N/A * @summary Ensure that calling unbind() on an unbound name returns
1178N/A * successfully.
1178N/A * @library ../../../../../../java/rmi/testlibrary
1178N/A * @build TestLibrary
1178N/A * @run main UnbindIdempotent
1178N/A */
1178N/A
1178N/Aimport java.rmi.registry.Registry;
1178N/Aimport javax.naming.Context;
1178N/Aimport javax.naming.InitialContext;
1178N/Aimport javax.naming.NameNotFoundException;
1178N/Aimport javax.naming.NamingException;
1178N/A
1178N/Apublic class UnbindIdempotent {
1178N/A
1178N/A public static void main(String[] args) throws Exception {
1178N/A Registry registry = TestLibrary.createRegistryOnUnusedPort();
1178N/A int registryPort = TestLibrary.getRegistryPort(registry);
1178N/A InitialContext ictx = new InitialContext();
1178N/A Context rctx;
1178N/A
1178N/A try {
1178N/A rctx = (Context)ictx.lookup("rmi://localhost:" + Integer.toString(registryPort));
1178N/A } catch (NamingException e) {
1178N/A // Unable to set up for test.
1178N/A return;
1178N/A }
1178N/A
1178N/A // Attempt to unbind a name that is not already bound.
1178N/A try {
1178N/A rctx.unbind("_bogus_4278121_");
0N/A } catch (NameNotFoundException e) {
0N/A throw new Exception("Test failed: unbind() call not idempotent");
1178N/A }
1178N/A }
1178N/A}
1178N/A