diff options
author | Mark Spruiell <mes@zeroc.com> | 2009-09-04 12:34:41 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2009-09-04 12:34:41 -0700 |
commit | a86b114d82c678b49ab2b43c16abff1f8239d5d6 (patch) | |
tree | db649f2762d87a991de02b2c2c641029a01cac85 /java/test/Ice/classLoader | |
parent | Converted demo projects to VS2008 (diff) | |
download | ice-a86b114d82c678b49ab2b43c16abff1f8239d5d6.tar.bz2 ice-a86b114d82c678b49ab2b43c16abff1f8239d5d6.tar.xz ice-a86b114d82c678b49ab2b43c16abff1f8239d5d6.zip |
bug 4196 - add class loader to InitializationData
Diffstat (limited to 'java/test/Ice/classLoader')
-rw-r--r-- | java/test/Ice/classLoader/AbstractClassI.java | 20 | ||||
-rw-r--r-- | java/test/Ice/classLoader/AllTests.java | 208 | ||||
-rw-r--r-- | java/test/Ice/classLoader/CertificateVerifierI.java | 18 | ||||
-rw-r--r-- | java/test/Ice/classLoader/Client.java | 37 | ||||
-rw-r--r-- | java/test/Ice/classLoader/InitialI.java | 51 | ||||
-rw-r--r-- | java/test/Ice/classLoader/PasswordCallbackI.java | 28 | ||||
-rw-r--r-- | java/test/Ice/classLoader/PluginFactoryI.java | 29 | ||||
-rw-r--r-- | java/test/Ice/classLoader/Server.java | 41 | ||||
-rw-r--r-- | java/test/Ice/classLoader/Test.ice | 39 | ||||
-rwxr-xr-x | java/test/Ice/classLoader/run.py | 25 |
10 files changed, 496 insertions, 0 deletions
diff --git a/java/test/Ice/classLoader/AbstractClassI.java b/java/test/Ice/classLoader/AbstractClassI.java new file mode 100644 index 00000000000..701c3da3fb2 --- /dev/null +++ b/java/test/Ice/classLoader/AbstractClassI.java @@ -0,0 +1,20 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +import test.Ice.classLoader.Test.AbstractClass; + +class AbstractClassI extends AbstractClass +{ + public void + op(Ice.Current current) + { + } +} diff --git a/java/test/Ice/classLoader/AllTests.java b/java/test/Ice/classLoader/AllTests.java new file mode 100644 index 00000000000..b8d5a5783ff --- /dev/null +++ b/java/test/Ice/classLoader/AllTests.java @@ -0,0 +1,208 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +import java.io.PrintWriter; + +import test.Ice.classLoader.Test.AbstractClass; +import test.Ice.classLoader.Test.ConcreteClass; +import test.Ice.classLoader.Test.E; +import test.Ice.classLoader.Test.InitialPrx; +import test.Ice.classLoader.Test.InitialPrxHelper; + +public class AllTests +{ + private static class MyObjectFactory implements Ice.ObjectFactory + { + public Ice.Object create(String type) + { + if(type.equals("::Test::AbstractClass")) + { + return new AbstractClassI(); + } + + assert (false); // Should never be reached + return null; + } + + public void destroy() + { + // Nothing to do + } + } + + private static class MyClassLoader extends ClassLoader + { + protected Class<?> loadClass(String name, boolean resolve) + throws ClassNotFoundException + { + _names.add(name); + return super.loadClass(name, resolve); + } + + void reset() + { + _names.clear(); + } + + boolean check(String name) + { + return _names.contains(name); + } + + private java.util.List<String> _names = new java.util.LinkedList<String>(); + } + + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void + allTests(boolean collocated, PrintWriter out, Ice.InitializationData initData) + { + // + // Verify that the class loader is used for Slice packages. + // + { + out.print("testing package... "); + out.flush(); + Ice.InitializationData init = (Ice.InitializationData)initData.clone(); + MyClassLoader classLoader = new MyClassLoader(); + init.classLoader = classLoader; + Ice.Communicator communicator = Ice.Util.initialize(init); + test(classLoader.check("test.Ice.classLoader.Test._Marker")); + communicator.destroy(); + out.println("ok"); + } + + // + // Verify that the class loader is used for Ice plug-ins. + // + { + out.print("testing plug-in... "); + out.flush(); + Ice.InitializationData init = (Ice.InitializationData)initData.clone(); + init.properties = (Ice.Properties)initData.properties._clone(); + init.properties.setProperty("Ice.Plugin.Test", "test.Ice.classLoader.PluginFactoryI"); + MyClassLoader classLoader = new MyClassLoader(); + init.classLoader = classLoader; + Ice.Communicator communicator = Ice.Util.initialize(init); + test(classLoader.check("test.Ice.classLoader.PluginFactoryI")); + communicator.destroy(); + out.println("ok"); + } + + // + // Verify that the class loader is used for IceSSL certificate verifiers and password callbacks. + // + if(initData.properties.getProperty("Ice.Default.Protocol").equals("ssl")) + { + out.print("testing IceSSL certificate verifier and password callback... "); + out.flush(); + Ice.InitializationData init = (Ice.InitializationData)initData.clone(); + init.properties = (Ice.Properties)initData.properties._clone(); + init.properties.setProperty("IceSSL.CertVerifier", "test.Ice.classLoader.CertificateVerifierI"); + init.properties.setProperty("IceSSL.PasswordCallback", "test.Ice.classLoader.PasswordCallbackI"); + MyClassLoader classLoader = new MyClassLoader(); + init.classLoader = classLoader; + Ice.Communicator communicator = Ice.Util.initialize(init); + test(classLoader.check("test.Ice.classLoader.CertificateVerifierI")); + test(classLoader.check("test.Ice.classLoader.PasswordCallbackI")); + communicator.destroy(); + out.println("ok"); + } + + // + // Marshaling tests. + // + { + Ice.InitializationData init = (Ice.InitializationData)initData.clone(); + MyClassLoader classLoader = new MyClassLoader(); + init.classLoader = classLoader; + Ice.Communicator communicator = Ice.Util.initialize(init); + + String ref = "initial:default -p 12010"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + test(base != null); + + InitialPrx initial = InitialPrxHelper.checkedCast(base); + test(initial != null); + + // + // Verify that the class loader is used for concrete classes. + // + { + out.print("testing concrete class... "); + out.flush(); + ConcreteClass cc = initial.getConcreteClass(); + test(cc != null); + test(classLoader.check("Test.ConcreteClass")); + test(classLoader.check("test.Ice.classLoader.Test.ConcreteClass")); + classLoader.reset(); + out.println("ok"); + } + + // + // Verify that the class loader is invoked when a factory is not installed, and is + // not invoked when a factory is installed. + // + { + out.print("testing abstract class... "); + out.flush(); + + try + { + initial.getAbstractClass(); + } + catch(Ice.NoObjectFactoryException ex) + { + // Expected. + } + test(classLoader.check("Test.AbstractClass")); + test(classLoader.check("test.Ice.classLoader.Test.AbstractClass")); + classLoader.reset(); + + communicator.addObjectFactory(new MyObjectFactory(), "::Test::AbstractClass"); + AbstractClass ac = initial.getAbstractClass(); + test(ac != null); + test(!classLoader.check("Test.AbstractClass")); + test(!classLoader.check("test.Ice.classLoader.Test.AbstractClass")); + classLoader.reset(); + + out.println("ok"); + } + + // + // Verify that the class loader is used for user exceptions. + // + out.print("testing user exception... "); + out.flush(); + try + { + initial.throwException(); + test(false); + } + catch(E ex) + { + } + test(classLoader.check("Test.E")); + test(classLoader.check("test.Ice.classLoader.Test.E")); + out.println("ok"); + + initial.shutdown(); + communicator.destroy(); + } + } +} diff --git a/java/test/Ice/classLoader/CertificateVerifierI.java b/java/test/Ice/classLoader/CertificateVerifierI.java new file mode 100644 index 00000000000..b5439bd7e80 --- /dev/null +++ b/java/test/Ice/classLoader/CertificateVerifierI.java @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +public class CertificateVerifierI implements IceSSL.CertificateVerifier +{ + public boolean verify(IceSSL.ConnectionInfo info) + { + return true; + } +} diff --git a/java/test/Ice/classLoader/Client.java b/java/test/Ice/classLoader/Client.java new file mode 100644 index 00000000000..6febef6417e --- /dev/null +++ b/java/test/Ice/classLoader/Client.java @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + AllTests.allTests(false, getWriter(), _initData); + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + _initData = new Ice.InitializationData(); + _initData.properties = Ice.Util.createProperties(argsH); + _initData.properties.setProperty("Ice.Package.Test", "test.Ice.classLoader"); + return _initData; + } + + public static void main(String[] args) + { + Client app = new Client(); + int result = app.main("Client", args); + System.gc(); + System.exit(result); + } + + private Ice.InitializationData _initData; +} diff --git a/java/test/Ice/classLoader/InitialI.java b/java/test/Ice/classLoader/InitialI.java new file mode 100644 index 00000000000..2b8b87caefd --- /dev/null +++ b/java/test/Ice/classLoader/InitialI.java @@ -0,0 +1,51 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +import test.Ice.classLoader.Test.AbstractClass; +import test.Ice.classLoader.Test.ConcreteClass; +import test.Ice.classLoader.Test.E; +import test.Ice.classLoader.Test._InitialDisp; + +public final class InitialI extends _InitialDisp +{ + public + InitialI(Ice.ObjectAdapter adapter) + { + _adapter = adapter; + } + + public ConcreteClass + getConcreteClass(Ice.Current current) + { + return new ConcreteClass(); + } + + public AbstractClass + getAbstractClass(Ice.Current current) + { + return new AbstractClassI(); + } + + public void + throwException(Ice.Current current) + throws E + { + throw new E(); + } + + public void + shutdown(Ice.Current current) + { + _adapter.getCommunicator().shutdown(); + } + + private Ice.ObjectAdapter _adapter; +} diff --git a/java/test/Ice/classLoader/PasswordCallbackI.java b/java/test/Ice/classLoader/PasswordCallbackI.java new file mode 100644 index 00000000000..3fc9260e8de --- /dev/null +++ b/java/test/Ice/classLoader/PasswordCallbackI.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +public class PasswordCallbackI implements IceSSL.PasswordCallback +{ + public char[] getPassword(String alias) + { + return "password".toCharArray(); + } + + public char[] getTruststorePassword() + { + return "password".toCharArray(); + } + + public char[] getKeystorePassword() + { + return "password".toCharArray(); + } +} diff --git a/java/test/Ice/classLoader/PluginFactoryI.java b/java/test/Ice/classLoader/PluginFactoryI.java new file mode 100644 index 00000000000..4ace4a2bcd7 --- /dev/null +++ b/java/test/Ice/classLoader/PluginFactoryI.java @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +public class PluginFactoryI implements Ice.PluginFactory +{ + static class PluginI implements Ice.Plugin + { + public void initialize() + { + } + + public void destroy() + { + } + } + + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginI(); + } +} diff --git a/java/test/Ice/classLoader/Server.java b/java/test/Ice/classLoader/Server.java new file mode 100644 index 00000000000..fa68d032e53 --- /dev/null +++ b/java/test/Ice/classLoader/Server.java @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package test.Ice.classLoader; + +public class Server extends test.Util.Application +{ + public int run(String[] args) + { + Ice.Communicator communicator = communicator(); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + Ice.Object object = new InitialI(adapter); + adapter.add(object, communicator.stringToIdentity("initial")); + adapter.activate(); + + return WAIT; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.classLoader"); + initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010"); + return initData; + } + + public static void main(String[] args) + { + Server app = new Server(); + int result = app.main("Server", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/classLoader/Test.ice b/java/test/Ice/classLoader/Test.ice new file mode 100644 index 00000000000..b1dbd09b8fc --- /dev/null +++ b/java/test/Ice/classLoader/Test.ice @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +[["java:package:test.Ice.classLoader"]] +module Test +{ + +class ConcreteClass +{ + int i; +}; + +class AbstractClass +{ + void op(); +}; + +exception E {}; + +interface Initial +{ + ConcreteClass getConcreteClass(); + AbstractClass getAbstractClass(); + void throwException() throws E; + void shutdown(); +}; + +}; + +#endif diff --git a/java/test/Ice/classLoader/run.py b/java/test/Ice/classLoader/run.py new file mode 100755 index 00000000000..56d48e628de --- /dev/null +++ b/java/test/Ice/classLoader/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +TestUtil.clientServerTest() + +TestUtil.cleanup() |