This project has retired. For details please refer to its Attic page.
WSDLLocatorTest 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.URISyntaxException;
18  import java.net.URL;
19  
20  import org.apache.juddi.v3.client.ClassUtil;
21  import org.apache.juddi.v3.client.mapping.wsdl.WSDLLocatorImpl;
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  /**
26   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
27   */
28  public class WSDLLocatorTest {
29  
30  	@Test
31  	public void testResolveAbsoluteURL() {
32  		WSDLLocatorImpl wsdlLocatorImpl = new WSDLLocatorImpl(null);
33  		URL url = wsdlLocatorImpl.constructImportUrl(null, "http://localhost/file.wsdl");
34  		Assert.assertEquals("http://localhost/file.wsdl", url.toExternalForm());
35  	}
36  	
37  	@Test
38  	public void testResolveAbsoluteURL2() {
39  		WSDLLocatorImpl wsdlLocatorImpl = new WSDLLocatorImpl(null);
40  		URL url = wsdlLocatorImpl.constructImportUrl("should get ignored", "http://localhost/file.wsdl");
41  		Assert.assertEquals("http://localhost/file.wsdl", url.toExternalForm());
42  	}
43  	
44  	@Test
45  	public void testResolveInCurrentDir() {
46  		WSDLLocatorImpl wsdlLocatorImpl = new WSDLLocatorImpl(null);
47  		URL wsdlFile = ClassUtil.getResource("wsdl/HelloWorld.wsdl", this.getClass());
48  		if (wsdlFile==null) Assert.fail("Can not find HelloWorld.wsdl file");
49  		String wsdlFileStr = wsdlFile.toExternalForm();
50  		String wsdlDir = wsdlFileStr.substring(0,wsdlFileStr.lastIndexOf("/"));
51  		URL url = wsdlLocatorImpl.constructImportUrl(wsdlFileStr, "child.wsdl");
52  		Assert.assertEquals(wsdlDir + "/child.wsdl", url.toExternalForm());
53  	}
54  	
55  	@Test
56  	public void testResolveInCurrentDir2() {
57  		WSDLLocatorImpl wsdlLocatorImpl = new WSDLLocatorImpl(null);
58  		URL wsdlFile = ClassUtil.getResource("wsdl/HelloWorld.wsdl", this.getClass());
59  		if (wsdlFile==null) Assert.fail("Can not find HelloWorld.wsdl file");
60  		String wsdlFileStr = wsdlFile.toExternalForm();
61  		String wsdlDir = wsdlFileStr.substring(0,wsdlFileStr.lastIndexOf("/"));
62  		URL url = wsdlLocatorImpl.constructImportUrl(wsdlFileStr, "./child.wsdl");
63  		Assert.assertEquals(wsdlDir + "/child.wsdl", url.toExternalForm());
64  	}
65  	
66  	@Test
67  	public void testResolveInParentDir() {
68  		WSDLLocatorImpl wsdlLocatorImpl = new WSDLLocatorImpl(null);
69  		URL wsdlFile = ClassUtil.getResource("wsdl/HelloWorld.wsdl", this.getClass());
70  		if (wsdlFile==null) Assert.fail("Can not find HelloWorld.wsdl file");
71  		String wsdlFileStr = wsdlFile.toExternalForm();
72  		String wsdlDir = wsdlFileStr.substring(0,wsdlFileStr.lastIndexOf("/"));
73  		wsdlDir = wsdlDir.substring(0, wsdlDir.lastIndexOf("/"));
74  		URL url = wsdlLocatorImpl.constructImportUrl(wsdlFileStr, "../child.wsdl");
75  		Assert.assertEquals(wsdlDir + "/child.wsdl", url.toExternalForm());
76  	}
77  	
78  	@Test
79  	public void testResolveInParentDir2() throws URISyntaxException {
80  		WSDLLocatorImpl wsdlLocatorImpl = new WSDLLocatorImpl(null);
81  		URL wsdlFile = ClassUtil.getResource("wsdl/HelloWorld.wsdl", this.getClass());
82  		if (wsdlFile==null) Assert.fail("Can not find HelloWorld.wsdl file");
83  		String wsdlFileStr = wsdlFile.toExternalForm();
84  		String wsdlDir = wsdlFileStr.substring(0,wsdlFileStr.lastIndexOf("/"));
85  		wsdlDir = wsdlDir.substring(0, wsdlDir.lastIndexOf("/"));
86  		wsdlDir = wsdlDir.substring(0, wsdlDir.lastIndexOf("/"));
87  		URL url = wsdlLocatorImpl.constructImportUrl(wsdlFileStr, "../../child.wsdl");
88  		Assert.assertEquals(wsdlDir + "/child.wsdl", url.toExternalForm());
89  	}
90  	
91  }