1 57 58 package schema; 59 60 import java.util.Enumeration; 61 import java.util.Hashtable; 62 63 import javax.wsdl.Definition; 64 import javax.xml.namespace.QName; 65 import junit.framework.Test; 66 import junit.framework.TestCase; 67 import junit.framework.TestSuite; 68 69 import org.apache.wsif.schema.Parser; 70 import org.apache.wsif.util.WSIFUtils; 71 import org.apache.wsif.wsdl.WSIFWSDLLocatorImpl; 72 73 import util.TestUtilities; 74 75 79 public class SchemaTest extends TestCase { 80 String wsdlLocation1 = TestUtilities.getWsdlPath("java\\test\\schema") + "SchemaTest1.wsdl"; 81 String wsdlLocation2 = TestUtilities.getWsdlPath("java\\test\\schema") + "SchemaTest2.wsdl"; 82 String wsdlLocation3 = TestUtilities.getWsdlPath("java\\test\\schema") + "SchemaTest3.wsdl"; 83 84 Hashtable expectedA = new Hashtable(); 85 Hashtable expectedB = new Hashtable(); 86 87 public SchemaTest(String name) { 88 super(name); 89 } 90 91 public static void main(String[] args) { 92 junit.textui.TestRunner.run(suite()); 93 } 94 95 public static Test suite() { 96 return new TestSuite(SchemaTest.class); 97 } 98 99 public void setUp() { 100 TestUtilities.setUpExtensionsAndProviders(); 101 expectedA.put( 102 new QName("http://types.wsiftest/", "addresses"), 103 "[Lwsiftest.types.Address;"); 104 expectedA.put( 105 new QName("http://types.wsiftest/", "InfoResponse"), 106 "wsiftest.types.InfoResponseElement"); 107 expectedA.put( 108 new QName("http://types.wsiftest/", "ArrayOfArrayOfAddress"), 109 "[[Lwsiftest.types.Address;"); 110 expectedA.put( 111 new QName("http://types.wsiftest/", "phone"), 112 "wsiftest.types.Phone"); 113 expectedA.put( 114 new QName("http://types.wsiftest/", "ArrayOfLong"), 115 "[[J"); 116 expectedA.put( 117 new QName("http://types.wsiftest/", "address"), 118 "wsiftest.types.Address"); 119 expectedA.put( 120 new QName("http://types.wsiftest/", "InfoRequest"), 121 "wsiftest.types.InfoRequestElement"); 122 expectedA.put(new QName("http://types.wsiftest/", "ArrayOfInt"), "[I"); 123 expectedA.put( 124 new QName("http://types.wsiftest/", "ArrayOfAddress"), 125 "[Lwsiftest.types.Address;"); 126 127 128 expectedB.put( 130 new QName("http://types.wsiftest/", "addresses"), 131 "[Lwsiftest.types2.Address;"); 132 expectedB.put( 133 new QName("http://types.wsiftest/", "InfoResponse"), 134 "wsiftest.types.InfoResponseElement"); 135 expectedB.put( 136 new QName("http://types2.wsiftest/", "ArrayOfArrayOfAddress"), 137 "[[Lwsiftest.types2.Address;"); 138 expectedB.put( 139 new QName("http://types2.wsiftest/", "phone"), 140 "wsiftest.types2.Phone"); 141 expectedB.put( 142 new QName("http://types.wsiftest/", "ArrayOfLong"), 143 "[[J"); 144 expectedB.put( 145 new QName("http://types2.wsiftest/", "address"), 146 "wsiftest.types2.Address"); 147 expectedB.put( 148 new QName("http://types.wsiftest/", "InfoRequest"), 149 "wsiftest.types.InfoRequestElement"); 150 expectedB.put(new QName("http://types.wsiftest/", "ArrayOfInt"), "[I"); 151 expectedB.put( 152 new QName("http://types2.wsiftest/", "ArrayOfAddress"), 153 "[Lwsiftest.types2.Address;"); 154 } 155 156 public void testParsing() { 157 doIt(wsdlLocation1, expectedA); 158 doIt(wsdlLocation2, expectedA); 159 doIt(wsdlLocation3, expectedB); 160 } 161 162 163 private void doIt(String wsdl, Hashtable expectedResults) { 164 try { 165 System.out.println("*** " + wsdl + " ***\n"); 166 Definition def = WSIFUtils.readWSDL(null, wsdl); 167 Hashtable table = new Hashtable(); 168 Parser.getTypeMappings(def, table, false); 169 if (table != null) { 170 System.out.println("WITHOUT STANDARD MAPPINGS:"); 171 Enumeration k = table.keys(); 172 while(k.hasMoreElements()) { 173 QName qn = (QName) k.nextElement(); 174 String cl = (String) table.get(qn); 175 System.out.println(qn + " -> " + cl); 176 } 177 } else { 178 System.out.println("WITHOUT STANDARD MAPPINGS RETURNED NULL!!"); 179 assertTrue("With wsdl "+wsdl+", table without standard mappings was null", false); 180 } 181 checkResult(wsdl, table, expectedResults); 182 System.out.println("- - - -"); 183 Hashtable table2 = new Hashtable(); 184 Parser.getTypeMappings(def, table2); 185 if (table2 != null) { 186 System.out.println("WITH STANDARD MAPPINGS:"); 187 Enumeration k = table2.keys(); 188 while(k.hasMoreElements()) { 189 QName qn = (QName) k.nextElement(); 190 String cl = (String) table2.get(qn); 191 System.out.println(qn + " -> " + cl); 192 } 193 } else { 194 System.out.println("WITH STANDARD MAPPINGS RETURNED NULL!!"); 195 assertTrue("With wsdl "+wsdl+", table with standard mappings was null", false); 196 } 197 checkResult(wsdl, table2, expectedResults); 198 System.out.println("-----------------------------------------------------\n"); 199 } catch (Exception e) { 200 System.err.println( 201 "SchemaTest caught exception " + e); 202 e.printStackTrace(); 203 assertTrue(false); 204 } finally { 205 TestUtilities.resetDefaultProviders(); 206 } 207 } 208 209 private void doItWithClassLoader(String wsdl, Hashtable expectedResults) { 210 try { 211 System.out.println("*** " + wsdl + " ***\n"); 212 ClassLoader loader = this.getClass().getClassLoader(); 213 Definition def = WSIFUtils.readWSDL(null, wsdl, loader); 214 Hashtable table = new Hashtable(); 215 Parser.getTypeMappings(def, table, loader, false); 216 if (table != null) { 217 System.out.println("WITHOUT STANDARD MAPPINGS:"); 218 Enumeration k = table.keys(); 219 while(k.hasMoreElements()) { 220 QName qn = (QName) k.nextElement(); 221 String cl = (String) table.get(qn); 222 System.out.println(qn + " -> " + cl); 223 } 224 } else { 225 System.out.println("WITHOUT STANDARD MAPPINGS RETURNED NULL!!"); 226 assertTrue("With wsdl "+wsdl+" and using a classloader, table without standard mappings was null", false); 227 } 228 checkResult(wsdl, table, expectedResults); 229 System.out.println("- - - -"); 230 Hashtable table2 = new Hashtable(); 231 Parser.getTypeMappings(def, table2, loader, true); 232 if (table2 != null) { 233 System.out.println("WITH STANDARD MAPPINGS:"); 234 Enumeration k = table2.keys(); 235 while(k.hasMoreElements()) { 236 QName qn = (QName) k.nextElement(); 237 String cl = (String) table2.get(qn); 238 System.out.println(qn + " -> " + cl); 239 } 240 } else { 241 System.out.println("WITH STANDARD MAPPINGS RETURNED NULL!!"); 242 assertTrue("With wsdl "+wsdl+" and using a classloader, table with standard mappings was null", false); 243 } 244 checkResult(wsdl, table2, expectedResults); 245 System.out.println("-----------------------------------------------------\n"); 246 } catch (Exception e) { 247 System.err.println( 248 "SchemaTest caught exception " + e); 249 e.printStackTrace(); 250 assertTrue(false); 251 } finally { 252 TestUtilities.resetDefaultProviders(); 253 } 254 } 255 256 private void checkResult(String wsdl, Hashtable results, Hashtable expected) { 257 Enumeration enum = expected.keys(); 258 while(enum.hasMoreElements()) { 259 QName key = (QName) enum.nextElement(); 260 String value = (String) expected.get(key); 261 if (results.containsKey(key)) { 262 String resultVal = (String) results.get(key); 263 if (!value.equals(resultVal)) { 264 assertTrue("Using wsdl "+wsdl+" results did not contain correct value for type "+key 265 + ", value should be "+value+" but result was "+resultVal, false); 266 } 267 } else { 268 assertTrue("Using wsdl "+wsdl+" results did not contain type "+key, false); 269 } 270 } 271 } 272 } 273 | Popular Tags |