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: TestMDBAllCallback.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.interceptors.lifecycle.messagedriven.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.entity.callbacklogger.OperationType.UNDEFINED;
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.mdb.containermanaged.lifecallback.MDBLifecycle00;
035: import org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.lifecallback.PostConstructMDB;
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.predestroy.PreDestroyLogger00;
039: import org.ow2.easybeans.tests.common.jms.JMSManager;
040: import org.testng.annotations.AfterClass;
041: import org.testng.annotations.BeforeClass;
042: import org.testng.annotations.Test;
043:
044: /**
045: * Verifies if lifecycle callback interceptors are invoked.
046: * @reference JSR 220 - EJB 3.0 Core - 12.4
047: * @requirement Application Server must be running.<br>
048: * MDB:<li>org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.lifecallback.MDBLifecycle00</li>
049: * (Ant task: install.jar.tests.interceptor.lifecycle)
050: * @author Eduardo Studzinski Estima de Castro
051: * @author Gisele Pinheiro Souza
052: */
053: public class TestMDBAllCallback {
054:
055: /**
056: * JMS Manager.
057: */
058: private JMSManager jmsQueue;
059:
060: /**
061: * Logger bean.
062: */
063: private ItfCallbackLoggerAccess beanLogger;
064:
065: /**
066: * Creates the JMS manager and the bean logger.
067: * @throws Exception if there is a problem.
068: */
069: @BeforeClass
070: public void startUp00() throws Exception {
071: jmsQueue = new JMSManager(
072: JMSManager.DEFAULT_QUEUE_CONNECTION_FACTORY,
073: JMSManager.DEFAULT_QUEUE);
074: beanLogger = getBeanRemoteInstance(
075: SLSBCallbackLoggerAccess.class,
076: ItfCallbackLoggerAccess.class);
077: jmsQueue.sendControlMessage(MDBLifecycle00.MESSAGE_TYPE,
078: UNDEFINED);
079: }
080:
081: /**
082: * Verifies if the PostConstruct callback in invoked in the correct order.
083: * @input -
084: * @output -
085: * @throws Exception if a problem occurs.
086: */
087: @Test
088: public void testPostConstruct() throws Exception {
089: //Interceptors list
090: List<String> arLife = new ArrayList<String>();
091:
092: arLife.add(PostConstructMDB.class.getName());
093: arLife.add(MDBLifecycle00.class.getName());
094:
095: beanLogger.verifyCallbackOrder(MDBLifecycle00.class,
096: POST_CONSTRUCT, arLife.toArray(new String[0]));
097: }
098:
099: /**
100: * Verifies if the PreDestroy callback in invoked in the correct order.
101: * @input -
102: * @output -
103: * @throws Exception if a problem occurs.
104: */
105: //@Test
106: public void testPreDestroy() throws Exception {
107: /*TODO: test, it's necessary to force a mdb destruction.*/
108:
109: //Interceptors list
110: List<String> arLife = new ArrayList<String>();
111:
112: arLife.add(PreDestroyLogger00.class.getName());
113: arLife.add(MDBLifecycle00.class.getName());
114:
115: beanLogger.verifyCallbackOrder(MDBLifecycle00.class,
116: PRE_DESTROY, arLife.toArray(new String[0]));
117: }
118:
119: /**
120: * Clears callback event log.
121: * @throws Exception if a problem occurs.
122: */
123: @AfterClass
124: public void tearDown() throws Exception {
125: beanLogger.deleteAll();
126: jmsQueue.close();
127: }
128: }
|