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: TestPersistenceLifetimeCMExtended01.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.SLSBPCtxLifeCMETest00;
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 extended-scoped persistence context. It uses a Stateless as client and a
036: * Stateful with extendended-scoped persistence context.
037: * @reference JSR 220 - Persistence API - FINAL DRAFT - 5.6.2
038: * @requirement Application Server must be running; the package
039: * org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.persistencectxlife
040: * must be deployed
041: * @setup gets the reference of the bean.
042: * @author Eduardo Studzinski Estima de Castro
043: * @author Gisele Pinheiro Souza
044: */
045: public class TestPersistenceLifetimeCMExtended01 {
046:
047: /**
048: * Bean.
049: */
050: private ItfTestPCtxLifeCM00 bean;
051:
052: /**
053: * Gets bean instances used in the tests.
054: * @throws Exception if there is a problem with the bean initialization.
055: */
056: @BeforeMethod
057: public void startUp() throws Exception {
058: bean = getBeanRemoteInstance(SLSBPCtxLifeCMETest00.class,
059: ItfTestPCtxLifeCM00.class);
060: bean.startUp();
061: }
062:
063: /**
064: * This test begins a transaction, creates an entity and rolls back the transaction.
065: * The entity must not exists after the rollback and the entity instance must become detached.
066: * A rollback in a transaction, which is used with the persistence context,
067: * always turns detached all entities associated with the persistence context.
068: * @input UserTransaction and entity.
069: * @output After the rollback, the bean must not exists.
070: * @throws Exception if a problem occurs.
071: */
072: @Test
073: public void test00() throws Exception {
074: bean.test00();
075: }
076:
077: /**
078: * This test begins a transaction, creates an entity and commits the transaction. The entity must
079: * exists after the commit and it must remains managed, because it is an extended persistence context.
080: * @input With a client transaction, invocation of a bean method which creates an entity.
081: * @output After the commit, the bean must remains managed.
082: * @throws Exception if a problem occurs.
083: */
084: @Test
085: public void test01() throws Exception {
086: bean.test01();
087: }
088:
089: /**
090: * This test begins a transaction and creates an entity. As it uses an extended persistence context,
091: * the entity must be managed after its creation. After this step,
092: * the test rolls back the transaction and the entity must become detached.
093: * @input With a client transaction, invocation of a bean method which creates an entity.
094: * @output An detached entity.
095: * @throws Exception if a problem occurs.
096: */
097: @Test
098: public void test02() throws Exception {
099: 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 {
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 {
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 {
134: bean.tearDown();
135: }
136: }
|