1/*2 * Copyright 2001-2009 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * http://www.apache.org/licenses/LICENSE-2.08 * 9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15package org.apache.juddi.v3.client.mapping.wsdl;
1617import java.net.HttpURLConnection;
18import java.net.MalformedURLException;
19import java.net.URISyntaxException;
20import java.net.URL;
21import java.net.UnknownHostException;
2223import javax.wsdl.Definition;
24import javax.wsdl.WSDLException;
2526import org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL;
27import org.junit.Assert;
28import org.junit.Test;
2930/**31 * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>32 */33publicclassReadWSDLTest {
3435 @Test
36publicvoid readFromFile() throws WSDLException, URISyntaxException, Exception {
3738 ReadWSDL readWSDL = new ReadWSDL();
39 Definition definition = readWSDL.readWSDL("wsdl/HelloWorld.wsdl");
40 Assert.assertNotNull(definition);
41 }
4243privatestaticboolean IsReachable(String url) {
44 System.out.println("Testing connectivity to " + url);
45try {
46//make a URL to a known source47 URL url2 = new URL(url);
4849//open a connection to that source50 HttpURLConnection urlConnect = (HttpURLConnection) url2.openConnection();
5152//trying to retrieve data from the source. If there53//is no connection, this line will fail54 Object objData = urlConnect.getContent();
55 urlConnect.disconnect();
5657 } catch (Exception e) {
58 System.out.println("Connectivity failed " + e.getMessage());
59return false;
60 }
61 System.out.println("Connectivity passed" );
62returntrue;
6364 }
6566/**67 * normally, this test will work correctly if and only if you're connected68 * to the big bad internet. if you happen to be offline, this test will69 * fail.70 */71 @Test
72publicvoid readFromURL() throws MalformedURLException, Exception {
7374boolean b = IsReachable("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl");
75if (!b) {
76 System.out.println("Skipping test for a remote WSDL due to connectivity problems");
77 }
787980 org.junit.Assume.assumeTrue(b);
81 ReadWSDL readWSDL = new ReadWSDL();
82 Definition definition = null;
83try {
84 definition = readWSDL.readWSDL(new URL("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl"));
85 Assert.assertNotNull(definition);
86 } catch (UnknownHostException ex) {
87 }
888990 }
9192 @Test
93publicvoid readFromJar() throws WSDLException, URISyntaxException, Exception {
9495 ReadWSDL readWSDL = new ReadWSDL();
96 Definition definition = readWSDL.readWSDL("uddi_v3_service.wsdl");
97 Assert.assertNotNull(definition);
98 }
99 }