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_TimeEndpoint.java 6393 2005-03-09 10:30:43Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.endpoint;
025:
026: import java.io.File;
027: import java.util.Calendar;
028:
029: import javax.wsdl.Definition;
030: import javax.wsdl.Import;
031: import javax.wsdl.factory.WSDLFactory;
032: import javax.wsdl.xml.WSDLReader;
033: import javax.xml.namespace.QName;
034: import javax.xml.rpc.Call;
035: import javax.xml.rpc.Service;
036: import javax.xml.rpc.ServiceFactory;
037:
038: import junit.framework.Test;
039: import junit.framework.TestSuite;
040:
041: import org.objectweb.common.Cmd;
042:
043: import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
044:
045: /**
046: * @author Guillaume Sauthier
047: */
048: public class F_TimeEndpoint extends JWebServicesTestCase {
049:
050: private static final String TIMEPORT_URL = "/time/TimePort/TimePort";
051:
052: /**
053: * @param s
054: */
055: public F_TimeEndpoint(String s) {
056: super (s);
057: }
058:
059: public static Test suite() {
060: return new TestSuite(F_TimeEndpoint.class);
061: }
062:
063: public void setUp() throws Exception {
064: super .setUp();
065:
066: useEar("time-test");
067: }
068:
069: public void tearDown() throws Exception {
070: super .tearDown();
071: }
072:
073: public void testTimeEndpoint() throws Exception {
074: String port = System.getProperty("http.port");
075:
076: Service service = ServiceFactory.newInstance().createService(
077: new QName("jonas:Time", "TimeBeanService"));
078: Call call = service.createCall(new QName("TimePort"),
079: new QName("getDate"));
080: call.setTargetEndpointAddress("http://localhost:" + port
081: + TIMEPORT_URL);
082: Calendar cal = (Calendar) call.invoke(new Object[] {});
083:
084: assertNotNull("ServiceEndpoint performed succesfully", cal);
085: }
086:
087: public void testTimeEndpointServerHandler() throws Exception {
088: String port = System.getProperty("http.port");
089:
090: Service service = ServiceFactory.newInstance().createService(
091: new QName("jonas:Time", "TimeBeanService"));
092: Call call = service.createCall(new QName("TimePort"),
093: new QName("isHandlerInitRequestInvoked"));
094: call.setTargetEndpointAddress("http://localhost:" + port
095: + TIMEPORT_URL);
096: Boolean b = (Boolean) call.invoke(new Object[] {});
097:
098: assertTrue("Handler were not invoked successfully", b
099: .booleanValue());
100: }
101:
102: public void testTimeEndpointFromAppClient() throws Exception {
103:
104: String javaHomeBin = System.getProperty("java.home")
105: + File.separator + "bin" + File.separator;
106: String jonasRoot = System.getProperty("jonas.root");
107: String jonasBase = System.getProperty("jonasbase");
108:
109: Cmd cmd = new Cmd(javaHomeBin + "java");
110: // classpath
111: cmd.addArgument("-classpath");
112: cmd.addArgument(jonasBase + File.separator + "conf"
113: + File.pathSeparator + jonasRoot + File.separator
114: + "lib" + File.separator + "client.jar");
115: cmd.addArgument("org.objectweb.jonas.client.ClientContainer");
116: // ear
117: cmd.addArgument(jonasBase + File.separator + "apps"
118: + File.separator + "time-test.ear");
119:
120: if (!cmd.run()) {
121: fail("Client fail see output for informations");
122: }
123: }
124:
125: public void testTimeEndpointURLPublication() throws Exception {
126: String port = System.getProperty("http.port");
127:
128: String url = "http://localhost:" + port + TIMEPORT_URL
129: + "?JWSDL";
130: WSDLFactory factory = WSDLFactory.newInstance();
131: WSDLReader reader = factory.newWSDLReader();
132: reader.setFeature("javax.wsdl.importDocuments", true);
133: Definition def = reader.readWSDL(url);
134:
135: Import imp = (Import) def.getImports("jonas:Time").get(0);
136: assertEquals("wsdl:import[@location] not updated !", url
137: + "&filename=Time.wsdl&context=.", imp.getLocationURI());
138: }
139:
140: }
|