KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > txexceptions > unit > TxExceptionsTestCase


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.txexceptions.unit;
23
24 import javax.ejb.EJBException JavaDoc;
25 import org.jboss.ejb3.test.txexceptions.AnnotatedAppException;
26 import org.jboss.ejb3.test.txexceptions.DeploymentDescriptorAppException;
27 import org.jboss.ejb3.test.txexceptions.AppException;
28 import org.jboss.ejb3.test.txexceptions.CheckedRollbackException;
29 import org.jboss.ejb3.test.txexceptions.DeploymentDescriptorCheckedRollbackException;
30 import org.jboss.ejb3.test.txexceptions.Dao;
31 import org.jboss.ejb3.test.txexceptions.NoRollbackRemoteException;
32 import org.jboss.ejb3.test.txexceptions.NoRollbackRuntimeException;
33 import org.jboss.ejb3.test.txexceptions.RollbackRemoteException;
34 import org.jboss.ejb3.test.txexceptions.RollbackRuntimeException;
35 import org.jboss.ejb3.test.txexceptions.SimpleEntity;
36 import org.jboss.test.JBossTestCase;
37 import junit.framework.Test;
38
39 /**
40  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
41  * @version $Revision: 58110 $
42  */

43 public class TxExceptionsTestCase extends JBossTestCase
44 {
45    org.jboss.logging.Logger log = getLog();
46
47    static boolean deployed = false;
48    static int test = 0;
49
50    public TxExceptionsTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    public void testRequiresNewWithLookedUpEntityManager() throws Exception JavaDoc
56    {
57       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
58       dao.testRequiresNewWithLookedUpEntityManager();
59    }
60    public void testAnnotatedAppException() throws Exception JavaDoc
61    {
62       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
63
64       boolean exceptionThrown = false;
65       try
66       {
67          dao.createThrowAnnotatedAppException(1);
68       }
69       catch (AnnotatedAppException e)
70       {
71          exceptionThrown = true;
72       }
73       assertTrue(exceptionThrown);
74       assertNotNull(dao.get(1));
75       dao.remove(1);
76    }
77    
78    public void testDeploymentDescriptorAppException() throws Exception JavaDoc
79    {
80       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
81
82       boolean exceptionThrown = false;
83       try
84       {
85          dao.createThrowDeploymentDescriptorAppException(1);
86       }
87       catch (DeploymentDescriptorAppException e)
88       {
89          exceptionThrown = true;
90       }
91       assertTrue(exceptionThrown);
92       assertNotNull(dao.get(1));
93       dao.remove(1);
94    }
95
96    public void testAppException() throws Exception JavaDoc
97    {
98       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
99
100       boolean exceptionThrown = false;
101       try
102       {
103          dao.createThrowAppException(1);
104       }
105       catch (AppException e)
106       {
107          exceptionThrown = true;
108       }
109       assertTrue(exceptionThrown);
110       assertNotNull(dao.get(1));
111       dao.remove(1);
112    }
113
114    public void testNoRollbackRemoteException() throws Exception JavaDoc
115    {
116       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
117
118       boolean exceptionThrown = false;
119       try
120       {
121          dao.createThrowNoRollbackRemoteException(1);
122       }
123       catch (NoRollbackRemoteException e)
124       {
125          exceptionThrown = true;
126       }
127       assertTrue(exceptionThrown);
128       assertNotNull(dao.get(1));
129       dao.remove(1);
130    }
131
132    public void testNoRollbackRuntimexception() throws Exception JavaDoc
133    {
134       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
135
136       boolean exceptionThrown = false;
137       try
138       {
139          dao.createThrowNoRollbackRuntimeException(1);
140       }
141       catch (NoRollbackRuntimeException e)
142       {
143          exceptionThrown = true;
144       }
145       assertTrue(exceptionThrown);
146       assertNotNull(dao.get(1));
147       dao.remove(1);
148    }
149
150    public void testDeploymentDescriptorCheckedRollbackException() throws Exception JavaDoc
151    {
152       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
153
154       try
155       {
156          dao.createThrowDeploymentDescriptorCheckedRollbackException(1);
157          fail();
158       }
159       catch (DeploymentDescriptorCheckedRollbackException e)
160       {
161       }
162
163       SimpleEntity entity = dao.get(1);
164       
165       if (entity != null)
166          dao.remove(1);
167       
168       assertNull(entity);
169    }
170    
171    public void testCheckedRollbackException() throws Exception JavaDoc
172    {
173       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
174
175       try
176       {
177          dao.createThrowCheckedRollbackException(1);
178          fail();
179       }
180       catch (CheckedRollbackException e)
181       {
182       }
183
184       SimpleEntity entity = dao.get(1);
185       
186       if (entity != null)
187          dao.remove(1);
188       
189       assertNull(entity);
190    }
191
192    public void testRollbackRemoteException() throws Exception JavaDoc
193    {
194       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
195
196       try
197       {
198          dao.createThrowRollbackRemoteException(1);
199          fail();
200       }
201       catch (RollbackRemoteException e)
202       {
203       }
204   
205       SimpleEntity entity = dao.get(1);
206       
207       if (entity != null)
208          dao.remove(1);
209       
210       assertNull(entity);
211    }
212
213    public void testRollbackRuntimeException() throws Exception JavaDoc
214    {
215       Dao dao = (Dao) getInitialContext().lookup("DaoBean/remote");
216
217       try
218       {
219          dao.createThrowRollbackRuntimeException(1);
220          fail();
221       }
222       catch (EJBException JavaDoc e)
223       {
224          assertTrue(e.getCausedByException() instanceof RollbackRuntimeException);
225       }
226      
227       SimpleEntity entity = dao.get(1);
228       
229       if (entity != null)
230          dao.remove(1);
231       
232       assertNull(entity);
233    }
234
235    public static Test suite() throws Exception JavaDoc
236    {
237       return getDeploySetup(TxExceptionsTestCase.class, "txexceptions-test.jar");
238    }
239 }
Popular Tags