KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > transaction > containermanaged > stateless > TestInheritance


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: TestInheritance.java 980 2006-07-28 13:20:32Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.transaction.containermanaged.stateless;
26
27 import javax.transaction.UserTransaction JavaDoc;
28
29 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.inheritance.ItfCMTInheritance;
30 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.inheritance.SLSBCMTInheritance;
31 import org.objectweb.easybeans.tests.common.helper.EJBHelper;
32 import org.objectweb.easybeans.tests.common.helper.TransactionHelper;
33 import org.testng.annotations.BeforeMethod;
34 import org.testng.annotations.Test;
35
36 /**
37  * Verifies if the inheritance in container-managed transaction is
38  * following the JSR 220.The item covered in this test are: 13.37.1.
39  * @reference JSR 220-FINAL RELEASE
40  * @requirement Application Server must be running; the bean
41  * SLSBCMTInheritance
42  * must be deployed.
43  * @setup gets the reference of the bean
44  * @author Gisele Pinheiro Souza
45  * @author Eduardo Studzinski Estima de Castro
46  */

47 public class TestInheritance {
48
49     /**
50      * Bean used during the tests.
51      */

52     private ItfCMTInheritance slsbCMTInheritance;
53
54     /**
55      * Creates the stateless bean used during the tests.
56      * @throws Exception if an error occurs during the lookup.
57      */

58     @BeforeMethod
59     public void setup() throws Exception JavaDoc {
60         slsbCMTInheritance = EJBHelper.getBeanRemoteInstance(SLSBCMTInheritance.class, ItfCMTInheritance.class);
61     }
62
63     /**
64      * Verifies if the transaction attribute define for the class is the same
65      * for all class methods. The class transaction attribute is never and the
66      * method is called in a transaction context, so the method must throw an
67      * exception.
68      * @input -
69      * @output an EJBException.
70      * @throws Exception if an error occurs.
71      */

72     @Test(expectedExceptions = javax.ejb.EJBException JavaDoc.class)
73     public void testClassDefinition() throws Exception JavaDoc {
74         UserTransaction JavaDoc utx = TransactionHelper.getInternalUserTransaction();
75         try {
76             utx.begin();
77             slsbCMTInheritance.dummyMethod1();
78         } finally {
79             utx.rollback();
80         }
81     }
82
83     /**
84      * Verifies if the transaction attribute defined in a method overrides the
85      * class transaction attribute. The method transaction attribute is
86      * mandatory and the method is called without a transaction context, so the
87      * method must throw an exception.
88      * @input -
89      * @output an EJBException.
90      * @throws Exception if an error occurs.
91      */

92     @Test(expectedExceptions = javax.ejb.EJBException JavaDoc.class)
93     public void testMethodDefinition() throws Exception JavaDoc {
94         slsbCMTInheritance.dummyMethod2();
95
96     }
97
98     /**
99      * Verifies if the transaction attribute defined in the class method overrides the
100      * transaction attribute defined in the superclass. The method transaction
101      * attribute is mandatory and the method is called without a transaction
102      * context, so the method must throw an exception.
103      * @input -
104      * @output an EJBException.
105      * @throws Exception if an error occurs.
106      */

107     @Test(expectedExceptions = javax.ejb.EJBException JavaDoc.class)
108     public void testOverrideSuperclassDefinition1() throws Exception JavaDoc {
109         slsbCMTInheritance.dummyMethod3();
110
111     }
112
113     /**
114      * Verifies if the transaction attribute defined in the class method overrides the
115      * transaction attribute defined in the superclass. The method transaction
116      * attribute is required, so the method must not throw an exception.
117      * @input -
118      * @output a correct method execution.
119      * @throws Exception if an error occurs.
120      */

121     @Test
122     public void testOverrideSuperclassDefinition2() throws Exception JavaDoc {
123         UserTransaction JavaDoc utx = TransactionHelper.getInternalUserTransaction();
124         try {
125             utx.begin();
126             slsbCMTInheritance.dummyMethod4();
127         } finally {
128             utx.rollback();
129         }
130     }
131 }
132
Popular Tags