1 /*
   2  * Copyright (c) 2001, 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 /* @test
  25  * @bug 4418673
  26  * @summary verify that setting the java.rmi.server.RMIClassLoaderSpi
  27  * system property to "default" causes the default provider instance to
  28  * be used by the RMIClassLoader API.
  29  * @author Peter Jones
  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  * @build TestLibrary ServiceConfiguration Foo
  37  * @run main/othervm/policy=security.policy DefaultProperty
  38  */
  39 
  40 import java.net.MalformedURLException;
  41 import java.net.URL;
  42 
  43 import java.rmi.server.RMIClassLoader;
  44 
  45 public class DefaultProperty {
  46 
  47     public static void main(String[] args) throws Exception {
  48 
  49         ServiceConfiguration.installServiceConfigurationFile();
  50 
  51         System.setProperty(
  52             "java.rmi.server.RMIClassLoaderSpi", "default");
  53 
  54         String classname = "Foo";
  55 
  56         URL codebaseURL = null;
  57         try {
  58             codebaseURL = TestLibrary.installClassInCodebase(
  59                 classname, "remote_codebase");
  60         } catch (MalformedURLException e) {
  61             TestLibrary.bomb(e);
  62         }
  63 
  64         TestLibrary.suggestSecurityManager(null);
  65 
  66         Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
  67         if (!fooClass.getName().equals(classname)) {
  68             throw new RuntimeException(
  69                 "wrong class name, expected: " + classname +
  70                 ", received: " + fooClass.getName());
  71         }
  72 
  73         String annotation = RMIClassLoader.getClassAnnotation(fooClass);
  74         if (!annotation.equals(codebaseURL.toString())) {
  75             throw new RuntimeException(
  76                 "wrong class annotation, expected: " + codebaseURL.toString() +
  77                 ", received: " + annotation);
  78         }
  79 
  80         System.err.println("TEST PASSED");
  81     }
  82 }