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  * @build TestLibrary ServiceConfiguration Foo
  33  * @run main/othervm/policy=security.policy DefaultProperty
  34  */
  35 
  36 import java.net.MalformedURLException;
  37 import java.net.URL;
  38 
  39 import java.rmi.server.RMIClassLoader;
  40 
  41 public class DefaultProperty {
  42 
  43     public static void main(String[] args) throws Exception {
  44 
  45         ServiceConfiguration.installServiceConfigurationFile();
  46 
  47         System.setProperty(
  48             "java.rmi.server.RMIClassLoaderSpi", "default");
  49 
  50         String classname = "Foo";
  51 
  52         URL codebaseURL = null;
  53         try {
  54             codebaseURL = TestLibrary.installClassInCodebase(
  55                 classname, "remote_codebase");
  56         } catch (MalformedURLException e) {
  57             TestLibrary.bomb(e);
  58         }
  59 
  60         TestLibrary.suggestSecurityManager(null);
  61 
  62         Class fooClass = RMIClassLoader.loadClass(codebaseURL, classname);
  63         if (!fooClass.getName().equals(classname)) {
  64             throw new RuntimeException(
  65                 "wrong class name, expected: " + classname +
  66                 ", received: " + fooClass.getName());
  67         }
  68 
  69         String annotation = RMIClassLoader.getClassAnnotation(fooClass);
  70         if (!annotation.equals(codebaseURL.toString())) {
  71             throw new RuntimeException(
  72                 "wrong class annotation, expected: " + codebaseURL.toString() +
  73                 ", received: " + annotation);
  74         }
  75 
  76         System.err.println("TEST PASSED");
  77     }
  78 }