KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > test > XAExceptionUnitTestCase


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.jca.test;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.transaction.TransactionRolledbackException JavaDoc;
27
28 import junit.framework.Test;
29
30 import org.jboss.test.JBossTestCase;
31 import org.jboss.test.jca.interfaces.XAExceptionSession;
32 import org.jboss.test.jca.interfaces.XAExceptionSessionHome;
33 import org.jboss.test.jca.interfaces.XAExceptionTestSession;
34 import org.jboss.test.jca.interfaces.XAExceptionTestSessionHome;
35
36 /**
37  * XAExceptionUnitTestCase.java
38  *
39  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
40  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
41  * @version <tt>$Revision: 37406 $</tt>
42  */

43 public class XAExceptionUnitTestCase extends JBossTestCase
44 {
45    public XAExceptionUnitTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    public static Test suite() throws Exception JavaDoc
51    {
52       Test t1 = getDeploySetup(XAExceptionUnitTestCase.class, "jcatest.jar");
53       Test t2 = getDeploySetup(t1, "testadapter-ds.xml");
54       return getDeploySetup(t2, "jbosstestadapter.rar");
55    }
56
57    public void testXAExceptionToTransactionRolledbackException() throws Exception JavaDoc
58    {
59       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
60       XAExceptionSession x = xh.create();
61       try
62       {
63          x.testXAExceptionToTransactionRolledbackException();
64       }
65       catch (TransactionRolledbackException JavaDoc tre)
66       {
67          getLog().info("testXAExceptionToRollbackException passed");
68          return;
69       }
70       fail("expected TransactionRolledbackException not thrown");
71    }
72
73    public void testXAExceptionToTransactionRolledbackExceptionOnServer() throws Exception JavaDoc
74    {
75       XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome");
76       XAExceptionTestSession xt = xth.create();
77       xt.testXAExceptionToTransactionRolledbackException();
78    }
79
80    public void testXAExceptionToTransactionRolledbackLocalExceptionOnServer() throws Exception JavaDoc
81    {
82       XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome");
83       XAExceptionTestSession xt = xth.create();
84       xt.testXAExceptionToTransactionRolledbackLocalException();
85    }
86
87    public void testRMERRInOnePCToTransactionRolledbackException() throws Exception JavaDoc
88    {
89       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
90       XAExceptionSession x = xh.create();
91       try
92       {
93          x.testRMERRInOnePCToTransactionRolledbackException();
94       }
95       catch (TransactionRolledbackException JavaDoc tre)
96       {
97          getLog().info("testXAExceptionToRollbackException passed");
98          return;
99       }
100       fail("expected TransactionRolledbackException not thrown");
101    }
102
103    public void testRMERRInOnePCToTransactionRolledbackExceptionOnServer() throws Exception JavaDoc
104    {
105       XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome");
106       XAExceptionTestSession xt = xth.create();
107       xt.testRMERRInOnePCToTransactionRolledbackException();
108    }
109
110    public void testXAExceptionToTransactionRolledbacLocalkExceptionOnServer() throws Exception JavaDoc
111    {
112       XAExceptionTestSessionHome xth = (XAExceptionTestSessionHome)getInitialContext().lookup("test/XAExceptionTestSessionHome");
113       XAExceptionTestSession xt = xth.create();
114       xt.testXAExceptionToTransactionRolledbacLocalkException();
115    }
116
117    public void testSimulateConnectionError() throws Exception JavaDoc
118    {
119       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
120       XAExceptionSession x = xh.create();
121       x.simulateConnectionError();
122    }
123
124    public void testSimulateConnectionErrorWithTwoHandles() throws Exception JavaDoc
125    {
126       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
127       XAExceptionSession x = xh.create();
128       x.simulateConnectionErrorWithTwoHandles();
129    }
130
131    public void testGetConnectionResourceError() throws Exception JavaDoc
132    {
133       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
134       XAExceptionSession x = xh.create();
135       try
136       {
137          x.simulateError("getConnectionResource", 10);
138       }
139       finally
140       {
141          flushConnections();
142       }
143    }
144
145    public void testGetConnectionRuntimeError() throws Exception JavaDoc
146    {
147       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
148       XAExceptionSession x = xh.create();
149       try
150       {
151          x.simulateError("getConnectionRuntime", 10);
152       }
153       finally
154       {
155          flushConnections();
156       }
157    }
158
159    public void testCreateManagedConnectionResourceError() throws Exception JavaDoc
160    {
161       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
162       XAExceptionSession x = xh.create();
163       try
164       {
165          x.simulateFactoryError("createManagedConnectionResource", 10);
166       }
167       finally
168       {
169          flushConnections();
170       }
171    }
172
173    public void testCreateManagedConnectionRuntimeError() throws Exception JavaDoc
174    {
175       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
176       XAExceptionSession x = xh.create();
177       try
178       {
179          x.simulateFactoryError("createManagedConnectionRuntime", 10);
180       }
181       finally
182       {
183          flushConnections();
184       }
185    }
186
187    public void testMatchManagedConnectionResourceError() throws Exception JavaDoc
188    {
189       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
190       XAExceptionSession x = xh.create();
191       try
192       {
193          x.simulateFactoryError("matchManagedConnectionResource", 10);
194       }
195       finally
196       {
197          flushConnections();
198       }
199    }
200
201    public void testMatchManagedConnectionRuntimeError() throws Exception JavaDoc
202    {
203       XAExceptionSessionHome xh = (XAExceptionSessionHome)getInitialContext().lookup("test/XAExceptionSessionHome");
204       XAExceptionSession x = xh.create();
205       try
206       {
207          x.simulateFactoryError("matchManagedConnectionRuntime", 10);
208       }
209       finally
210       {
211          flushConnections();
212       }
213    }
214
215    protected void flushConnections()
216    {
217       try
218       {
219          MBeanServerConnection JavaDoc server = getServer();
220          server.invoke(new ObjectName JavaDoc("jboss.jca:service=ManagedConnectionPool,name=JBossTestCF"), "flush", new Object JavaDoc[0], new String JavaDoc[0]);
221       }
222       catch (Exception JavaDoc e)
223       {
224          log.warn("Unable to flush connections", e);
225       }
226    }
227 }
228
Popular Tags