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