1 22 package org.jboss.ejb3.test.regression.ejbthree485.unit; 23 24 import java.rmi.RMISecurityManager ; 25 26 import javax.naming.Context ; 27 import junit.framework.Test; 28 29 import org.jboss.ejb3.test.regression.ejbthree485.MyException; 30 import org.jboss.ejb3.test.regression.ejbthree485.MyRemote; 31 import org.jboss.test.JBossTestCase; 32 33 39 public class ClassNameTestCase extends JBossTestCase 40 { 41 public ClassNameTestCase(String name) 42 { 43 super(name); 44 } 45 46 public void testException() throws Exception { 47 Context ctx = getInitialContext(); 48 MyRemote remote = (MyRemote) ctx.lookup("StatelessBean/remote"); 49 try { 50 remote.giveMeAnException(); 51 52 fail("expected an exception"); 53 } 54 catch(MyException e) { 55 e.printStackTrace(); 56 57 StackTraceElement stackTrace[] = e.getStackTrace(); 58 int i = 0; 59 while(i < stackTrace.length && !stackTrace[i].getClassName().equals(ClassNameTestCase.class.getName())) 60 i++; 61 i--; 63 String actual = stackTrace[i].getClassName(); 64 String expected = "?"; 65 assertFalse("class name must not start with $Proxy", actual.startsWith("$Proxy")); 66 assertEquals(expected, actual); 67 return; 68 } 69 } 70 71 public void testRuntimeException() throws Exception { 72 Context ctx = getInitialContext(); 73 MyRemote remote = (MyRemote) ctx.lookup("StatelessBean/remote"); 74 try { 75 remote.giveMeARuntimeException(); 76 77 fail("expected an exception"); 78 } 79 catch(RuntimeException re) { 80 Throwable e = re.getCause(); 81 StackTraceElement stackTrace[] = e.getStackTrace(); 82 int i = 0; 83 while(i < stackTrace.length && !stackTrace[i].getClassName().equals(ClassNameTestCase.class.getName())) 84 i++; 85 i--; 87 String actual = stackTrace[i].getClassName(); 88 String expected = "?"; 89 assertFalse("class name must not start with $Proxy", actual.startsWith("$Proxy")); 90 assertEquals(expected, actual); 91 } 92 } 93 94 public static Test suite() throws Exception 95 { 96 return getDeploySetup(ClassNameTestCase.class, "ejbthree485.jar"); 97 } 98 } 99 | Popular Tags |