KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateful > containermanaged > interceptorxml > SFSBInterceptorTester00


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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 of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SFSBInterceptorTester00.java 820 2006-07-04 12:37:48Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.interceptorxml;
26
27 import static org.objectweb.easybeans.tests.common.asserts.Assert.assertEquals;
28 import static org.testng.Assert.assertTrue;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32
33 import javax.ejb.EJB JavaDoc;
34 import javax.ejb.Remote JavaDoc;
35 import javax.ejb.Stateful JavaDoc;
36
37 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
38 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
39 import org.objectweb.easybeans.tests.common.interceptors.business.base.PrintOrderWithoutAnnotationInterc;
40 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
41 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
42
43 /**
44  * Verifies the definition of interceptors by deployment descriptors.
45  * @author Gisele Pinheiro Souza
46  * @author Eduardo Studzinski Estima de Castro
47  */

48 @Stateful JavaDoc
49 @Remote JavaDoc(ItfInterceptorTester00.class)
50 public class SFSBInterceptorTester00 implements ItfInterceptorTester00 {
51
52     /**
53      * Bean defined by deployment descriptor used to test the interceptors.
54      */

55     @EJB JavaDoc(beanName = "SFSBInterceptorXMLRemote00")
56     private ItfInterceptorXML sfsbInterceptorXML;
57
58     /**
59      * Bean used to log the callback methods.
60      */

61     @EJB JavaDoc(beanName = "SLSBCallbackLoggerAccess")
62     private ItfCallbackLoggerAccess clBean;
63
64     /**
65      * Verifies if the default interceptor, the class interceptor and the method
66      * interceptor are called.
67      * @param lstResult the list that was returned by the bean method.
68      */

69     private void verifyMethodInterceptor(final List JavaDoc<Integer JavaDoc> lstResult) {
70         List JavaDoc<Integer JavaDoc> lstExpected = new ArrayList JavaDoc<Integer JavaDoc>();
71
72         // the default interceptor in first place
73
lstExpected.add(PrintOrderWithoutAnnotationInterc.ORDER);
74         // after the class interceptor
75
lstExpected.add(PrintOrder02Interceptor.ORDER);
76         lstExpected.add(SFSBInterceptorXML.ORDER);
77         // the method interceptor
78
lstExpected.add(PrintOrder03Interceptor.ORDER);
79
80         assertEquals(lstResult, lstExpected,
81                 "The interceptors defined in the xml descriptor does not run in the correct order.");
82
83     }
84
85     /**
86      * Verifies if the default interceptors and the class interceptors defined
87      * in the deployment descriptors are called.
88      */

89     public void testInterceptorOrder01() {
90         List JavaDoc<Integer JavaDoc> lstResult = sfsbInterceptorXML.insertOrder1(new ArrayList JavaDoc<Integer JavaDoc>());
91         List JavaDoc<Integer JavaDoc> lstExpected = new ArrayList JavaDoc<Integer JavaDoc>();
92
93         // the default interceptor in first place
94
lstExpected.add(PrintOrderWithoutAnnotationInterc.ORDER);
95         // after the class interceptor
96
lstExpected.add(PrintOrder02Interceptor.ORDER);
97         lstExpected.add(SFSBInterceptorXML.ORDER);
98
99         assertEquals(lstResult, lstExpected,
100                 "The interceptors defined in the xml descriptor does not run in the correct order.");
101     }
102
103     /**
104      * Verifies if the interceptor defined for a method works correctly. The
105      * interceptor is defined to the methods with the name insertOrder2, so the
106      * both methods must have the same interceptors.
107      */

108     public void testInterceptorOrder02() {
109         verifyMethodInterceptor(sfsbInterceptorXML.insertOrder2(new ArrayList JavaDoc<Integer JavaDoc>()));
110         verifyMethodInterceptor(sfsbInterceptorXML.insertOrder2(new ArrayList JavaDoc<Integer JavaDoc>(), 1));
111     }
112
113     /**
114      * Verifies the element exclude class interceptors.
115      */

116     public void testInterceptorOrder03() {
117         List JavaDoc<Integer JavaDoc> lstResult = sfsbInterceptorXML.insertOrder3(new ArrayList JavaDoc<Integer JavaDoc>());
118         List JavaDoc<Integer JavaDoc> lstExpected = new ArrayList JavaDoc<Integer JavaDoc>();
119
120         // the default interceptor in first place
121
lstExpected.add(PrintOrderWithoutAnnotationInterc.ORDER);
122
123         assertEquals(lstResult, lstExpected,
124                 "The interceptors defined in the xml descriptor does not run in the correct order.");
125     }
126
127     /**
128      * Verifies if the postConstruct was called.
129      */

130     public void testPostConstruct() {
131         assertTrue(sfsbInterceptorXML.calledPostConstruct(), "The postConstruct defined by XML was not called.");
132     }
133
134     /**
135      * Verifies if the preDestroy was called.
136      */

137     public void testPreDestroy() {
138         sfsbInterceptorXML.remove();
139
140         // Interceptors list
141
List JavaDoc<String JavaDoc> arLife = new ArrayList JavaDoc<String JavaDoc>();
142
143         arLife.add(SFSBInterceptorXML.class.getName());
144
145         clBean.verifyCallbackOrder(SFSBInterceptorXML.class.getName(), CallbackType.PRE_DESTROY, arLife
146                 .toArray(new String JavaDoc[arLife.size()]));
147     }
148
149     /**
150      * Verifies if the prePassivate is called.
151      */

152     public void testPrePassivate() {
153         // TODO - how to test the prePassivate?
154
}
155
156     /**
157      * Verifies if the postActivate is called.
158      */

159     public void testPostActivate() {
160         // TODO - how to test the postActivate?
161
}
162 }
163
Popular Tags