📄 exceptiontestcase.java
字号:
/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Exoffice Technologies. For written permission, * please contact info@exolab.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Exoffice Technologies. Exolab is a registered * trademark of Exoffice Technologies. * * 5. Due credit should be given to the Exolab Project * (http://www.exolab.org/). * * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2004-2005 (C) Exoffice Technologies Inc. All Rights Reserved. * * $Id: ExceptionTestCase.java,v 1.4 2005/05/24 05:50:56 tanderson Exp $ */package org.exolab.jms.net.invoke;import java.rmi.RemoteException;import java.util.Map;import java.util.HashMap;import java.io.IOException;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import junit.framework.AssertionFailedError;import junit.framework.Protectable;import junit.framework.TestCase;import org.exolab.jms.net.ExceptionService;import org.exolab.jms.net.ExceptionServiceImpl;import org.exolab.jms.net.orb.ORB;import org.exolab.jms.net.orb.ORBFactory;import org.exolab.jms.net.proxy.Proxy;import org.exolab.jms.net.proxy.RemoteInvocationException;import org.exolab.jms.net.registry.Registry;import org.exolab.jms.net.util.SSLUtil;/** * Tests exception handling. * * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> * @version $Revision: 1.4 $ $Date: 2005/05/24 05:50:56 $ */public abstract class ExceptionTestCase extends TestCase { /** * The export URI. */ private final String _uri; /** * The route URI. */ private final String _routeURI; /** * Connection properties used when establishing a connection to the remote * ORB. May be <code>null</code> */ private final Map _connectionProps; /** * Connection properties used when constructing the local ORB. May * be <code>null</code> */ private final Map _acceptorProps; /** * The ORB. */ private ORB _orb; /** * The exception service proxy. */ private ExceptionService _service; /** * The logger. */ private static final Log _log = LogFactory.getLog(ExceptionTestCase.class); /** * Exception service name. */ private static final String EXCEPTION_SERVICE = "exception"; /** * Construct an instance of this class for a specific test case. * * @param name the name of test case * @param uri the export URI */ public ExceptionTestCase(String name, String uri) { this(name, uri, null, null); } /** * Construct an instance of this class for a specific test case. * * @param name the name of test case * @param uri the export URI * @param routeURI the route URI */ public ExceptionTestCase(String name, String uri, String routeURI) { this(name, uri, routeURI, null, null); } /** * Construct an instance of this class for a specific test case. * * @param name the name of test case * @param uri the export URI * @param properties connection properties. May be <code>null</code> */ public ExceptionTestCase(String name, String uri, Map properties) { this(name, uri, null, properties, properties); } /** * Construct an instance of this class for a specific test case. * * @param name the name of test case * @param uri the export URI * @param routeURI the route URI * @param properties connection properties. May be <code>null</code> */ public ExceptionTestCase(String name, String uri, String routeURI, Map properties) { this(name, uri, routeURI, properties, properties); } /** * Construct an instance of this class for a specific test case. * * @param name the name of test case * @param uri the export URI * @param routeURI the route URI * @param connectionProps connection properties. May be <code>null</code> * @param acceptorProps acceptor properites. May be <code>null</code> */ public ExceptionTestCase(String name, String uri, String routeURI, Map connectionProps, Map acceptorProps) { super(name); _uri = uri; _routeURI = routeURI; _connectionProps = connectionProps; _acceptorProps = acceptorProps; } /** * Verifies that a declared <code>Throwable</code> is propagated to the * client. * * @throws Exception for any error */ public void testDeclaredThrowable() throws Exception { Protectable protectable = new Protectable() { public void protect() throws Throwable { _service.throwThrowable(); } }; checkException(protectable, Throwable.class, null); } /** * Verifies that a declared <code>Exception</code> is propagated to the * client. * * @throws Exception for any error */ public void testDeclaredException() throws Exception { Protectable protectable = new Protectable() { public void protect() throws Throwable { _service.throwException(); } }; checkException(protectable, Exception.class, null); } /** * Verifies that a declared <code>Error</code> is propagated to the client. * * @throws Exception for any error */ public void testDeclaredError() throws Exception { Protectable protectable = new Protectable() { public void protect() throws Throwable { _service.throwError(); } }; checkException(protectable, Error.class, null); } /** * Verifies that an undeclared <code>Error</code> is propagated to the * client, wrapped in a {@link RemoteInvocationException}. * * @throws Exception for any error */ public void testUndeclaredError() throws Exception { Protectable protectable = new Protectable() { public void protect() throws Throwable { _service.throwUndeclaredError(); } }; checkException(protectable, RemoteInvocationException.class,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -