01: // Copyright © 2004-2005 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.boundary;
03:
04: import com.canoo.webtest.extension.applet.AbstractAppletTag;
05: import com.canoo.webtest.extension.applet.runner.Context;
06: import org.apache.log4j.Logger;
07: import org.netbeans.jemmy.JemmyException;
08:
09: import java.net.MalformedURLException;
10: import java.net.URLClassLoader;
11:
12: /**
13: * Boundary class for {@link com.canoo.webtest.extension.applet.runner.AppletRunner}.
14: *
15: * @author Paul King
16: */
17: public class AppletRunnerBoundary {
18: private static final Logger LOG = Logger
19: .getLogger(AppletRunnerBoundary.class);
20:
21: public static Object assertObjectHasCorrectClass(
22: final Class expectedClass, final Object object,
23: final String msg) throws Exception {
24: if (expectedClass.isInstance(object)) {
25: return object;
26: }
27: final String error = "Expected class " + expectedClass
28: + " but found " + object.getClass().getName();
29: LOG.error(msg + error);
30: throw new Exception(msg + error);
31: }
32:
33: public static URLClassLoader tryCreateUrlClassLoader(
34: final AbstractAppletTag appletTag,
35: final ClassLoader classLoader) throws Exception {
36: try {
37: return new URLClassLoader(appletTag.getArchiveURL(),
38: classLoader);
39: } catch (MalformedURLException e) {
40: final String msg = "Can't build classpath url for "
41: + appletTag.getCode();
42: LOG.error(msg, e);
43: throw new Exception(msg + " " + e.getMessage());
44: }
45: }
46:
47: public static void storeJemmyExceptionIfNeeded(
48: final JemmyException jemmyException,
49: final Context appletContext) {
50: if (jemmyException != null) {
51: appletContext.getAppletPluginResults().setJemmyException(
52: jemmyException);
53: LOG.error(jemmyException.getMessage(), jemmyException);
54: }
55: }
56:
57: public void processClassNotFound(final int classNotFoundErrorCode) {
58: System.exit(classNotFoundErrorCode);
59: }
60:
61: public void processIoException(final int ioErrorCode) {
62: System.exit(ioErrorCode);
63: }
64: }
|