KickJava   Java API By Example, From Geeks To Geeks.

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


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: SFSBInterceptorTester02.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.PrintOrderWithAllCallbackMethods;
40 import org.objectweb.easybeans.tests.common.interceptors.business.base.PrintOrderWithoutAnnotationInterc;
41 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
42
43
44 /**
45  * Verifies the interceptor order.
46  * @author Gisele Pinheiro Souza
47  * @author Eduardo Studzinski Estima de Castro
48  *
49  */

50 @Stateful JavaDoc
51 @Remote JavaDoc(ItfInterceptorTester02.class)
52 public class SFSBInterceptorTester02 implements ItfInterceptorTester02 {
53
54     /**
55      * Bean defined by deployment descriptor used to test the interceptors.
56      */

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

63     @EJB JavaDoc(beanName = "SLSBCallbackLoggerAccess")
64     private ItfCallbackLoggerAccess clBean;
65
66     /**
67      * Verifies if the interceptor method is called together with the others
68      * interceptors.
69      * @param lstResult the list returned by the bean.
70      */

71     private void verifyMethodOrder(final List JavaDoc<Integer JavaDoc> lstResult){
72         List JavaDoc<Integer JavaDoc> lstExpected = new ArrayList JavaDoc<Integer JavaDoc>();
73
74         // the method interceptor in first place
75
lstExpected.add(PrintOrder03Interceptor.ORDER);
76         //the default interceptor in the second place
77
lstExpected.add(PrintOrderWithoutAnnotationInterc.ORDER);
78         //after the methods defined in the class
79
lstExpected.add(SFSBInterceptorXML.ORDER);
80         //and the class interceptor
81
lstExpected.add(PrintOrderWithAllCallbackMethods.ORDER);
82
83         assertEquals(lstResult, lstExpected,
84         "The interceptors defined in the xml descriptor does not run in the order defined by the interceptors-order element.");
85
86     }
87
88
89     /**
90      * Verifies if the container uses the interceptor order defined in the deployment descriptor.
91      *
92      */

93     public void testInterceptorOrder01(){
94         List JavaDoc<Integer JavaDoc> lstResult = sfsbInterceptorXML.insertOrder1(new ArrayList JavaDoc<Integer JavaDoc>());
95         List JavaDoc<Integer JavaDoc> lstExpected = new ArrayList JavaDoc<Integer JavaDoc>();
96
97         // the default interceptor in first place
98
lstExpected.add(PrintOrderWithoutAnnotationInterc.ORDER);
99         //after the methods defined in the class
100
lstExpected.add(SFSBInterceptorXML.ORDER);
101         //and the class interceptor
102
lstExpected.add(PrintOrderWithAllCallbackMethods.ORDER);
103
104         assertEquals(lstResult, lstExpected,
105         "The interceptors defined in the xml descriptor does not run in the order defined by the interceptors-order element.");
106     }
107
108     /**
109      * Verifies if the method interceptor respect the order defined by the deployment descriptor.
110      *
111      */

112     public void testInterceptorOrder02(){
113         verifyMethodOrder(sfsbInterceptorXML.insertOrder2(new ArrayList JavaDoc<Integer JavaDoc>()));
114         verifyMethodOrder(sfsbInterceptorXML.insertOrder2(new ArrayList JavaDoc<Integer JavaDoc>(), 1));
115     }
116
117     /**
118      * Verifies if the postConstruct was called.
119      */

120     public void testPostConstruct() {
121         assertTrue(sfsbInterceptorXML.calledPostConstruct(), "The postConstruct defined by XML was not called.");
122         // Interceptors list
123
List JavaDoc<String JavaDoc> arLife = new ArrayList JavaDoc<String JavaDoc>();
124
125         arLife.add(PrintOrderWithAllCallbackMethods.class.getName());
126
127         clBean.verifyCallbackOrder(SFSBInterceptorXML.class.getName(), CallbackType.PRE_DESTROY, arLife
128                 .toArray(new String JavaDoc[arLife.size()]));
129     }
130
131     /**
132      * Verifies if the preDestroy was called.
133      */

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

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

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