1 /**2 * EasyBeans3 * Copyright (C) 2006 Bull S.A.S.4 * Contact: easybeans@objectweb.org5 *6 * This library is free software; you can redistribute it and/or7 * modify it under the terms of the GNU Lesser General Public8 * License as published by the Free Software Foundation; either9 * version 2.1 of the License, or any later version.10 *11 * This library is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14 * Lesser General Public License for more details.15 *16 * You should have received a copy of the GNU Lesser General Public17 * License along with this library; if not, write to the Free Software18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-130719 * USA20 *21 * --------------------------------------------------------------------------22 * $Id: TestSFCallbackAccess00.java 978 2006-07-28 13:19:14Z studzine $23 * --------------------------------------------------------------------------24 */25 package org.objectweb.easybeans.tests.interceptors.lifecycle.stateful.containermanaged;26 27 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.POST_CONSTRUCT;28 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.PRE_DESTROY;29 import static org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess.SLEEP;30 import static org.objectweb.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;31 32 import java.util.ArrayList ;33 import java.util.List ;34 35 import org.objectweb.easybeans.tests.common.ejbs.base.ItfCheck02;36 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.SFSBExternalCallbackAccess00;37 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;38 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.SLSBCallbackLoggerAccess;39 import org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackEJBAccess00;40 import org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackEMFactoryAccess00;41 import org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackEntityManagerAccess00;42 import org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackJEnvCompAccess00;43 import org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackResourceManagerAccess00;44 import org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc.AllLifeCallbackSessionContextAccess00;45 import org.testng.annotations.AfterMethod;46 import org.testng.annotations.BeforeMethod;47 import org.testng.annotations.Test;48 49 50 /**51 * Verifies if interceptors methods for lifecycle callbacks can perform the operations52 * allowed by the specification.53 * @reference JSR 220-PROPOSED FINAL - Table 254 * @requirement Application Server must be running; the beans55 * org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.lifecallback.*56 * must be deployed.57 * (Ant task: install.jar.tests.interceptor.lifecycle)58 * @author Eduardo Studzinski Estima de Castro59 * @author Gisele Pinheiro Souza60 */61 public class TestSFCallbackAccess00 {62 63 /**64 * Bean.65 */66 private ItfCheck02 bean;67 68 /**69 * Logger bean.70 */71 private ItfCallbackLoggerAccess beanLogger;72 73 /**74 * Gets bean instances used in the tests.75 * @throws Exception if there is a problem with the bean initialization.76 */77 @BeforeMethod78 public void startUp() throws Exception {79 bean = getBeanRemoteInstance(SFSBExternalCallbackAccess00.class, ItfCheck02.class);80 beanLogger = getBeanRemoteInstance(SLSBCallbackLoggerAccess.class, ItfCallbackLoggerAccess.class);81 beanLogger.deleteAll();82 }83 84 /**85 * Verifies PostConstruct lifecycle callback interceptor method operations.86 * The following operations are tested:87 * <li>EJB</li>88 * <li>SessionContext</li>89 * <li>JNDI</li>90 * <li>ResourceManager</li>91 * <li>EntityManagerFactory</li>92 * <li>EntityManager</li>93 * @input -94 * @output -95 * @throws Exception if a problem occurs.96 */97 @Test98 public void test00() throws Exception {99 bean.check();100 101 /*TODO: review after PostConstruct implementation.*/102 103 //Interceptors list104 List <String > arLife = new ArrayList <String >();105 106 arLife.add(AllLifeCallbackEJBAccess00.class.getName());107 arLife.add(AllLifeCallbackSessionContextAccess00.class.getName());108 arLife.add(AllLifeCallbackJEnvCompAccess00.class.getName());109 arLife.add(AllLifeCallbackResourceManagerAccess00.class.getName());110 arLife.add(AllLifeCallbackEMFactoryAccess00.class.getName());111 arLife.add(AllLifeCallbackEntityManagerAccess00.class.getName());112 113 114 beanLogger.verifyCallbackOrder(SFSBExternalCallbackAccess00.class, POST_CONSTRUCT,115 arLife.toArray(new String [0]));116 }117 118 /**119 * Verifies PreDestroy lifecycle callback interceptor method operations.120 * The following operations are tested:121 * <li>EJB</li>122 * <li>SessionContext</li>123 * <li>JNDI</li>124 * <li>ResourceManager</li>125 * <li>EntityManagerFactory</li>126 * <li>EntityManager</li>127 * @input -128 * @output -129 * @throws Exception if a problem occurs.130 */131 @Test132 public void test01() throws Exception {133 bean.check();134 bean.remove();135 136 //Sleep used to wait all interceptors execution137 Thread.sleep(SLEEP);138 139 /*TODO: review after PreDestroy implementation.*/140 141 //Interceptors list142 List <String > arLife = new ArrayList <String >();143 144 arLife.add(AllLifeCallbackEJBAccess00.class.getName());145 arLife.add(AllLifeCallbackSessionContextAccess00.class.getName());146 arLife.add(AllLifeCallbackJEnvCompAccess00.class.getName());147 arLife.add(AllLifeCallbackResourceManagerAccess00.class.getName());148 arLife.add(AllLifeCallbackEMFactoryAccess00.class.getName());149 arLife.add(AllLifeCallbackEntityManagerAccess00.class.getName());150 151 beanLogger.verifyCallbackOrder(SFSBExternalCallbackAccess00.class, PRE_DESTROY,152 arLife.toArray(new String [0]));153 }154 155 /**156 * Clears callback event log.157 */158 @AfterMethod159 public void tearDown(){160 beanLogger.deleteAll();161 }162 }163