KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > sessionbean > stateful > remove > TestSFRemove


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: TestSFRemove.java 972 2006-07-27 17:01:14Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.sessionbean.stateful.remove;
26
27 import static org.objectweb.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
28
29 import javax.ejb.NoSuchEJBException JavaDoc;
30
31 import org.objectweb.easybeans.log.JLog;
32 import org.objectweb.easybeans.log.JLogFactory;
33 import org.objectweb.easybeans.tests.common.ejbs.base.ItfCheck00;
34 import org.objectweb.easybeans.tests.common.ejbs.base.ItfCheck02;
35 import org.objectweb.easybeans.tests.common.ejbs.base.ItfCheck03;
36 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.remove.SFSBRemove00;
37 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.remove.SFSBRemoveByException;
38 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.remove.SFSBRemoveWithRetain;
39 import org.objectweb.easybeans.tests.common.exception.AppException;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
42
43 /**
44  * Tests related with stateful instance remove operation.
45  * @reference JSR 220 - EJB 3.0 Core - 4.3.11
46  * @requirement Application Server must be running.<br>
47  * (Ant task: install.jar.tests.stateful.remove)
48  * @author Eduardo Studzinski Estima de Castro
49  * @author Gisele Pinheiro Souza
50  */

51 public class TestSFRemove {
52
53     /**
54      * Log helper.
55      */

56     private JLog logger = JLogFactory.getLog(TestSFRemove.class);
57
58     /**
59      * Bean.
60      */

61     private ItfCheck02 beanRemoveDefault;
62
63     /**
64      * Bean.
65      */

66     private ItfCheck00 beanRemoveByException;
67
68     /**
69      * Bean.
70      */

71     private ItfCheck03 beanRetain;
72
73     /**
74      * Gets bea instances used in the tests.
75      * @throws Exception if there is a problem with bean initialization.
76      */

77     @BeforeClass
78     public void startUp() throws Exception JavaDoc {
79         beanRemoveDefault = getBeanRemoteInstance(SFSBRemove00.class, ItfCheck02.class);
80         beanRemoveByException = getBeanRemoteInstance(SFSBRemoveByException.class, ItfCheck00.class);
81         beanRetain = getBeanRemoteInstance(SFSBRemoveWithRetain.class, ItfCheck03.class);
82     }
83
84     /**
85      * Verifies if the bean is destroyed after the remove() invocation.
86      * @input -
87      * @output NoSuchEJBException
88      * @throws Exception if a problem occurs.
89      */

90     @Test(expectedExceptions = { NoSuchEJBException JavaDoc.class })
91     public void testRemoveMethod() throws Exception JavaDoc {
92         beanRemoveDefault.remove();
93         beanRemoveDefault.check();
94     }
95
96     /**
97      * Verifies if the bean is destroyed after a system exception.
98      * @input -
99      * @output NoSuchEJBException
100      * @throws Exception if a problem occurs.
101      */

102     @Test(expectedExceptions = { NoSuchEJBException JavaDoc.class })
103     public void testRemoveBySystemException() throws Exception JavaDoc {
104         try {
105             beanRemoveByException.check();
106         } catch (Exception JavaDoc e) {
107             logger.debug("Exception.");
108         }
109         beanRemoveByException.check();
110     }
111
112     /**
113      * Verifies if the bean is not destroyed after an application exception
114      * during the remote() method invocation.
115      * @input -
116      * @output NoSuchEJBException
117      * @throws Exception if a problem occurs.
118      */

119     @Test
120     public void testRetain() throws Exception JavaDoc {
121         try {
122             beanRetain.remove();
123         }catch (AppException e) {
124             logger.debug("Expected Exception occured.");
125         }catch (Exception JavaDoc e) {
126             logger.debug("Exception");
127         }
128         beanRetain.check();
129     }
130 }
131
Popular Tags