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: TestSFCallbackAccess00.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.interceptors.lifecycle.stateful.containermanaged;
025:
026: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.POST_CONSTRUCT;
027: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.PRE_DESTROY;
028: import static org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess.SLEEP;
029: import static org.ow2.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
030:
031: import java.util.ArrayList;
032: import java.util.List;
033:
034: import org.ow2.easybeans.tests.common.ejbs.base.ItfCheck02;
035: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.SFSBExternalCallbackAccess00;
036: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
037: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.SLSBCallbackLoggerAccess;
038: import org.ow2.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackEJBAccess00;
039: import org.ow2.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackEMFactoryAccess00;
040: import org.ow2.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackEntityManagerAccess00;
041: import org.ow2.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackJEnvCompAccess00;
042: import org.ow2.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackResourceManagerAccess00;
043: import org.ow2.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackSessionContextAccess00;
044: import org.testng.annotations.AfterMethod;
045: import org.testng.annotations.BeforeMethod;
046: import org.testng.annotations.Test;
047:
048: /**
049: * Verifies if interceptors methods for lifecycle callbacks can perform the operations
050: * allowed by the specification.
051: * @reference JSR 220-PROPOSED FINAL - Table 2
052: * @requirement Application Server must be running; the beans
053: * org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.*
054: * must be deployed.
055: * (Ant task: install.jar.tests.interceptor.lifecycle)
056: * @author Eduardo Studzinski Estima de Castro
057: * @author Gisele Pinheiro Souza
058: */
059: public class TestSFCallbackAccess00 {
060:
061: /**
062: * Bean.
063: */
064: private ItfCheck02 bean;
065:
066: /**
067: * Logger bean.
068: */
069: private ItfCallbackLoggerAccess beanLogger;
070:
071: /**
072: * Gets bean instances used in the tests.
073: * @throws Exception if there is a problem with the bean initialization.
074: */
075: @BeforeMethod
076: public void startUp() throws Exception {
077: bean = getBeanRemoteInstance(
078: SFSBExternalCallbackAccess00.class, ItfCheck02.class);
079: beanLogger = getBeanRemoteInstance(
080: SLSBCallbackLoggerAccess.class,
081: ItfCallbackLoggerAccess.class);
082: beanLogger.deleteAll();
083: }
084:
085: /**
086: * Verifies PostConstruct lifecycle callback interceptor method operations.
087: * The following operations are tested:
088: * <li>EJB</li>
089: * <li>SessionContext</li>
090: * <li>JNDI</li>
091: * <li>ResourceManager</li>
092: * <li>EntityManagerFactory</li>
093: * <li>EntityManager</li>
094: * @input -
095: * @output -
096: * @throws Exception if a problem occurs.
097: */
098: @Test
099: public void test00() throws Exception {
100: bean.check();
101:
102: /*TODO: review after PostConstruct implementation.*/
103:
104: //Interceptors list
105: List<String> arLife = new ArrayList<String>();
106:
107: arLife.add(AllLifeCallbackEJBAccess00.class.getName());
108: arLife.add(AllLifeCallbackSessionContextAccess00.class
109: .getName());
110: arLife.add(AllLifeCallbackJEnvCompAccess00.class.getName());
111: arLife.add(AllLifeCallbackResourceManagerAccess00.class
112: .getName());
113: arLife.add(AllLifeCallbackEMFactoryAccess00.class.getName());
114: arLife
115: .add(AllLifeCallbackEntityManagerAccess00.class
116: .getName());
117:
118: beanLogger.verifyCallbackOrder(
119: SFSBExternalCallbackAccess00.class, POST_CONSTRUCT,
120: arLife.toArray(new String[0]));
121: }
122:
123: /**
124: * Verifies PreDestroy lifecycle callback interceptor method operations.
125: * The following operations are tested:
126: * <li>EJB</li>
127: * <li>SessionContext</li>
128: * <li>JNDI</li>
129: * <li>ResourceManager</li>
130: * <li>EntityManagerFactory</li>
131: * <li>EntityManager</li>
132: * @input -
133: * @output -
134: * @throws Exception if a problem occurs.
135: */
136: @Test
137: public void test01() throws Exception {
138: bean.check();
139: bean.remove();
140:
141: //Sleep used to wait all interceptors execution
142: Thread.sleep(SLEEP);
143:
144: /*TODO: review after PreDestroy implementation.*/
145:
146: //Interceptors list
147: List<String> arLife = new ArrayList<String>();
148:
149: arLife.add(AllLifeCallbackEJBAccess00.class.getName());
150: arLife.add(AllLifeCallbackSessionContextAccess00.class
151: .getName());
152: arLife.add(AllLifeCallbackJEnvCompAccess00.class.getName());
153: arLife.add(AllLifeCallbackResourceManagerAccess00.class
154: .getName());
155: arLife.add(AllLifeCallbackEMFactoryAccess00.class.getName());
156: arLife
157: .add(AllLifeCallbackEntityManagerAccess00.class
158: .getName());
159:
160: beanLogger.verifyCallbackOrder(
161: SFSBExternalCallbackAccess00.class, PRE_DESTROY, arLife
162: .toArray(new String[0]));
163: }
164:
165: /**
166: * Clears callback event log.
167: */
168: @AfterMethod
169: public void tearDown() {
170: beanLogger.deleteAll();
171: }
172: }
|