1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6245733
  27  * @summary synopsis: rmid's registry's list operation doesn't include
  28  * activation system
  29  * @author Ann Wollrath
  30  *
  31  * @library ../../../testlibrary
  32  * @modules java.rmi/sun.rmi.registry
  33  *          java.rmi/sun.rmi.server
  34  *          java.rmi/sun.rmi.transport
  35  *          java.rmi/sun.rmi.transport.tcp
  36  *          java.base/sun.nio.ch
  37  * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
  38  * @run main/othervm/timeout=240 LookupActivationSystem
  39  */
  40 
  41 import java.rmi.*;
  42 import java.rmi.activation.*;
  43 import java.rmi.registry.*;
  44 import java.rmi.server.*;
  45 import java.io.Serializable;
  46 
  47 public class LookupActivationSystem implements Remote, Serializable {
  48 
  49     private static final String NAME = ActivationSystem.class.getName();
  50 
  51     public static void main(String[] args) throws Exception {
  52 
  53         System.out.println("\nRegression test for bug 6245733\n");
  54 
  55         RMID rmid = null;
  56 
  57         try {
  58             RMID.removeLog();
  59             rmid = RMID.createRMIDOnEphemeralPort();
  60             rmid.start();
  61 
  62             System.err.println("look up activation system");
  63             Registry rmidRegistry =
  64                 LocateRegistry.getRegistry(rmid.getPort());
  65             ActivationSystem system = (ActivationSystem)
  66                 rmidRegistry.lookup(NAME);
  67 
  68             if (system instanceof ActivationSystem) {
  69                 System.err.println("test1 passed: lookup succeeded");
  70             }
  71 
  72             System.err.println("get list of rmid internal registry");
  73             String[] list = rmidRegistry.list();
  74             if (list.length == 1 && list[0].equals(NAME)) {
  75                 System.err.println(
  76                     "test2 passed: activation system found in list");
  77             } else {
  78                 throw new RuntimeException("test2 FAILED");
  79             }
  80 
  81             try {
  82                 rmidRegistry.bind(NAME, new LookupActivationSystem());
  83                 throw new RuntimeException("test3 FAILED: bind succeeded!");
  84             } catch (ServerException e) {
  85                 if (e.getCause() instanceof AccessException) {
  86                     System.err.println(
  87                         "test3 passed: binding ActivationSystem " +
  88                         "failed as expected");
  89                 } else {
  90                     throw new RuntimeException(
  91                         "test3 FAILED: incorrect cause: " + e.getCause());
  92                 }
  93 
  94             }
  95 
  96             try {
  97                 rmidRegistry.rebind(NAME, new LookupActivationSystem());
  98                 throw new RuntimeException("test4 FAILED: rebind succeeded!");
  99             } catch (ServerException e) {
 100                 if (e.getCause() instanceof AccessException) {
 101                     System.err.println(
 102                         "test4 passed: rebinding ActivationSystem " +
 103                         "failed as expected");
 104                 } else {
 105                     throw new RuntimeException(
 106                         "test4 FAILED: incorrect cause: " + e.getCause());
 107                 }
 108             }
 109 
 110             try {
 111                 rmidRegistry.unbind(NAME);
 112                 throw new RuntimeException("test4 FAILED: unbind succeeded!");
 113             } catch (ServerException e) {
 114                 if (e.getCause() instanceof AccessException) {
 115                     System.err.println(
 116                         "test5 passed: unbinding ActivationSystem " +
 117                         "failed as expected");
 118                 } else {
 119                     throw new RuntimeException(
 120                         "test5 FAILED: incorrect cause: " + e.getCause());
 121                 }
 122             }
 123 
 124 
 125         } finally {
 126             rmid.cleanup();
 127         }
 128     }
 129 }