KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > ejb2view > SLSBCMTEjb2ViewClient


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SLSBCMTEjb2ViewClient.java 981 2006-07-28 14:16:22Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ejb2view;
26
27 import static org.testng.Assert.fail;
28 import static org.testng.Assert.assertTrue;
29
30 import java.rmi.RemoteException JavaDoc;
31
32 import javax.ejb.CreateException JavaDoc;
33 import javax.ejb.EJB JavaDoc;
34 import javax.ejb.EJBException JavaDoc;
35 import javax.ejb.Remote JavaDoc;
36 import javax.ejb.Stateless JavaDoc;
37 import javax.ejb.TransactionAttribute JavaDoc;
38 import javax.ejb.TransactionAttributeType JavaDoc;
39 import javax.ejb.TransactionRequiredLocalException JavaDoc;
40 import javax.transaction.TransactionRequiredException JavaDoc;
41
42 /**
43  * Verifies if a client with ejb 2.1 view receives the correctly the exceptions when
44  * call the different types of transaction attribute.
45  * @author Gisele Pinheiro Souza
46  * @author Eduardo Studzinski Estima de Castro
47  */

48 @Stateless JavaDoc
49 @Remote JavaDoc(ItfCMTEjb2ViewClient.class)
50 public class SLSBCMTEjb2ViewClient implements ItfCMTEjb2ViewClient {
51
52     /**
53      * Instance of the ejb home.
54      */

55     @EJB JavaDoc
56     private CMTEjb2ViewHome beanHome;
57
58     /**
59      * Instance of ejb local home.
60      */

61     @EJB JavaDoc
62     private CMTEjb2ViewLocalHome beanLocalHome;
63
64     /**
65      * Verifies if a remote client receives the correct exception when call a
66      * method with the transaction attribute Mandatory without transaction context.
67      * @throws RemoteException if a system level error occurs.
68      * @throws CreateException if a creation error occurs.
69      */

70     @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
71     public void testRemoteMandatoryException() throws RemoteException JavaDoc, CreateException JavaDoc {
72         CMTEjb2View bean = beanHome.create();
73         try {
74             bean.attributeMandatory();
75             fail("The container did not throw an exception after a mandatory method had been "
76                     + "called without a transaction context.");
77         } catch (Exception JavaDoc e) {
78             if (!(e instanceof TransactionRequiredException JavaDoc)) {
79                 fail("The bean has 2.1 remote client view and did not receive the correct exception after a mandatory "
80                         + "method had been called without a transaction context. The excepted exception expected was "
81                         + "TransactionRequiredException, but the exception received was " + e.getClass().getName());
82             }
83         }
84     }
85
86     /**
87      * Verifies if a local client receives the correct exception when call a
88      * method with the transaction attribute Mandatory without transaction context.
89      * @throws CreateException if a creation error occurs.
90      */

91     @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
92     public void testLocalMandatoryException() throws CreateException JavaDoc {
93         CMTEjb2LocalView bean = beanLocalHome.create();
94         try {
95             bean.attributeMandatoryLocal();
96             fail("The container did not throw an exception after a mandatory method had been called "
97                     + "without a transaction context.");
98         } catch (Exception JavaDoc e) {
99             if (!(e instanceof TransactionRequiredLocalException JavaDoc)) {
100                 fail("The bean has 2.1 local client view and did not receive the correct exception after a mandatory "
101                         + "method had been called without a transaction context. The excepted exception expected was "
102                         + "TransactionRequiredLocalException, but the exception received was " + e.getClass().getName());
103             }
104         }
105     }
106
107     /**
108      * Verifies if a remote client receives the correct exception when call a
109      * method with the transaction attribute Never with a transaction context.
110      * @throws RemoteException if a system level error occurs.
111      * @throws CreateException if a creation error occurs.
112      */

113     @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRED)
114     public void testRemoteNeverException() throws RemoteException JavaDoc, CreateException JavaDoc {
115         CMTEjb2View bean = beanHome.create();
116         try {
117             bean.attributeNever();
118             fail("The container did not throw an exception after a never method had been called "
119                     + "with a transaction context.");
120         } catch (Exception JavaDoc e) {
121             if (!(e instanceof RemoteException JavaDoc)) {
122                 fail("The bean has 2.1 remote client view and did not receive the correct exception after "
123                         + "a never method had been called with a transaction context. The excepted exception expected "
124                         + "was RemoteException, but the exception received was " + e.getClass().getName());
125             }
126         }
127     }
128
129     /**
130      * Verifies if a local client receives the correct exception when call a
131      * method with the transaction attribute Never with a transaction context.
132      * @throws CreateException if a creation error occurs.
133      */

134     @TransactionAttribute JavaDoc(TransactionAttributeType.REQUIRED)
135     public void testLocalNeverException() throws CreateException JavaDoc {
136         CMTEjb2LocalView bean = beanLocalHome.create();
137         try {
138             bean.attributeNeverLocal();
139             fail("The container did not throw an exception after a never method had been called "
140                     + "with a transaction context.");
141         } catch (Exception JavaDoc e) {
142             if (!(e instanceof EJBException JavaDoc)) {
143                 fail("The bean has 2.1 local client view and did not receive the correct exception after a never method "
144                         + "had been called with a transaction context. The excepted exception expected was EJBException, "
145                         + "but the exception received was " + e.getClass().getName());
146             }
147         }
148     }
149
150     /**
151      * Verifies the identity for stateless bean.
152      * @throws RemoteException if a system level error occurs.
153      * @throws CreateException if a creation error occurs.
154      */

155     public void testIdentity() throws RemoteException JavaDoc, CreateException JavaDoc {
156         CMTEjb2View bean1 = beanHome.create();
157         CMTEjb2View bean2 = beanHome.create();
158
159         assertTrue(bean1.isIdentical(bean1), "The isIdentical method is not working for stateless beans");
160         assertTrue(bean1.isIdentical(bean2), "The isIdentical method is not working for stateless beans");
161     }
162 }
163
Popular Tags