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: TestSFAllCallbackOrder00.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.helper.EJBHelper.getBeanRemoteInstance;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: import org.ow2.easybeans.tests.common.ejbs.base.ItfCheck02;
034: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.BasePostConstructAllOrder00;
035: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.BasePreDestroyAllOrder00;
036: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.SFSBPostConstructAllOrder;
037: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.SFSBPreDestroyAllOrder;
038: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
039: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.SLSBCallbackLoggerAccess;
040: import org.ow2.easybeans.tests.common.interceptors.lifecycle.postconstruct.PostConstructLogger00;
041: import org.ow2.easybeans.tests.common.interceptors.lifecycle.postconstruct.PostConstructLogger01;
042: import org.ow2.easybeans.tests.common.interceptors.lifecycle.predestroy.PreDestroyLogger00;
043: import org.ow2.easybeans.tests.common.interceptors.lifecycle.predestroy.PreDestroyLogger01;
044: import org.testng.annotations.AfterMethod;
045: import org.testng.annotations.BeforeClass;
046: import org.testng.annotations.BeforeMethod;
047: import org.testng.annotations.Test;
048:
049: /**
050: * Verifies if interceptors invocation order.
051: * @reference JSR 220 - EJB 3.0 Core - 12.4.1
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 TestSFAllCallbackOrder00 {
060:
061: /**
062: * Bean.
063: */
064: private ItfCheck02 beanPostConstructAllOrder;
065:
066: /**
067: * Bean.
068: */
069: private ItfCheck02 beanPreDestroyAllOrder;
070:
071: /**
072: * Logger bean.
073: */
074: private ItfCallbackLoggerAccess beanLogger;
075:
076: /**
077: * Gets bean instances used in the tests.
078: * @throws Exception if there is a problem with the bean initialization.
079: */
080: @BeforeClass
081: public void startBeans() throws Exception {
082: beanPostConstructAllOrder = getBeanRemoteInstance(
083: SFSBPostConstructAllOrder.class, ItfCheck02.class);
084: beanPreDestroyAllOrder = getBeanRemoteInstance(
085: SFSBPreDestroyAllOrder.class, ItfCheck02.class);
086: }
087:
088: /**
089: * Gets bean instances used in the tests.
090: * @throws Exception if there is a problem with the bean initialization.
091: */
092: @BeforeMethod
093: public void startLog() throws Exception {
094: beanLogger = getBeanRemoteInstance(
095: SLSBCallbackLoggerAccess.class,
096: ItfCallbackLoggerAccess.class);
097: beanLogger.deleteAll();
098: }
099:
100: /**
101: * Verifies if the PostConstruct callback in invoked in the correct order.
102: * @input -
103: * @output -
104: * @throws Exception if a problem occurs.
105: */
106: @Test
107: public void testPostConstruct() throws Exception {
108: beanPostConstructAllOrder.check();
109:
110: // Interceptors list
111: List<String> arLife = new ArrayList<String>();
112:
113: arLife.add(PostConstructLogger00.class.getName());
114: arLife.add(PostConstructLogger01.class.getName());
115: arLife.add(BasePostConstructAllOrder00.class.getName());
116: arLife.add(SFSBPostConstructAllOrder.class.getName());
117:
118: beanLogger.verifyCallbackOrder(SFSBPostConstructAllOrder.class,
119: POST_CONSTRUCT, arLife.toArray(new String[0]));
120: }
121:
122: /**
123: * Verifies if the PreDestroy callback in invoked in the correct order.
124: * @input -
125: * @output -
126: * @throws Exception if a problem occurs.
127: */
128: @Test
129: public void testPreDestroy() throws Exception {
130: /* TODO: review after PreDestroy implementation. */
131:
132: beanPreDestroyAllOrder.check();
133: beanPreDestroyAllOrder.remove();
134:
135: // Interceptors list
136: List<String> arLife = new ArrayList<String>();
137:
138: arLife.add(PreDestroyLogger00.class.getName());
139: arLife.add(PreDestroyLogger01.class.getName());
140: arLife.add(BasePreDestroyAllOrder00.class.getName());
141: arLife.add(SFSBPreDestroyAllOrder.class.getName());
142:
143: beanLogger.verifyCallbackOrder(SFSBPreDestroyAllOrder.class,
144: PRE_DESTROY, arLife.toArray(new String[0]));
145: }
146:
147: /* TODO: tests for PrePassivate and PostActivate. */
148:
149: /**
150: * Clears callback event log.
151: */
152: @AfterMethod
153: public void tearDown() {
154: beanLogger.deleteAll();
155: }
156: }
|