KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > mcontext > F_MessageContext


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@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: F_MessageContext.java,v 1.2 2004/04/15 16:12:29 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.mcontext;
27
28 import javax.xml.namespace.QName JavaDoc;
29 import javax.xml.rpc.Call JavaDoc;
30 import javax.xml.rpc.Service JavaDoc;
31 import javax.xml.rpc.ServiceFactory JavaDoc;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35
36 import org.objectweb.jonas.jtests.beans.mcontext.BeanAccessor;
37 import org.objectweb.jonas.jtests.beans.mcontext.BeanAccessorHome;
38 import org.objectweb.jonas.jtests.beans.mcontext.TestMC2;
39 import org.objectweb.jonas.jtests.beans.mcontext.TestMC2Home;
40 import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
41
42 /**
43  * test case for MessageContext use between web & ejb container
44  */

45 public class F_MessageContext extends JWebServicesTestCase {
46
47     public F_MessageContext(String JavaDoc name) {
48         super(name);
49     }
50     
51     public static Test suite() {
52         return new TestSuite(F_MessageContext.class);
53     }
54
55     public void setUp() throws Exception JavaDoc {
56         super.setUp();
57         
58         useEar("mcontext");
59     }
60
61     public void tearDown() throws Exception JavaDoc {
62         super.tearDown();
63     }
64
65
66     public void testWSCallLocal() throws Exception JavaDoc {
67         String JavaDoc port = System.getProperty("http.port");
68
69         Service JavaDoc service = ServiceFactory.newInstance().createService(new QName JavaDoc("jonas:MessageContextTest",
70                                                                                "MessageContextTestService"));
71         Call JavaDoc call = service.createCall(new QName JavaDoc("LocalMContextPort"),
72                                        new QName JavaDoc("serviceEndpointMethodHasMessageContext"));
73         call.setTargetEndpointAddress("http://localhost:" + port + "/mcontext/MessageContextWS/LocalMContextPort");
74         Boolean JavaDoc b = (Boolean JavaDoc) call.invoke(new Object JavaDoc[]{});
75         
76         assertTrue("ServiceEndpoint invokation cannot access the MessageContext",
77                    b.booleanValue());
78     }
79
80     public void testWSCallRemote() throws Exception JavaDoc {
81         String JavaDoc port = System.getProperty("http.port");
82
83         Service JavaDoc service = ServiceFactory.newInstance().createService(new QName JavaDoc("jonas:MessageContextTest",
84                                                                                "MessageContextTestService"));
85         Call JavaDoc call = service.createCall(new QName JavaDoc("RemoteMContextPort"),
86                                        new QName JavaDoc("serviceEndpointMethodHasMessageContext"));
87         call.setTargetEndpointAddress("http://localhost:" + port + "/mcontext/MessageContextWS/RemoteMContextPort");
88         Boolean JavaDoc b = (Boolean JavaDoc) call.invoke(new Object JavaDoc[]{});
89         
90         assertTrue("ServiceEndpoint invokation cannot access the MessageContext",
91                    b.booleanValue());
92     }
93
94     public void testEJBCallLocal() throws Exception JavaDoc {
95         BeanAccessorHome home = (BeanAccessorHome) ictx.lookup("BeanAccessorHome");
96         BeanAccessor accessor = home.create();
97         assertFalse("ejb call have access to the MessageContext.",
98                     accessor.localBeanHasMessageContext());
99     }
100
101     public void testEJBCallRemote() throws Exception JavaDoc {
102         Object JavaDoc obj = ictx.lookup("TestMC2Home");
103         TestMC2Home home = (TestMC2Home) javax.rmi.PortableRemoteObject.narrow(obj, TestMC2Home.class);
104         TestMC2 mc2 = home.create();
105         assertFalse("ejb call have access to the MessageContext.",
106                     mc2.remoteMethodHasMessageContext());
107     }
108
109     public static void main (String JavaDoc args[]) {
110         String JavaDoc testtorun = null;
111         // Get args
112
for (int argn = 0; argn < args.length; argn++) {
113             String JavaDoc s_arg = args[argn];
114             Integer JavaDoc i_arg;
115             if (s_arg.equals("-n")) {
116                 testtorun = args[++argn];
117             }
118         }
119         if (testtorun == null) {
120             junit.textui.TestRunner.run(suite());
121         } else {
122             junit.textui.TestRunner.run(new F_MessageContext(testtorun));
123         }
124     }
125
126 }
127
Popular Tags