This project has retired. For details please refer to its Attic page.
ReadWSDLTest xref
View Javadoc
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 at
7    *      http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * 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 and
13   * limitations under the License.
14   */
15  package org.apache.juddi.v3.client.mapping.wsdl;
16  
17  import java.net.HttpURLConnection;
18  import java.net.MalformedURLException;
19  import java.net.URISyntaxException;
20  import java.net.URL;
21  import java.net.UnknownHostException;
22  
23  import javax.wsdl.Definition;
24  import javax.wsdl.WSDLException;
25  
26  import org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL;
27  import org.junit.Assert;
28  import org.junit.Test;
29  
30  /**
31   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
32   */
33  public class ReadWSDLTest {
34  
35      @Test
36      public void readFromFile() throws WSDLException, URISyntaxException, Exception {
37  
38          ReadWSDL readWSDL = new ReadWSDL();
39          Definition definition = readWSDL.readWSDL("wsdl/HelloWorld.wsdl");
40          Assert.assertNotNull(definition);
41      }
42  
43      private static boolean IsReachable(String url) {
44          System.out.println("Testing connectivity to " + url);
45          try {
46              //make a URL to a known source
47              URL url2 = new URL(url);
48  
49              //open a connection to that source
50              HttpURLConnection urlConnect = (HttpURLConnection) url2.openConnection();
51  
52              //trying to retrieve data from the source. If there
53              //is no connection, this line will fail
54              Object objData = urlConnect.getContent();
55              urlConnect.disconnect();
56  
57          } catch (Exception e) {
58              System.out.println("Connectivity failed " + e.getMessage());
59              return false;
60          }
61          System.out.println("Connectivity passed" );
62          return true;
63  
64      }
65  
66      /**
67       * normally, this test will work correctly if and only if you're connected
68       * to the big bad internet. if you happen to be offline, this test will
69       * fail.
70       */
71      @Test
72      public void readFromURL() throws MalformedURLException, Exception {
73          
74          boolean b = IsReachable("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl");
75          if (!b) {
76              System.out.println("Skipping test for a remote WSDL due to connectivity problems");
77          }
78  
79  
80          org.junit.Assume.assumeTrue(b);
81          ReadWSDL readWSDL = new ReadWSDL();
82          Definition definition = null;
83          try {
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          }
88  
89  
90      }
91  
92      @Test
93      public void readFromJar() throws WSDLException, URISyntaxException, Exception {
94  
95          ReadWSDL readWSDL = new ReadWSDL();
96          Definition definition = readWSDL.readWSDL("uddi_v3_service.wsdl");
97          Assert.assertNotNull(definition);
98      }
99  }