1 57 58 package docStyle; 59 60 import http.net.pointwsp.www.ws.finance.ArrayOfCurrency; 61 import http.net.pointwsp.www.ws.finance.Currency; 62 import http.net.pointwsp.www.ws.finance.Currencyrates; 63 import java.io.StringReader ; 64 import java.io.StringWriter ; 65 66 import junit.framework.Test; 67 import junit.framework.TestCase; 68 import junit.framework.TestSuite; 69 70 import org.apache.wsif.WSIFConstants; 71 import org.apache.wsif.WSIFMessage; 72 import org.apache.wsif.WSIFOperation; 73 import org.apache.wsif.WSIFPort; 74 import org.apache.wsif.WSIFService; 75 import org.apache.wsif.WSIFServiceFactory; 76 import org.apache.xerces.parsers.DOMParser; 77 import org.apache.xml.serialize.OutputFormat; 78 import org.apache.xml.serialize.XMLSerializer; 79 import org.w3c.dom.Element ; 80 import org.xml.sax.InputSource ; 81 import util.TestUtilities; 82 83 import docStyle.wsifservice.PwspNoCentrbankCurRatesSoap; 84 85 90 public class NWBankTest extends TestCase { 91 String wsdlLocation = 92 TestUtilities.getWsdlPath("java\\test\\docStyle\\wsifservice") 93 + "nwBank.wsdl"; 94 96 public NWBankTest(String name) { 97 super(name); 98 } 99 100 public static void main(String [] args) { 101 TestUtilities.startListeners( 102 TestUtilities.ADDRESSBOOK_LISTENER 103 | TestUtilities.ASYNC_LISTENER 104 | TestUtilities.NATIVEJMS_LISTENER); 105 junit.textui.TestRunner.run(suite()); 106 TestUtilities.stopListeners(); 107 } 108 109 public static Test suite() { 110 return new TestSuite(NWBankTest.class); 111 } 112 113 public void setUp() { 114 TestUtilities.setUpExtensionsAndProviders(); 115 } 116 117 public void testDynamicAxis() { 118 doitDyn("pwspNoCentrbankCurRatesSoap", "axis"); 119 } 120 121 public void testStubsAxis() { 122 doitStub("pwspNoCentrbankCurRatesSoap", "axis"); 123 } 124 125 public void testMessagingAxis() { 126 doitMessaging("pwspNoCentrbankCurRatesSoap", "axis"); 127 } 128 129 public void testDynJMS() { 130 doitDyn("pwspNoCentrbankCurRatesSoapJMS", "axis"); 131 } 132 133 public void testStubsAxisJMS() { 134 doitStub("pwspNoCentrbankCurRatesSoapJMS", "axis"); 135 } 136 137 private void doitDyn(String portName, String protocol) { 138 if (portName.toUpperCase().indexOf("JMS") != -1 139 && !TestUtilities.areWeTesting("jms")) 140 return; 141 142 TestUtilities.setProviderForProtocol(protocol); 143 144 try { 145 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 146 WSIFService service = 147 factory.getService( 148 wsdlLocation, 149 null, 150 null, 151 "http/www.pointwsp.net/ws/finance", 152 "pwspNoCentrbankCurRatesSoap"); 153 154 service.mapType( 155 new javax.xml.namespace.QName ("http/www.pointwsp.net/ws/finance", "currencyrates"), 156 Currencyrates.class ); 157 158 service.mapType( 159 new javax.xml.namespace.QName ("http/www.pointwsp.net/ws/finance", "ArrayOfCurrency"), 160 ArrayOfCurrency.class); 161 162 service.mapType( 163 new javax.xml.namespace.QName ("http/www.pointwsp.net/ws/finance", "currency"), 164 Currency.class); 165 166 WSIFMessage context = service.getContext(); 168 context.setObjectPart(WSIFConstants.CONTEXT_OPERATION_STYLE, WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED); 169 service.setContext(context); 170 171 WSIFPort port = service.getPort(portName); 172 173 WSIFOperation operation = port.createOperation("GetRatesXML"); 174 175 WSIFMessage inMsg = operation.createInputMessage(); 176 WSIFMessage outMsg = operation.createOutputMessage(); 177 WSIFMessage faultMsg = operation.createFaultMessage(); 178 179 boolean ok = 180 operation.executeRequestResponseOperation( 181 inMsg, 182 outMsg, 183 faultMsg); 184 185 assertTrue("operation returned false!!", ok); 186 Object o = outMsg.getObjectPart("GetRatesXMLResult"); 187 assertTrue("unexpected result: " + o, o instanceof Currencyrates); 188 189 192 } catch (Exception ex) { 193 ex.printStackTrace(); 194 assertTrue( 195 "AddressBookTest(" 196 + portName 197 + ") caught exception " 198 + ex.getLocalizedMessage(), 199 false); 200 } 201 } 202 203 private void doitStub(String portName, String protocol) { 204 if (portName.toUpperCase().indexOf("JMS") != -1 205 && !TestUtilities.areWeTesting("jms")) 206 return; 207 208 TestUtilities.setProviderForProtocol(protocol); 209 210 try { 211 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 212 WSIFService service = 213 factory.getService( 214 wsdlLocation, 215 null, 216 null, 217 "http/www.pointwsp.net/ws/finance", 218 "pwspNoCentrbankCurRatesSoap"); 219 220 WSIFMessage context = service.getContext(); 222 context.setObjectPart(WSIFConstants.CONTEXT_OPERATION_STYLE, WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED); 223 service.setContext(context); 224 225 PwspNoCentrbankCurRatesSoap stub = (PwspNoCentrbankCurRatesSoap) service.getStub(portName, PwspNoCentrbankCurRatesSoap.class); 226 227 Object o = stub.GetRatesXML(); 228 assertTrue("unexpected result: " + o, o instanceof Currencyrates); 229 232 } catch (Exception ex) { 233 ex.printStackTrace(); 234 assertTrue( 235 "AddressBookTest(" 236 + portName 237 + ") caught exception " 238 + ex.getLocalizedMessage(), 239 false); 240 } 241 } 242 243 private void doitMessaging(String portName, String protocol) { 244 if (portName.toUpperCase().indexOf("JMS") != -1 245 && !TestUtilities.areWeTesting("jms")) 246 return; 247 248 TestUtilities.setProviderForProtocol(protocol); 249 250 try { 251 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 252 WSIFService service = 253 factory.getService( 254 wsdlLocation, 255 null, 256 null, 257 "http/www.pointwsp.net/ws/finance", 258 "pwspNoCentrbankCurRatesSoap"); 259 260 service.mapType( 261 new javax.xml.namespace.QName ("http/www.pointwsp.net/ws/finance", "currencyrates"), 262 Currencyrates.class ); 263 264 service.mapType( 265 new javax.xml.namespace.QName ("http/www.pointwsp.net/ws/finance", "ArrayOfCurrency"), 266 ArrayOfCurrency.class); 267 268 service.mapType( 269 new javax.xml.namespace.QName ("http/www.pointwsp.net/ws/finance", "currency"), 270 Currency.class); 271 272 WSIFPort port = service.getPort(portName); 273 274 WSIFOperation operation = port.createOperation("GetRatesXML"); 275 276 WSIFMessage inMsg = operation.createInputMessage(); 277 WSIFMessage outMsg = operation.createOutputMessage(); 278 WSIFMessage faultMsg = operation.createFaultMessage(); 279 280 String inputDocument = 281 "<GetRatesXML xmlns=\"http/www.pointwsp.net/ws/finance\"/>"; 282 283 DOMParser parser = new DOMParser(); 284 String xmlString = "<?xml version=\"1.0\"?>\n" + inputDocument; 285 parser.parse(new InputSource (new StringReader (xmlString))); 286 Element element = parser.getDocument().getDocumentElement(); 287 289 inMsg.setObjectPart("parameters", element); 290 291 boolean ok = 292 operation.executeRequestResponseOperation( 293 inMsg, 294 outMsg, 295 faultMsg); 296 297 assertTrue("operation returned false!!", ok); 298 299 Element responseElement = 300 (Element ) outMsg.getObjectPart("parameters"); 301 assertTrue("return element is null!!", responseElement != null); 303 304 305 } catch (Exception ex) { 306 ex.printStackTrace(); 307 assertTrue( 308 "AddressBookTest(" 309 + portName 310 + ") caught exception " 311 + ex.getLocalizedMessage(), 312 false); 313 } 314 } 315 316 private void printElement(Element e) throws Exception { 317 OutputFormat of = new OutputFormat(e.getOwnerDocument(), "UTF-8", true); 318 XMLSerializer xmls = new XMLSerializer(of); 319 StringWriter sw = new StringWriter (); 320 xmls.setOutputCharStream(sw); 321 xmls.serialize(e); 322 System.err.println("element=" + sw.toString()); 323 } 324 } 325
| Popular Tags
|