1 /*
   2  * Copyright (c) 2005, 2012, 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  * @build TestLibrary RMID ActivationLibrary
  33  * @run main/othervm/timeout=240 LookupActivationSystem
  34  */
  35 
  36 import java.rmi.*;
  37 import java.rmi.activation.*;
  38 import java.rmi.registry.*;
  39 import java.rmi.server.*;
  40 import java.io.Serializable;
  41 
  42 public class LookupActivationSystem implements Remote, Serializable {
  43 
  44     private static final String NAME = ActivationSystem.class.getName();
  45 
  46     public static void main(String[] args) throws Exception {
  47 
  48         System.out.println("\nRegression test for bug 6245733\n");
  49 
  50         RMID rmid = null;
  51 
  52         try {
  53             RMID.removeLog();
  54             rmid = RMID.createRMID();
  55             rmid.start();
  56 
  57             System.err.println("look up activation system");
  58             Registry rmidRegistry =
  59                 LocateRegistry.getRegistry(rmid.getPort());
  60             ActivationSystem system = (ActivationSystem)
  61                 rmidRegistry.lookup(NAME);
  62 
  63             if (system instanceof ActivationSystem) {
  64                 System.err.println("test1 passed: lookup succeeded");
  65             }
  66 
  67             System.err.println("get list of rmid internal registry");
  68             String[] list = rmidRegistry.list();
  69             if (list.length == 1 && list[0].equals(NAME)) {
  70                 System.err.println(
  71                     "test2 passed: activation system found in list");
  72             } else {
  73                 throw new RuntimeException("test2 FAILED");
  74             }
  75 
  76             try {
  77                 rmidRegistry.bind(NAME, new LookupActivationSystem());
  78                 throw new RuntimeException("test3 FAILED: bind succeeded!");
  79             } catch (ServerException e) {
  80                 if (e.getCause() instanceof AccessException) {
  81                     System.err.println(
  82                         "test3 passed: binding ActivationSystem " +
  83                         "failed as expected");
  84                 } else {
  85                     throw new RuntimeException(
  86                         "test3 FAILED: incorrect cause: " + e.getCause());
  87                 }
  88 
  89             }
  90 
  91             try {
  92                 rmidRegistry.rebind(NAME, new LookupActivationSystem());
  93                 throw new RuntimeException("test4 FAILED: rebind succeeded!");
  94             } catch (ServerException e) {
  95                 if (e.getCause() instanceof AccessException) {
  96                     System.err.println(
  97                         "test4 passed: rebinding ActivationSystem " +
  98                         "failed as expected");
  99                 } else {
 100                     throw new RuntimeException(
 101                         "test4 FAILED: incorrect cause: " + e.getCause());
 102                 }
 103             }
 104 
 105             try {
 106                 rmidRegistry.unbind(NAME);
 107                 throw new RuntimeException("test4 FAILED: unbind succeeded!");
 108             } catch (ServerException e) {
 109                 if (e.getCause() instanceof AccessException) {
 110                     System.err.println(
 111                         "test5 passed: unbinding ActivationSystem " +
 112                         "failed as expected");
 113                 } else {
 114                     throw new RuntimeException(
 115                         "test5 FAILED: incorrect cause: " + e.getCause());
 116                 }
 117             }
 118 
 119 
 120         } finally {
 121             ActivationLibrary.rmidCleanup(rmid);
 122         }
 123     }
 124 }