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: TestSFRemove.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.sessionbean.stateful.remove;
025:
026: import static org.ow2.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
027:
028: import javax.ejb.NoSuchEJBException;
029:
030: import org.ow2.easybeans.tests.common.ejbs.base.ItfCheck00;
031: import org.ow2.easybeans.tests.common.ejbs.base.ItfCheck02;
032: import org.ow2.easybeans.tests.common.ejbs.base.ItfCheck03;
033: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.remove.SFSBRemove00;
034: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.remove.SFSBRemoveByException;
035: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.remove.SFSBRemoveWithRetain;
036: import org.ow2.easybeans.tests.common.exception.AppException;
037: import org.ow2.util.log.Log;
038: import org.ow2.util.log.LogFactory;
039: import org.testng.annotations.BeforeClass;
040: import org.testng.annotations.Test;
041:
042: /**
043: * Tests related with stateful instance remove operation.
044: * @reference JSR 220 - EJB 3.0 Core - 4.3.11
045: * @requirement Application Server must be running.<br>
046: * (Ant task: install.jar.tests.stateful.remove)
047: * @author Eduardo Studzinski Estima de Castro
048: * @author Gisele Pinheiro Souza
049: */
050: public class TestSFRemove {
051:
052: /**
053: * Log helper.
054: */
055: private Log logger = LogFactory.getLog(TestSFRemove.class);
056:
057: /**
058: * Bean.
059: */
060: private ItfCheck02 beanRemoveDefault;
061:
062: /**
063: * Bean.
064: */
065: private ItfCheck00 beanRemoveByException;
066:
067: /**
068: * Bean.
069: */
070: private ItfCheck03 beanRetain;
071:
072: /**
073: * Gets bea instances used in the tests.
074: * @throws Exception if there is a problem with bean initialization.
075: */
076: @BeforeClass
077: public void startUp() throws Exception {
078: beanRemoveDefault = getBeanRemoteInstance(SFSBRemove00.class,
079: ItfCheck02.class);
080: beanRemoveByException = getBeanRemoteInstance(
081: SFSBRemoveByException.class, ItfCheck00.class);
082: beanRetain = getBeanRemoteInstance(SFSBRemoveWithRetain.class,
083: ItfCheck03.class);
084: }
085:
086: /**
087: * Verifies if the bean is destroyed after the remove() invocation.
088: * @input -
089: * @output NoSuchEJBException
090: * @throws Exception if a problem occurs.
091: */
092: @Test(expectedExceptions={NoSuchEJBException.class})
093: public void testRemoveMethod() throws Exception {
094: beanRemoveDefault.remove();
095: beanRemoveDefault.check();
096: }
097:
098: /**
099: * Verifies if the bean is destroyed after a system exception.
100: * @input -
101: * @output NoSuchEJBException
102: * @throws Exception if a problem occurs.
103: */
104: @Test(expectedExceptions={NoSuchEJBException.class})
105: public void testRemoveBySystemException() throws Exception {
106: try {
107: beanRemoveByException.check();
108: } catch (Exception e) {
109: logger.debug("Exception.");
110: }
111: beanRemoveByException.check();
112: }
113:
114: /**
115: * Verifies if the bean is not destroyed after an application exception
116: * during the remote() method invocation.
117: * @input -
118: * @output NoSuchEJBException
119: * @throws Exception if a problem occurs.
120: */
121: @Test
122: public void testRetain() throws Exception {
123: try {
124: beanRetain.remove();
125: } catch (AppException e) {
126: logger.debug("Expected Exception occured.");
127: } catch (Exception e) {
128: logger.debug("Exception");
129: }
130: beanRetain.check();
131: }
132: }
|