KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > AbstractSystemTest


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.util.UnexpectedThrowable;
26
27 /**
28  * A SystemTest.
29  *
30  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
31  * @version $Revision: 1.2 $
32  */

33 public abstract class AbstractSystemTest extends AbstractTestCaseWithSetup
34 {
35    private static Logger staticLog = Logger.getLogger(AbstractSystemTest.class);
36    
37    // @fixme move to AbstractTestCase
38
public static void checkThrowableDeep(Class JavaDoc<? extends Throwable JavaDoc> expected, Throwable JavaDoc throwable) throws Exception JavaDoc
39    {
40       assertNotNull(expected);
41       assertNotNull(throwable);
42       
43       Throwable JavaDoc original = throwable;
44       
45       while (throwable.getCause() != null)
46          throwable = throwable.getCause();
47       
48       if (expected.equals(throwable.getClass()) == false)
49       {
50          if (original instanceof Exception JavaDoc)
51             throw (Exception JavaDoc) original;
52          else if (original instanceof Error JavaDoc)
53             throw (Error JavaDoc) original;
54          else
55             throw new UnexpectedThrowable("UnexpectedThrowable", original);
56       }
57       else
58       {
59          staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")");
60       }
61    }
62    
63    // @fixme move to AbstractTestCase
64
public static <T> T assertInstanceOf(Class JavaDoc<T> expected, Object JavaDoc object) throws Exception JavaDoc
65    {
66       if (object == null)
67          return null;
68       assertTrue(object.getClass(). getName() + " is not an instance of " + expected.getName(), expected.isInstance(object));
69       return expected.cast(object);
70    }
71    
72
73    /**
74     * Create a new ContainerTest.
75     *
76     * @param name the test name
77     */

78    public AbstractSystemTest(String JavaDoc name)
79    {
80       super(name);
81    }
82    
83    /**
84     * Default setup with security manager enabled
85     *
86     * @param clazz the class
87     * @return the delegate
88     * @throws Exception for any error
89     */

90    public static AbstractTestDelegate getDelegate(Class JavaDoc clazz) throws Exception JavaDoc
91    {
92       AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
93       delegate.enableSecurity = true;
94       return delegate;
95    }
96 }
97
Popular Tags