001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.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: F_MessageContext.java 4603 2004-04-15 16:12:29Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.mcontext;
025:
026: import javax.xml.namespace.QName;
027: import javax.xml.rpc.Call;
028: import javax.xml.rpc.Service;
029: import javax.xml.rpc.ServiceFactory;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.objectweb.jonas.jtests.beans.mcontext.BeanAccessor;
035: import org.objectweb.jonas.jtests.beans.mcontext.BeanAccessorHome;
036: import org.objectweb.jonas.jtests.beans.mcontext.TestMC2;
037: import org.objectweb.jonas.jtests.beans.mcontext.TestMC2Home;
038: import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
039:
040: /**
041: * test case for MessageContext use between web & ejb container
042: */
043: public class F_MessageContext extends JWebServicesTestCase {
044:
045: public F_MessageContext(String name) {
046: super (name);
047: }
048:
049: public static Test suite() {
050: return new TestSuite(F_MessageContext.class);
051: }
052:
053: public void setUp() throws Exception {
054: super .setUp();
055:
056: useEar("mcontext");
057: }
058:
059: public void tearDown() throws Exception {
060: super .tearDown();
061: }
062:
063: public void testWSCallLocal() throws Exception {
064: String port = System.getProperty("http.port");
065:
066: Service service = ServiceFactory.newInstance().createService(
067: new QName("jonas:MessageContextTest",
068: "MessageContextTestService"));
069: Call call = service.createCall(new QName("LocalMContextPort"),
070: new QName("serviceEndpointMethodHasMessageContext"));
071: call.setTargetEndpointAddress("http://localhost:" + port
072: + "/mcontext/MessageContextWS/LocalMContextPort");
073: Boolean b = (Boolean) call.invoke(new Object[] {});
074:
075: assertTrue(
076: "ServiceEndpoint invokation cannot access the MessageContext",
077: b.booleanValue());
078: }
079:
080: public void testWSCallRemote() throws Exception {
081: String port = System.getProperty("http.port");
082:
083: Service service = ServiceFactory.newInstance().createService(
084: new QName("jonas:MessageContextTest",
085: "MessageContextTestService"));
086: Call call = service.createCall(new QName("RemoteMContextPort"),
087: new QName("serviceEndpointMethodHasMessageContext"));
088: call.setTargetEndpointAddress("http://localhost:" + port
089: + "/mcontext/MessageContextWS/RemoteMContextPort");
090: Boolean b = (Boolean) call.invoke(new Object[] {});
091:
092: assertTrue(
093: "ServiceEndpoint invokation cannot access the MessageContext",
094: b.booleanValue());
095: }
096:
097: public void testEJBCallLocal() throws Exception {
098: BeanAccessorHome home = (BeanAccessorHome) ictx
099: .lookup("BeanAccessorHome");
100: BeanAccessor accessor = home.create();
101: assertFalse("ejb call have access to the MessageContext.",
102: accessor.localBeanHasMessageContext());
103: }
104:
105: public void testEJBCallRemote() throws Exception {
106: Object obj = ictx.lookup("TestMC2Home");
107: TestMC2Home home = (TestMC2Home) javax.rmi.PortableRemoteObject
108: .narrow(obj, TestMC2Home.class);
109: TestMC2 mc2 = home.create();
110: assertFalse("ejb call have access to the MessageContext.", mc2
111: .remoteMethodHasMessageContext());
112: }
113:
114: public static void main(String args[]) {
115: String testtorun = null;
116: // Get args
117: for (int argn = 0; argn < args.length; argn++) {
118: String s_arg = args[argn];
119: Integer i_arg;
120: if (s_arg.equals("-n")) {
121: testtorun = args[++argn];
122: }
123: }
124: if (testtorun == null) {
125: junit.textui.TestRunner.run(suite());
126: } else {
127: junit.textui.TestRunner
128: .run(new F_MessageContext(testtorun));
129: }
130: }
131:
132: }
|