KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > persistence > lifetime > TestPersistenceLifetimeCMExtended01


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: TestPersistenceLifetimeCMExtended01.java 979 2006-07-28 13:19:50Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.persistence.lifetime;
26
27 import static org.objectweb.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
28
29 import org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.persistencectxlife.SLSBPCtxLifeCMETest00;
30 import org.objectweb.easybeans.tests.common.interfaces.ItfTestPCtxLifeCM00;
31 import org.testng.annotations.AfterMethod;
32 import org.testng.annotations.BeforeMethod;
33 import org.testng.annotations.Test;
34
35 /**
36  * Tests container-managed extended-scoped persistence context. It uses a Stateless as client and a
37  * Stateful with extendended-scoped persistence context.
38  * @reference JSR 220 - Persistence API - FINAL DRAFT - 5.6.2
39  * @requirement Application Server must be running; the package
40  * org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.persistencectxlife
41  * must be deployed
42  * @setup gets the reference of the bean.
43  * @author Eduardo Studzinski Estima de Castro
44  * @author Gisele Pinheiro Souza
45  */

46 public class TestPersistenceLifetimeCMExtended01{
47
48     /**
49      * Bean.
50      */

51     private ItfTestPCtxLifeCM00 bean;
52
53     /**
54      * Gets bean instances used in the tests.
55      * @throws Exception if there is a problem with the bean initialization.
56      */

57     @BeforeMethod
58     public void startUp() throws Exception JavaDoc {
59         bean = getBeanRemoteInstance(SLSBPCtxLifeCMETest00.class, ItfTestPCtxLifeCM00.class);
60         bean.startUp();
61     }
62
63     /**
64      * This test begins a transaction, creates an entity and rolls back the transaction.
65      * The entity must not exists after the rollback and the entity instance must become detached.
66      * A rollback in a transaction, which is used with the persistence context,
67      * always turns detached all entities associated with the persistence context.
68      * @input UserTransaction and entity.
69      * @output After the rollback, the bean must not exists.
70      * @throws Exception if a problem occurs.
71      */

72     @Test
73     public void test00() throws Exception JavaDoc {
74         bean.test00();
75     }
76
77     /**
78      * This test begins a transaction, creates an entity and commits the transaction. The entity must
79      * exists after the commit and it must remains managed, because it is an extended persistence context.
80      * @input With a client transaction, invocation of a bean method which creates an entity.
81      * @output After the commit, the bean must remains managed.
82      * @throws Exception if a problem occurs.
83      */

84     @Test
85     public void test01() throws Exception JavaDoc {
86         bean.test01();
87     }
88
89     /**
90      * This test begins a transaction and creates an entity. As it uses an extended persistence context,
91      * the entity must be managed after its creation. After this step,
92      * the test rolls back the transaction and the entity must become detached.
93      * @input With a client transaction, invocation of a bean method which creates an entity.
94      * @output An detached entity.
95      * @throws Exception if a problem occurs.
96      */

97     @Test
98     public void test02() throws Exception JavaDoc {
99         bean.test02();
100     }
101
102     /**
103      * This test creates an entity and verifies if it remains managed.
104      * In this test, the transaction is created by the container for each bean method invocation,
105      * however, as it is an extended persistence context, it must remains managed.
106      * @input Without providing a client transaction, invocation of a bean method which creates an entity and persists it.
107      * @output A managed entity.
108      * @throws Exception if a problem occurs.
109      */

110     @Test
111     public void test03() throws Exception JavaDoc {
112         bean.test03();
113     }
114
115     /**
116      * This test creates an entity, persist the entity and verifies if it remains managed.
117      * In this test, the transaction is created by the container for each bean method invocation,
118      * however, as it is an extended persistence context, it must remains managed.
119      * @input Without providing a client transaction, invocation of a bean method which creates an entity and persists it.
120      * @output A managed entity.
121      * @throws Exception if a problem occurs.
122      */

123     @Test
124     public void test04() throws Exception JavaDoc {
125         bean.test04();
126     }
127
128     /**
129      * Cleans the test results.
130      * @throws Exception if a problem occurs
131      */

132     @AfterMethod
133     public void tearDown() throws Exception JavaDoc {
134         bean.tearDown();
135     }
136 }
137
Popular Tags