1 22 package org.jboss.test; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.util.UnexpectedThrowable; 26 27 33 public abstract class AbstractSystemTest extends AbstractTestCaseWithSetup 34 { 35 private static Logger staticLog = Logger.getLogger(AbstractSystemTest.class); 36 37 public static void checkThrowableDeep(Class <? extends Throwable > expected, Throwable throwable) throws Exception 39 { 40 assertNotNull(expected); 41 assertNotNull(throwable); 42 43 Throwable 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 ) 51 throw (Exception ) original; 52 else if (original instanceof Error ) 53 throw (Error ) 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 public static <T> T assertInstanceOf(Class <T> expected, Object object) throws Exception 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 78 public AbstractSystemTest(String name) 79 { 80 super(name); 81 } 82 83 90 public static AbstractTestDelegate getDelegate(Class clazz) throws Exception 91 { 92 AbstractTestDelegate delegate = new AbstractTestDelegate(clazz); 93 delegate.enableSecurity = true; 94 return delegate; 95 } 96 } 97 | Popular Tags |