KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > endpoint > F_TimeEndpoint


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_TimeEndpoint.java,v 1.6 2005/03/09 10:30:42 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.jtests.clients.endpoint;
26
27 import java.io.File JavaDoc;
28 import java.util.Calendar JavaDoc;
29
30 import javax.wsdl.Definition;
31 import javax.wsdl.Import;
32 import javax.wsdl.factory.WSDLFactory;
33 import javax.wsdl.xml.WSDLReader;
34 import javax.xml.namespace.QName JavaDoc;
35 import javax.xml.rpc.Call JavaDoc;
36 import javax.xml.rpc.Service JavaDoc;
37 import javax.xml.rpc.ServiceFactory JavaDoc;
38
39 import junit.framework.Test;
40 import junit.framework.TestSuite;
41
42 import org.objectweb.common.Cmd;
43
44 import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
45
46 /**
47  * @author Guillaume Sauthier
48  */

49 public class F_TimeEndpoint extends JWebServicesTestCase {
50
51     private static final String JavaDoc TIMEPORT_URL = "/time/TimePort/TimePort";
52     
53     /**
54      * @param s
55      */

56     public F_TimeEndpoint(String JavaDoc s) {
57         super(s);
58     }
59
60     public static Test suite() {
61         return new TestSuite(F_TimeEndpoint.class);
62     }
63
64     public void setUp() throws Exception JavaDoc {
65         super.setUp();
66
67         useEar("time-test");
68     }
69
70     public void tearDown() throws Exception JavaDoc {
71         super.tearDown();
72     }
73
74     public void testTimeEndpoint() throws Exception JavaDoc {
75         String JavaDoc port = System.getProperty("http.port");
76
77         Service JavaDoc service = ServiceFactory.newInstance().createService(new QName JavaDoc("jonas:Time", "TimeBeanService"));
78         Call JavaDoc call = service.createCall(new QName JavaDoc("TimePort"), new QName JavaDoc("getDate"));
79         call.setTargetEndpointAddress("http://localhost:" + port + TIMEPORT_URL);
80         Calendar JavaDoc cal = (Calendar JavaDoc) call.invoke(new Object JavaDoc[] {});
81
82         assertNotNull("ServiceEndpoint performed succesfully", cal);
83     }
84
85     public void testTimeEndpointServerHandler() throws Exception JavaDoc {
86         String JavaDoc port = System.getProperty("http.port");
87
88         Service JavaDoc service = ServiceFactory.newInstance().createService(new QName JavaDoc("jonas:Time", "TimeBeanService"));
89         Call JavaDoc call = service.createCall(new QName JavaDoc("TimePort"), new QName JavaDoc("isHandlerInitRequestInvoked"));
90         call.setTargetEndpointAddress("http://localhost:" + port + TIMEPORT_URL);
91         Boolean JavaDoc b = (Boolean JavaDoc) call.invoke(new Object JavaDoc[] {});
92
93         assertTrue("Handler were not invoked successfully", b.booleanValue());
94     }
95
96     public void testTimeEndpointFromAppClient() throws Exception JavaDoc {
97
98         String JavaDoc javaHomeBin = System.getProperty("java.home") + File.separator + "bin" + File.separator;
99         String JavaDoc jonasRoot = System.getProperty("jonas.root");
100         String JavaDoc jonasBase = System.getProperty("jonasbase");
101
102         Cmd cmd = new Cmd(javaHomeBin + "java");
103         // classpath
104
cmd.addArgument("-classpath");
105         cmd.addArgument(jonasBase + File.separator + "conf" + File.pathSeparator + jonasRoot + File.separator + "lib"
106                 + File.separator + "client.jar");
107         cmd.addArgument("org.objectweb.jonas.client.ClientContainer");
108         // ear
109
cmd.addArgument(jonasBase + File.separator + "apps" + File.separator + "time-test.ear");
110
111         if (!cmd.run()) {
112             fail("Client fail see output for informations");
113         }
114     }
115
116
117     public void testTimeEndpointURLPublication() throws Exception JavaDoc {
118         String JavaDoc port = System.getProperty("http.port");
119
120         String JavaDoc url = "http://localhost:" + port + TIMEPORT_URL + "?JWSDL";
121         WSDLFactory factory = WSDLFactory.newInstance();
122         WSDLReader reader = factory.newWSDLReader();
123         reader.setFeature("javax.wsdl.importDocuments", true);
124         Definition def = reader.readWSDL(url);
125         
126         Import imp = (Import) def.getImports("jonas:Time").get(0);
127         assertEquals("wsdl:import[@location] not updated !", url + "&filename=Time.wsdl&context=.", imp.getLocationURI());
128     }
129
130 }
Popular Tags