1 57 58 package soap; 59 60 61 import java.util.Iterator ; 62 63 import javax.jms.JMSException ; 64 import javax.jms.Message ; 65 import javax.jms.Queue ; 66 import javax.jms.QueueConnection ; 67 import javax.jms.QueueConnectionFactory ; 68 import javax.jms.QueueReceiver ; 69 import javax.jms.QueueSession ; 70 import javax.jms.Session ; 71 import javax.jms.TextMessage ; 72 import junit.framework.Test; 73 import junit.framework.TestCase; 74 import junit.framework.TestSuite; 75 76 import org.apache.wsif.WSIFConstants; 77 import org.apache.wsif.WSIFCorrelationId; 78 import org.apache.wsif.WSIFCorrelationService; 79 import org.apache.wsif.WSIFException; 80 import org.apache.wsif.WSIFMessage; 81 import org.apache.wsif.WSIFOperation; 82 import org.apache.wsif.WSIFPort; 83 import org.apache.wsif.WSIFService; 84 import org.apache.wsif.WSIFServiceFactory; 85 import org.apache.wsif.base.WSIFServiceImpl; 86 import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis; 87 import org.apache.wsif.util.WSIFCorrelationServiceLocator; 88 import org.apache.wsif.util.WSIFPluggableProviders; 89 import org.apache.wsif.util.WSIFProperties; 90 import org.apache.wsif.util.jms.WSIFJMSFinder; 91 import org.apache.wsif.util.jms.WSIFJMSFinderForJndi; 92 import util.TestUtilities; 93 94 import async.AsyncResponseHandler; 95 96 107 public class OutputPartsTest extends TestCase { 108 109 static final String WSDL_LOCATION = 110 TestUtilities.getWsdlPath( "java\\test\\soap\\wsifservice" ) + 111 "FakeStockQuote.wsdl"; 112 113 static final String FAKE_SOAP_MSG_FILENAME1 = 114 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 115 "FakeSQRespOK.txt"; 116 static final String FAKE_SOAP_MSG_FILENAME2 = 117 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 118 "FakeSQRespNull.txt"; 119 static final String FAKE_SOAP_MSG_FILENAME3 = 120 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 121 "FakeSQRespMissingReturn.txt"; 122 static final String FAKE_SOAP_MSG_FILENAME4 = 123 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 124 "FakeSQRespMissingPart.txt"; 125 static final String FAKE_SOAP_MSG_FILENAME5 = 126 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 127 "FakeSQRespMissingAllParts.txt"; 128 static final String FAKE_SOAP_MSG_FILENAME6 = 129 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 130 "FakeSQRespRtnTypeErr.txt"; 131 static final String FAKE_SOAP_MSG_FILENAME7 = 132 TestUtilities.getWsdlPath( "java\\test\\soap" ) + 133 "FakeSQRespExtraParts.txt"; 134 135 public OutputPartsTest(String name) { 136 super(name); 137 } 138 139 public static void main(String [] args) { 140 TestUtilities.startListeners(); 141 junit.textui.TestRunner.run(suite()); 142 TestUtilities.stopListeners(); 143 } 144 145 public static Test suite() { 146 return new TestSuite(OutputPartsTest.class); 147 } 148 149 public void setUp() { 150 TestUtilities.setUpExtensionsAndProviders(); 151 } 152 153 public void tearDown() { 154 WSIFPluggableProviders.overrideDefaultProvider( 155 "http://schemas.xmlsoap.org/wsdl/soap/", 156 null); 157 } 158 159 public void testSOAP1() { 160 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME1, null ); 161 } 162 public void testAxis1() { 163 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME1, null ); 164 } 165 public void testSOAP2() { 166 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME2, "return value not found in response message" ); 167 } 168 public void testAxis2() { 169 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME2, "<null>" ); 170 } 171 public void testSOAP3() { 172 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME3, "java.lang.String" ); 173 } 174 public void testAxis3() { 175 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME3, "java.lang.String" ); 176 } 177 public void testSOAP4() { 178 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME4, "p1=null" ); 179 } 180 public void testAxis4() { 181 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME4, "p1=null" ); 182 } 183 public void testSOAP5() { 184 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME5, "parms=null" ); 185 } 186 public void testAxis5() { 187 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME5, "parms=null" ); 188 } 189 public void testSOAP6() { 190 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME6, "java.lang.String" ); 191 } 192 193 public void testSOAP7() { 198 doitStockquote( "SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME7, null ); 199 } 200 201 206 209 public void doitStockquote(String portName, String protocol, String fakeFile, String error) { 210 float value; 211 WSIFPort port; 212 WSIFOperation operation; 213 WSIFMessage input, output, fault, context; 214 215 if (portName.toUpperCase().indexOf("JMS") != -1 216 && !TestUtilities.areWeTesting("jms")) { 217 return; 218 } 219 220 TestUtilities.setProviderForProtocol( protocol ); 221 222 System.out.println("\n=== StockQuote"); 223 try { 224 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 225 WSIFService service = factory.getService( WSDL_LOCATION, 226 null, null, "http://wsifservice.stockquote/", "StockquotePT" ); 231 port = service.getPort(portName); 232 233 operation = port.createOperation( "getQuote" ); 235 236 context = operation.getContext(); 237 context.setObjectPart( 238 WSIFConstants.CONTEXT_JMS_PREFIX + "WSIF_FAKE", 239 "\"" + fakeFile + "\"" ); 240 241 input = operation.createInputMessage(); 242 input.setName("GetQuoteInput"); 243 input.setObjectPart("symbol", "" ); 244 output = operation.createOutputMessage(); 245 246 doSyncOp( operation, input, output, context ); 248 249 Object o; 250 251 o = output.getObjectPart( "quote" ); 252 if ( o != null ) { 253 value = ((Float )o).floatValue(); 254 assertTrue( "doAsyncOpNoHandler stockquote value incorrect!", 255 value == -1.0F ); 256 } else if (error.equals("<null>")) { 257 assertNull("return value not null!!", o); 258 } else { 259 assertTrue( "return value null!!", 260 error.equals( "return=null" ) 261 || error.equals( "all=null" ) ); 262 } 263 264 265 System.out.println( "out message contains:" ); 266 String partName; 267 for (Iterator i = output.getPartNames(); i.hasNext(); ) { 268 partName = (String ) i.next(); 269 o = output.getObjectPart( partName ); 270 System.out.println( "part=" + partName + " value=" + o ); 271 } 272 273 o = output.getObjectPart( "p1" ); 274 if ( o != null ) { 275 assertTrue( "error on part p1!!", o instanceof String ); 276 } else if (error.equals("<null>")) { 277 assertNull("return value not null!!", o); 278 } else { 279 assertTrue( "p1 is null!!", 280 error.equals( "p1=null" ) 281 || error.equals( "parms=null" ) 282 || error.equals( "all=null" ) ); 283 } 284 o = output.getObjectPart( "p2" ); 285 if ( o != null ) { 286 assertTrue( "error on part p2!!", o instanceof Float ); 287 } else if (error.equals("<null>")) { 288 assertNull("return value not null!!", o); 289 } else { 290 assertTrue( "p2 is null!!", 291 error.equals( "p2=null" ) 292 || error.equals( "parms=null" ) 293 || error.equals( "all=null" ) ); 294 } 295 o = output.getObjectPart( "p3" ); 296 if ( o != null ) { 297 assertTrue( "error on part p3!!", o instanceof String ); 298 } else if (error.equals("<null>")) { 299 assertNull("return value not null!!", o); 300 } else { 301 assertTrue( "p3 is null!!", 302 error.equals( "p3=null" ) 303 || error.equals( "parms=null" ) 304 || error.equals( "all=null" ) ); 305 } 306 307 } catch (Exception ex) { 308 if ( error == null || !error.equals(ex.getMessage()) ) { 309 ex.printStackTrace(); 310 assertTrue("exception during stockquote test: " + ex.getMessage(), false); 311 } 312 } 313 } 314 315 private void doSyncOp(WSIFOperation op, 316 WSIFMessage input, 317 WSIFMessage output, 318 WSIFMessage context) throws WSIFException { 319 op.setContext( context ); 321 WSIFMessage fault = op.createFaultMessage(); 322 boolean ok = op.executeRequestResponseOperation(input, output, fault ); 323 assertTrue( "executeRequestResponseOperation returned false!", ok ); 324 } 329 330 private WSIFMessage doAsyncOp(WSIFOperation op, WSIFMessage input, WSIFMessage context) throws WSIFException{ 331 AsyncResponseHandler handler = new AsyncResponseHandler(1); context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 333 TestUtilities.getWsifProperty("wsif.async.replytoq") ); 334 op.setContext( context ); 335 WSIFCorrelationId id = op.executeRequestResponseAsync(input, handler); 336 337 int i = 5; while ( i-- > 0 && !handler.isDone() ) { 339 System.out.println( "async requests sent, waiting for responses - " + i ); 340 try { 341 Thread.sleep(3000); 342 } catch (InterruptedException ex) {} 343 } 344 assertTrue( "no response to async operation!", i > 0 ); return handler.getOutputs()[0]; 346 } 347 348 private WSIFMessage doAsyncOpNoHandler(WSIFOperation op, WSIFMessage input, WSIFMessage context) 349 throws WSIFException, JMSException { 350 WSIFMessage output = null; 351 352 context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 353 TestUtilities.getWsifProperty("wsif.async.replytoq2") ); 354 context.setObjectPart( "testJMSnoHandler", "true" ); 355 op.setContext( context ); 356 WSIFCorrelationId id = op.executeRequestResponseAsync( input ); 357 System.out.println( "async operation done, correlation id=" + id.getCorrelationId() ); 358 op = null; 359 360 Object jmsResponse = 361 TestUtilities.getJMSAsyncResponse( 362 id.getCorrelationId(), 363 TestUtilities.getWsifProperty("wsif.async.replytoq2")); 364 365 WSIFCorrelationService cs = 366 WSIFCorrelationServiceLocator.getCorrelationService(); 367 Object o; 368 synchronized( cs ) { 369 o = cs.get( id ); 370 } 371 if ( o != null && o instanceof WSIFOperation ) { 372 cs.remove( id ); 373 op = (WSIFOperation)o; 374 } else { 375 assertTrue( "stored correlation object not as expected: " + o, false ); 376 } 377 output = op.createOutputMessage(); 378 WSIFMessage fault = op.createFaultMessage(); 379 op.processAsyncResponse( jmsResponse, output, fault ); 380 381 return output; 382 } 383 }
| Popular Tags
|