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: TestSFAccessInterceptor01.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.interceptors.business.stateful.containermanaged;
025:
026: import static org.ow2.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
027: import static org.ow2.easybeans.tests.common.helper.ExceptionHelper.checkCause;
028:
029: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessEJB;
030: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessEMFactory;
031: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessEntityManager;
032: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessJNDI;
033: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessResourceManager;
034: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessSessionContext;
035: import org.ow2.easybeans.tests.common.ejbs.base.ItfAccessUserTransaction;
036: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.interceptoraccess.SFSBAccessInterceptorTest01;
037: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.interceptoraccess.SFSBAccessSessionCtxInterceptor02;
038: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.interceptoraccess.SFSBAccessUserTxInterceptor01;
039: import org.ow2.easybeans.tests.common.exception.CustomException00;
040: import org.ow2.easybeans.tests.interceptors.business.base.access.BaseAccessOperationsInterceptor00;
041: import org.testng.annotations.BeforeClass;
042: import org.testng.annotations.Test;
043:
044: /**
045: * Verifies if interceptors in the bean class can access the perform the
046: * operations specified by the JSR-220.
047: * @reference JSR 220 - EJB 3.0 Core - 4.4.1
048: * @requirement Application Server must be running; the beans
049: * org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.SLSB*AccessInterceptor*
050: * must be deployed.
051: * (Ant task: install.jar.tests.interceptor.business)
052: * @setup gets the reference of SLSBAccessInterceptorTest01,
053: * SLSBAccessTimerInterceptor01
054: * @author Eduardo Studzinski Estima de Castro
055: * @author Gisele Pinheiro Souza
056: */
057: public class TestSFAccessInterceptor01 extends
058: BaseAccessOperationsInterceptor00 {
059:
060: /**
061: * Gets bean instances used in the tests.
062: * @throws Exception if there is a problem with the bean initialization.
063: */
064: @BeforeClass
065: public void startUp() throws Exception {
066: ItfAccessJNDI bean00 = getBeanRemoteInstance(
067: SFSBAccessInterceptorTest01.class, ItfAccessJNDI.class);
068: ItfAccessEJB bean01 = getBeanRemoteInstance(
069: SFSBAccessInterceptorTest01.class, ItfAccessEJB.class);
070: ItfAccessResourceManager bean02 = getBeanRemoteInstance(
071: SFSBAccessInterceptorTest01.class,
072: ItfAccessResourceManager.class);
073: ItfAccessEntityManager bean03 = getBeanRemoteInstance(
074: SFSBAccessInterceptorTest01.class,
075: ItfAccessEntityManager.class);
076: ItfAccessEMFactory bean04 = getBeanRemoteInstance(
077: SFSBAccessInterceptorTest01.class,
078: ItfAccessEMFactory.class);
079: ItfAccessSessionContext bean05 = getBeanRemoteInstance(
080: SFSBAccessInterceptorTest01.class,
081: ItfAccessSessionContext.class);
082:
083: ItfAccessSessionContext bean07 = getBeanRemoteInstance(
084: SFSBAccessSessionCtxInterceptor02.class,
085: ItfAccessSessionContext.class);
086: super .setBeans(bean00, bean01, bean02, bean03, bean04, bean05,
087: null, bean07, null);
088: }
089:
090: /**
091: * Verifies if the interceptor can access the "java:comp/env" via JNDI. This
092: * operation is allowed, so there isn't an expected
093: * exception.
094: * @input -
095: * @output no exceptions.
096: * @throws Exception if a problem occurs.
097: */
098: @Override
099: @Test(groups={"java:comp/env access"})
100: public void testJNDI00() throws Exception {
101: super .testJNDI00();
102: }
103:
104: /**
105: * Verifies if the interceptor can access an EJB. This
106: * operation is allowed, so there isn't an expected
107: * exception.
108: * @input -
109: * @output no exceptions.
110: * @throws Exception if a problem occurs.
111: */
112: @Override
113: @Test(groups={"EJB access"})
114: public void testEJB00() throws Exception {
115: super .testEJB00();
116: }
117:
118: /**
119: * Verifies if the interceptor can access the resource manager. This
120: * operation is allowed, so there isn't an expected
121: * exception.
122: * @input -
123: * @output no exceptions.
124: * @throws Exception if a problem occurs.
125: */
126: @Override
127: @Test(groups={"Resource access"})
128: public void testResource00() throws Exception {
129: super .testResource00();
130: }
131:
132: /**
133: * Verifies if the interceptor can access the entity manager. This
134: * operation is allowed, so there isn't an expected
135: * exception.
136: * @input -
137: * @output no exceptions.
138: * @throws Exception if a problem occurs.
139: */
140: @Override
141: @Test(groups={"Entity Manager access"})
142: public void testEntityManager00() throws Exception {
143: super .testEntityManager00();
144: }
145:
146: /**
147: * Verifies if the interceptor can access the entity factory. This
148: * operation is allowed, so there isn't an expected
149: * exception.
150: * @input -
151: * @output no exceptions.
152: * @throws Exception if a problem occurs.
153: */
154: @Override
155: @Test(groups={"Entity Factory access"})
156: public void testEntityFactory00() throws Exception {
157: super .testEntityFactory00();
158: }
159:
160: /**
161: * Verifies if the interceptor can access the session context. This
162: * operation is allowed, so there isn't an expected
163: * exception.
164: * @input -
165: * @output no exceptions.
166: * @throws Exception if a problem occurs.
167: */
168: @Override
169: @Test(groups={"SessionContext access"})
170: public void testSessionContext00() throws Exception {
171: super .testSessionContext00();
172: }
173:
174: /**
175: * Verifies if an interceptor can access the "getTimerService()" of a SessionContext instance.
176: * The specification defines that if a bean instance attempts to invoke a method and that access is not allowed, the container
177: * must throw an javax.ejb.EJBException with the java.lang.IllegalStateException as cause.
178: * @input -
179: * @output java.lang.IllegalStateException.
180: * @throws Exception if a problem occurs.
181: */
182: @Override
183: @Test(groups={"SessionContext access"})
184: public void testSessionContext01() throws Exception {
185: try {
186: super .testSessionContext01();
187: } catch (Exception e) {
188: checkCause(e, IllegalStateException.class);
189: }
190: }
191:
192: /**
193: * Verifies if an interceptor can access the user transaction.
194: * The specification denies the use of this service, the reference must be null and
195: * an exception must be thrown.
196: * @input -
197: * @output CustomException00
198: * @throws Exception if a problem occurs.
199: */
200: @Override
201: @Test(groups={"UserTransaction access"},expectedExceptions=CustomException00.class)
202: @SuppressWarnings("unused")
203: public void testUserTransaction00() throws Exception {
204: ItfAccessUserTransaction bean = getBeanRemoteInstance(
205: SFSBAccessUserTxInterceptor01.class,
206: ItfAccessUserTransaction.class);
207: bean.accessUserTransaction(null);
208: }
209:
210: }
|