1 57 58 package wsdl; 59 60 71 72 import java.io.InputStream ; 73 import java.io.InputStreamReader ; 74 import java.io.Reader ; 75 import java.net.URL ; 76 77 import javax.wsdl.Definition; 78 import junit.framework.Test; 79 import junit.framework.TestCase; 80 import junit.framework.TestSuite; 81 82 import org.apache.wsif.WSIFService; 83 import org.apache.wsif.WSIFServiceFactory; 84 import org.apache.wsif.util.WSIFUtils; 85 import util.TestUtilities; 86 87 public class ClassLoaderTest extends TestCase { 88 String wsdlLocation = "test/ImportingTest.wsdl"; 89 String wsdlLocation2 = "test/ImportingTest2.wsdl"; 90 String wsdlLocation3 = "test/ImportingTest3.wsdl"; 91 String wsdlLocation4 = "ImportingTest4.wsdl"; 92 String wsdlLocation5 = "test/subtest/ImportingTest5.wsdl"; 93 String wsdlLocation6 = "test/subtest/subtest2/ImportingTest6.wsdl"; 94 String wsdlLocation7 = 95 TestUtilities.getWsdlPath("java\\test\\addressbook") 96 + "ImportingAddressBook.wsdl"; 97 String wsdlLocationError = "test/subtest/subtest2/ImportingTestError.wsdl"; 98 String wsdlLocationA = "ImportingTestA.wsdl"; 99 100 public ClassLoaderTest(String name) { 101 super(name); 102 } 103 104 public static void main(String [] args) { 105 junit.textui.TestRunner.run(suite()); 106 } 107 108 public static Test suite() { 109 return new TestSuite(ClassLoaderTest.class); 110 } 111 112 public void setUp() { 113 TestUtilities.setUpExtensionsAndProviders(); 114 } 115 116 public void test() { 119 doIt(wsdlLocation); 120 } 121 122 public void test2() { 125 doIt(wsdlLocation2); 126 } 127 128 public void test3() { 131 doIt(wsdlLocation3); 132 } 133 134 public void test4() { 137 doIt(wsdlLocation4); 138 } 139 140 public void test5() { 143 doIt(wsdlLocation5); 144 } 145 146 public void test6() { 149 doIt(wsdlLocation6); 150 } 151 152 public void test7() { 155 if (TestUtilities.areWeTesting("remotewsdl")) { 156 doIt(wsdlLocation7); 157 } 158 } 159 160 public void test8() { 161 doItWithReader(wsdlLocation2); 162 } 163 164 public void test9() { 168 doIt(wsdlLocationA); 169 } 170 171 public void testError() { 174 doItError(wsdlLocationError); 175 } 176 177 private void doIt(String wsdlLoc) { 178 try { 179 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 180 WSIFService service = 181 factory 182 .getService(wsdlLoc, this.getClass().getClassLoader(), null, 183 null, "http://wsifservice.addressbook/", "AddressBook"); } catch (Exception e) { 188 System.err.println( 189 "ClassLoaderTest(" + wsdlLoc + ") caught exception " + e); 190 e.printStackTrace(); 191 assertTrue(false); 192 } 193 } 194 195 private void doItError(String wsdlLoc) { 196 try { 197 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 198 WSIFService service = 199 factory 200 .getService(wsdlLoc, this.getClass().getClassLoader(), null, 201 null, "http://wsifservice.addressbook/", "AddressBook"); assertTrue("Import location of '../../../../AddressBook.wsdl'" + 206 "should have caused an error", false); 207 } catch (Exception e) { 208 } 210 } 211 212 private void doItWithReader(String wsdlLoc) { 213 InputStream in = null; 214 ClassLoader loader = this.getClass().getClassLoader(); 215 try { 216 URL url = null; 217 if (wsdlLoc.indexOf(":") == -1) 218 url = new URL ("file", null, wsdlLoc); 219 else 220 url = new URL (wsdlLoc); 221 String wsdlRelativeLocation = url.getPath(); 222 if (wsdlRelativeLocation.startsWith("/")) 223 wsdlRelativeLocation = wsdlRelativeLocation.substring(1); 224 in = loader.getResourceAsStream(wsdlRelativeLocation); 225 Reader reader = new InputStreamReader (in); 226 Definition def = WSIFUtils.readWSDL(url, reader, loader); 227 assertNotNull("Definition is null!!", def); 228 } catch (Exception e) { 229 System.err.println( 230 "ClassLoaderTest(" + wsdlLoc + ") caught exception " + e); 231 assertTrue(false); 232 } 233 } 234 } 235 | Popular Tags |