KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > regression > ejbthree485 > unit > ClassNameTestCase


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.ejb3.test.regression.ejbthree485.unit;
23
24 import java.rmi.RMISecurityManager JavaDoc;
25
26 import javax.naming.Context JavaDoc;
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 /**
34  * Comment
35  *
36  * @author <a HREF="mailto:carlo@nerdnet.nl">Carlo de Wolf</a>
37  * @version $Revision: 46054 $
38  */

39 public class ClassNameTestCase extends JBossTestCase
40 {
41    public ClassNameTestCase(String JavaDoc name)
42    {
43       super(name);
44    }
45
46    public void testException() throws Exception JavaDoc {
47       Context JavaDoc 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 JavaDoc stackTrace[] = e.getStackTrace();
58          int i = 0;
59          while(i < stackTrace.length && !stackTrace[i].getClassName().equals(ClassNameTestCase.class.getName()))
60             i++;
61          //assertTrue(i < stackTrace.length); // let's error if this happens
62
i--;
63          String JavaDoc actual = stackTrace[i].getClassName();
64          String JavaDoc 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 JavaDoc {
72       Context JavaDoc 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 JavaDoc re) {
80          Throwable JavaDoc e = re.getCause();
81          StackTraceElement JavaDoc stackTrace[] = e.getStackTrace();
82          int i = 0;
83          while(i < stackTrace.length && !stackTrace[i].getClassName().equals(ClassNameTestCase.class.getName()))
84             i++;
85          //assertTrue(i < stackTrace.length); // let's error if this happens
86
i--;
87          String JavaDoc actual = stackTrace[i].getClassName();
88          String JavaDoc 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 JavaDoc
95    {
96       return getDeploySetup(ClassNameTestCase.class, "ejbthree485.jar");
97    }
98 }
99
Popular Tags