KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestPersistenceLifetimeCMTransaction01.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.SLSBPCtxLifeCMTTest00;
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 transaction-scoped persistence context. It uses this test class as client and a
37  * Stateless with transaction-scoped persistence context.
38  * In this scope, the lifecycle of a persistence context ends when the associated transaction ends.
39  * @reference JSR 220 - Persistence API - FINAL DRAFT - 5.6.1
40  * @requirement Application Server must be running; the package
41  * org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.persistencectxlife
42  * must be deployed
43  * @setup gets the reference of the bean.
44  * @author Eduardo Studzinski Estima de Castro
45  * @author Gisele Pinheiro Souza
46  */

47 public class TestPersistenceLifetimeCMTransaction01{
48
49     /**
50      * Bean.
51      */

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

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

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

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

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

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

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

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