001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TestPersistenceLifetimeCMTransaction01.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.persistence.lifetime;
025:
026: import static org.ow2.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
027:
028: import org.ow2.easybeans.tests.common.ejbs.stateless.beanmanaged.persistencectxlife.SLSBPCtxLifeCMTTest00;
029: import org.ow2.easybeans.tests.common.interfaces.ItfTestPCtxLifeCM00;
030: import org.testng.annotations.AfterMethod;
031: import org.testng.annotations.BeforeMethod;
032: import org.testng.annotations.Test;
033:
034: /**
035: * Tests container-managed transaction-scoped persistence context. It uses this test class as client and a
036: * Stateless with transaction-scoped persistence context.
037: * In this scope, the lifecycle of a persistence context ends when the associated transaction ends.
038: * @reference JSR 220 - Persistence API - FINAL DRAFT - 5.6.1
039: * @requirement Application Server must be running; the package
040: * org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.persistencectxlife
041: * must be deployed
042: * @setup gets the reference of the bean.
043: * @author Eduardo Studzinski Estima de Castro
044: * @author Gisele Pinheiro Souza
045: */
046: public class TestPersistenceLifetimeCMTransaction01 {
047:
048: /**
049: * Bean.
050: */
051: private ItfTestPCtxLifeCM00 bean;
052:
053: /**
054: * Gets bean instances used in the tests.
055: * @throws Exception if there is a problem with the bean initialization.
056: */
057: @BeforeMethod
058: public void startUp() throws Exception {
059: bean = getBeanRemoteInstance(SLSBPCtxLifeCMTTest00.class,
060: ItfTestPCtxLifeCM00.class);
061: bean.startUp();
062: }
063:
064: /**
065: * This test begins a transaction, creates an entity and rolls back the transaction.
066: * The entity must not exists after the rollback and the entity instance must become detached.
067: * A rollback in a transaction, which is used with the persistence context,
068: * always turns detached all entities associated with the persistence context.
069: * @input UserTransaction and entity.
070: * @output After the rollback, the bean must not exists.
071: * @throws Exception if a problem occurs.
072: */
073: @Test
074: public void test00() throws Exception {
075: bean.test00();
076: }
077:
078: /**
079: * This test begins a transaction, creates an entity and commits the transaction. The entity must
080: * exists after the commit and it must become detached, because it is an transaction persistence context.
081: * @input With a client transaction, invocation of a bean method which creates an entity.
082: * @output After the commit, the bean must become detached.
083: * @throws Exception if a problem occurs.
084: */
085: @Test
086: public void test01() throws Exception {
087: bean.test01();
088: }
089:
090: /**
091: * This test begins a transaction and creates an entity. As it uses an transaction
092: * persistence context and the transaction is still open,
093: * the entity remains managed after its creation. After this step,
094: * the test rolls back the transaction and the entity must be removed.
095: * @input With a client transaction, invocation of a bean method which creates an entity.
096: * @output The entity must be removed.
097: * @throws Exception if a problem occurs.
098: */
099: @Test
100: public void test02() throws Exception {
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 {
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 {
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 {
136: bean.tearDown();
137: }
138: }
|