KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > invocationcontext > SLSBInvocationParameterTest


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: SLSBInvocationParameterTest.java 880 2006-07-17 11:51:17Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.invocationcontext;
26
27 import static org.objectweb.easybeans.tests.common.helper.EJBHelper.getBeanLocalInstance;
28 import static org.objectweb.easybeans.tests.common.helper.InvocationContextHelper.INT_VALUE_0;
29 import static org.objectweb.easybeans.tests.common.helper.InvocationContextHelper.INT_VALUE_1;
30 import static org.objectweb.easybeans.tests.common.helper.InvocationContextHelper.INT_VALUE_2;
31 import static org.objectweb.easybeans.tests.common.helper.InvocationContextHelper.STR_VALUE_0;
32 import static org.objectweb.easybeans.tests.common.helper.InvocationContextHelper.STR_VALUE_1;
33 import static org.objectweb.easybeans.tests.common.helper.InvocationContextHelper.STR_VALUE_2;
34 import static org.testng.Assert.assertEquals;
35 import static org.testng.Assert.assertNull;
36 import static org.testng.Assert.assertTrue;
37
38 import java.util.List JavaDoc;
39
40 import javax.ejb.Remote JavaDoc;
41 import javax.ejb.Stateless JavaDoc;
42
43 import org.objectweb.easybeans.log.JLog;
44 import org.objectweb.easybeans.log.JLogFactory;
45 import org.objectweb.easybeans.tests.common.ejbs.base.invocationcontext.ItfInvocationParameter00;
46 import org.objectweb.easybeans.tests.common.ejbs.base.invocationcontext.ItfInvocationParameterTest;
47 import org.objectweb.easybeans.tests.common.interceptors.invocationcontext.BeanDescriptor;
48 import org.objectweb.easybeans.tests.common.interceptors.invocationcontext.ComplexObject00;
49
50 /**
51  * This bean is used to perform test in the intercepted method parameters stored
52  * in the invocation context.
53  * @author Eduardo Studzinski Estima de Castro
54  * @author Gisele Pinheiro Souza
55  */

56 @Stateless JavaDoc
57 @Remote JavaDoc
58 public class SLSBInvocationParameterTest implements ItfInvocationParameterTest {
59
60     /**
61      * Logger.
62      */

63     private JLog logger = JLogFactory.getLog(SLSBInvocationParameterTest.class);
64
65     /**
66      * Verifies if the intercepted method parameters can be modified to a null
67      * reference.
68      * @param beanClass bean class
69      * @throws Exception if there is a problem with the test.
70      */

71     public void testNull(final Class JavaDoc beanClass) throws Exception JavaDoc {
72         ItfInvocationParameter00 icBean = getBeanLocalInstance(beanClass, ItfInvocationParameter00.class);
73
74         ComplexObject00 cmpObj = new ComplexObject00();
75
76         Object JavaDoc[] arResult = icBean.getObjects00(cmpObj);
77
78         assertNull(arResult[0], "[0]The object should be null.");
79     }
80
81     /**
82      * Verifies if the intercepted method parameters can be returned WITHOUT
83      * modifications.
84      * @param beanClass bean class name
85      * @throws Exception if there is a problem with the test.
86      */

87     public void testWithoutModification(final Class JavaDoc beanClass) throws Exception JavaDoc {
88         ItfInvocationParameter00 icBean = getBeanLocalInstance(beanClass, ItfInvocationParameter00.class);
89
90         ComplexObject00 cmpObj = new ComplexObject00();
91
92         logger.debug("before bean method call, parameter: {0}", cmpObj);
93
94         Object JavaDoc[] arResult = icBean.getObjects01(cmpObj);
95
96         logger.debug("after bean method call, parameter: {0}", arResult[0]);
97
98         assertEquals(arResult[0], cmpObj, "[0]The object should be the same. ");
99     }
100
101     /**
102      * Verifies if the intercepted method parameters can be returned WITH
103      * modifications.
104      * @param beanClass bean class
105      * @throws Exception if there is a problem with the test.
106      */

107     public void testWithModification(final Class JavaDoc beanClass) throws Exception JavaDoc {
108         ItfInvocationParameter00 icBean = getBeanLocalInstance(beanClass, ItfInvocationParameter00.class);
109
110         ComplexObject00 cmpObj = new ComplexObject00();
111
112         Object JavaDoc[] arObjResult = icBean.getObjects02(cmpObj);
113
114         ComplexObject00 cmpResult = (ComplexObject00) arObjResult[0];
115
116         // Checks if the result is correct
117
assertTrue(cmpResult.getHashCode() == INT_VALUE_0.intValue(), "[0]The returned object is not the expected. ");
118         assertEquals(cmpResult.getInterceptedMethod(), STR_VALUE_0, "[1]The returned object is not the expected. ");
119
120         List JavaDoc<BeanDescriptor> lstDescs = cmpResult.getDescriptors().get(0);
121         // Checks the first bean descriptor
122
assertTrue(lstDescs.get(0).getHashCode() == INT_VALUE_1.intValue(),
123                 "[2]The returned object is not the expected. ");
124         assertEquals(lstDescs.get(0).getInterceptedMethod(), STR_VALUE_1,
125                 "[3]The returned object is not the expected. ");
126
127         assertTrue(lstDescs.get(1).getHashCode() == INT_VALUE_2.intValue(),
128                 "[4]The returned object is not the expected. ");
129         assertEquals(lstDescs.get(1).getInterceptedMethod(), STR_VALUE_2,
130                 "[5]The returned object is not the expected. ");
131     }
132
133 }
134
Popular Tags