001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2005 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 1any 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: A_WebServicesEndpoint.java 7547 2005-10-20 15:03:58Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.examples.clients.webservices;
025:
026: import java.io.File;
027: import java.io.FileInputStream;
028: import java.util.Properties;
029:
030: import javax.wsdl.Definition;
031: import javax.wsdl.Port;
032: import javax.wsdl.Service;
033: import javax.wsdl.extensions.soap.SOAPAddress;
034: import javax.wsdl.factory.WSDLFactory;
035: import javax.wsdl.xml.WSDLReader;
036: import javax.xml.namespace.QName;
037:
038: import com.meterware.httpunit.WebForm;
039: import com.meterware.httpunit.WebLink;
040: import com.meterware.httpunit.WebResponse;
041:
042: /**
043: * Define a class to test the webServices examples wsWarExample
044: * Test WebServices deployment OK and test Call on deployed WebService
045: * @author Guillaume Sauthier
046: */
047: public abstract class A_WebServicesEndpoint extends A_WebServices {
048:
049: /**
050: * property name => file1 WSDLHandler is mandatory for this test !
051: */
052: private static final String JPROP_WSDL_LOCATION = "jonas.service.publish.file.directory";
053:
054: public A_WebServicesEndpoint(String s, String urlPrefix) {
055: super (s, urlPrefix);
056: }
057:
058: public A_WebServicesEndpoint(String s, String urlPrefix,
059: String username, String password) {
060: super (s, urlPrefix, username, password);
061: }
062:
063: /**
064: * Check if Axis is Running
065: * @param idServicesLink indicate where is the link to /services in the homepage
066: * @param portName the name of the port we want to check
067: * @throws Exception if an error occurs
068: */
069: public void checkAxisServicesAccessible(int idServicesLink,
070: String context, String portName) throws Exception {
071:
072: WebResponse wr = wc.getResponse(url + "index.html");
073: WebLink services = wr.getLinks()[idServicesLink];
074:
075: // click the link
076: WebResponse swr = services.click();
077:
078: // traverse the links and find the interresting one.
079: boolean found = false;
080: for (int i = 0; i < swr.getLinks().length; i++) {
081: String ws_url = swr.getLinks()[i].getURLString();
082: if (ws_url.equalsIgnoreCase(url + context + "/" + portName
083: + "?jwsdl"))
084: found = true;
085: }
086: if (!found)
087: fail("endpoint '" + portName + "' not found in /" + context);
088:
089: }
090:
091: /**
092: * Check if WSDL is generated
093: * @param idWSDLServiceLink indicate where we can find the link
094: * to WSDL of the port we want to test. (first, second, ...)
095: * @throws Exception if an error occurs
096: */
097: public void checkAxisWSDL(String path) throws Exception {
098:
099: WebResponse wr = wc.getResponse(url + path);
100: assertEquals("Must be an XML mime type", "text/xml", wr
101: .getContentType());
102:
103: }
104:
105: /**
106: * Check if deployed WebService is running
107: * @param formPage the filename of the webpage containing the form
108: * @param endpoint the URL where local service can be found
109: * @param name the name to set as parameter
110: * @param pageTitle title of the returned page
111: * @throws Exception if an error occurs
112: */
113: public void checkDeployedWebService(String formPage,
114: String endpoint, String name, String pageTitle)
115: throws Exception {
116:
117: // Get the page containing the form
118: WebResponse wr = wc.getResponse(url + formPage);
119:
120: // get the form named "prepare"
121: WebForm form = wr.getFormWithName("prepare");
122: // set all parameters
123: form.setParameter("name", name);
124: // submit
125: WebResponse wr2 = form.submit();
126:
127: String text = wr2.getText();
128:
129: String valTitle = "<title>" + pageTitle + "</title>";
130: String valURL = "Working with URL : <i>" + endpoint
131: + "</i><br/>";
132: String valHello = "<b>result of sayHello(name) method :</b><i>Hello "
133: + name + "</i><br/>";
134: String valQuotes = "<b>result of getCotes() method :</b><i>12</i><br/>";
135:
136: assertTrue("incorrect title", (text.indexOf(valTitle) != -1));
137: assertTrue("incorrect URL", (text.indexOf(valURL) != -1));
138: assertTrue("incorrect Name", (text.indexOf(valHello) != -1));
139: assertTrue("incorrect Cotes", (text.indexOf(valQuotes) != -1));
140:
141: }
142:
143: /**
144: * Check if WSDL has been published.
145: * @param wsdlFilename the filename of the WSDL file
146: * @param tns targetNameSpace of the Definition
147: * @param serviceName the localpart of the Service QName
148: * @param portName the name of the WSDL' Port
149: * @param endpoint the expected URL
150: * @throws Exception if an error occurs
151: */
152: public void checkWSDLPublication(String wsdlFilename, String tns,
153: String serviceName, String portName, String endpoint)
154: throws Exception {
155:
156: String jonasbase = System.getProperty("jonas.base");
157: Properties props = new Properties();
158: props.load(new FileInputStream(new File(jonasbase,
159: "conf/file1.properties")));
160: String wsdlLoc = props.getProperty(JPROP_WSDL_LOCATION);
161:
162: File wsdl = new File(wsdlLoc, wsdlFilename);
163:
164: assertTrue("WSDL is not created", wsdl.exists());
165: assertTrue("WSDL is not a file", wsdl.isFile());
166:
167: WSDLFactory f = WSDLFactory.newInstance();
168: WSDLReader r = f.newWSDLReader();
169:
170: r.setFeature("javax.wsdl.verbose", true);
171: r.setFeature("javax.wsdl.importDocuments", false);
172:
173: Definition def = r.readWSDL(wsdl.getPath());
174: Service s = def.getService(new QName(tns, serviceName));
175: Port p = s.getPort(portName);
176: SOAPAddress sa = (SOAPAddress) p.getExtensibilityElements()
177: .get(0);
178:
179: assertEquals("URL has not been updated", endpoint, sa
180: .getLocationURI());
181:
182: }
183:
184: }
|