1 57 58 package jms; 59 60 import java.util.Iterator ; 61 62 import junit.framework.Test; 63 import junit.framework.TestCase; 64 import junit.framework.TestSuite; 65 66 import org.apache.wsif.WSIFConstants; 67 import org.apache.wsif.WSIFCorrelationId; 68 import org.apache.wsif.WSIFException; 69 import org.apache.wsif.WSIFMessage; 70 import org.apache.wsif.WSIFOperation; 71 import org.apache.wsif.WSIFPort; 72 import org.apache.wsif.WSIFService; 73 import org.apache.wsif.WSIFServiceFactory; 74 import util.TestUtilities; 75 76 80 public class JmsFaultTest extends TestCase { 81 String wsdlLocation = TestUtilities.getWsdlPath("java\\test\\jms") + "jmsfault.wsdl"; 82 83 private static final boolean SYNC = true; 84 private static final boolean ASYNC = false; 85 86 public JmsFaultTest(String name) { 87 super(name); 88 } 89 90 public static void main(String [] args) { 91 TestUtilities.startListeners(TestUtilities.NATIVEJMS_LISTENER); 92 junit.textui.TestRunner.run (suite()); 93 TestUtilities.stopListeners(); 94 } 95 96 public static Test suite() { 97 return new TestSuite(JmsFaultTest.class); 98 } 99 100 public void setUp() { 101 TestUtilities.setUpExtensionsAndProviders(); 102 } 103 104 public void testNoFaultSync() { 105 doit("throwSimple", 0, false, false, null, null, SYNC); 106 } 107 108 public void testSimpleSync() { 109 doit( 110 "throwSimple", 111 1, 112 true, 113 false, 114 new String [] { "faultText" }, 115 new Object [] { "A Simple Fault" }, SYNC); 116 } 117 118 public void testIntsSync() { 119 doit( 120 "throwSimple", 121 2, 122 true, 123 false, 124 new String [] { "faultInt1", "faultInt2", "faultInt3" }, 125 new Object [] { new Integer (1), new Integer (2), new Integer (3)}, SYNC); 126 } 127 128 public void testTwoIntsSync() { 129 doit( 130 "throwSimple", 131 3, 132 true, 133 false, 134 new String [] { "faultInt1", "faultInt2" }, 135 new Object [] { new Integer (1), new Integer (2) }, SYNC); 136 } 137 138 public void testEmptyJmsFaultSync() { 139 doit( 140 "throwSimple", 141 2, 142 true, 143 false, 144 new String [] { "faultInt1", "faultInt2", "faultInt3" }, 145 new Object [] { new Integer (1), new Integer (2), new Integer (3)}, SYNC); 146 } 147 148 public void testIndicIntSync() { 149 doit( 150 "throwIndicInt", 151 4, 152 true, 153 false, 154 new String [] { "faultText" }, 155 new Object [] { "A Simple Fault" }, SYNC); 156 } 157 158 public void testNoFaultAltSync() { 159 doit("throwSimple", 5, false, false, null, null, SYNC); 160 } 161 162 public void testFaultIndicPropSync() { 163 doit( 164 "throwProperties", 165 6, 166 true, 167 false, 168 new String [] { "faultText", "faultIndic" }, 169 new Object [] { "A Fault Indicator", new Byte ((byte) - 1)}, SYNC); 170 } 171 172 public void testJmsPropFaultSync() { 173 doit( 174 "throwProperties", 175 7, 176 true, 177 false, 178 new String [] { "faultText", "faultIndic", "faultProp" }, 179 new Object [] { 180 "Another Property Fault", 181 new Byte ((byte) - 2), 182 "Another JMS Property" }, SYNC); 183 } 184 185 public void testIndicOnlySync() { 186 doit( 187 "throwProperties", 188 8, 189 true, 190 false, 191 new String [] { "faultIndic" }, 192 new Object [] { new Byte ((byte) - 3)}, 193 SYNC); 194 } 195 196 public void testPropOnlySync() { 197 doit( 198 "throwProperties", 199 9, 200 true, 201 false, 202 new String [] { "faultProp" }, 203 new Object [] { "Another JMS Property" }, 204 SYNC); 205 } 206 207 public void testNullFaultSync() { 208 doit("throwProperties", 10, true, false, null, null, SYNC); 209 } 210 211 212 213 public void testNoFaultAsync() { 214 doit("throwSimple", 0, false, false, null, null, ASYNC); 215 } 216 217 public void testSimpleAsync() { 218 doit( 219 "throwSimple", 220 1, 221 true, 222 false, 223 new String [] { "faultText" }, 224 new Object [] { "A Simple Fault" }, ASYNC); 225 } 226 227 public void testIntsAsync() { 228 doit( 229 "throwSimple", 230 2, 231 true, 232 false, 233 new String [] { "faultInt1", "faultInt2", "faultInt3" }, 234 new Object [] { new Integer (1), new Integer (2), new Integer (3)}, ASYNC); 235 } 236 237 public void testTwoIntsAsync() { 238 doit( 239 "throwSimple", 240 3, 241 true, 242 false, 243 new String [] { "faultInt1", "faultInt2" }, 244 new Object [] { new Integer (1), new Integer (2) }, ASYNC); 245 } 246 247 public void testEmptyJmsFaultAsync() { 248 doit( 249 "throwSimple", 250 2, 251 true, 252 false, 253 new String [] { "faultInt1", "faultInt2", "faultInt3" }, 254 new Object [] { new Integer (1), new Integer (2), new Integer (3)}, ASYNC); 255 } 256 257 public void testIndicIntAsync() { 258 doit( 259 "throwIndicInt", 260 4, 261 true, 262 false, 263 new String [] { "faultText" }, 264 new Object [] { "A Simple Fault" }, ASYNC); 265 } 266 267 public void testNoFaultAltAsync() { 268 doit("throwSimple", 5, false, false, null, null, ASYNC); 269 } 270 271 public void testFaultIndicPropAsync() { 272 doit( 273 "throwProperties", 274 6, 275 true, 276 false, 277 new String [] { "faultText", "faultIndic" }, 278 new Object [] { "A Fault Indicator", new Byte ((byte) - 1)}, ASYNC); 279 } 280 281 public void testJmsPropFaultAsync() { 282 doit( 283 "throwProperties", 284 7, 285 true, 286 false, 287 new String [] { "faultText", "faultIndic", "faultProp" }, 288 new Object [] { 289 "Another Property Fault", 290 new Byte ((byte) - 2), 291 "Another JMS Property" }, ASYNC); 292 } 293 294 public void testIndicOnlyAsync() { 295 doit( 296 "throwProperties", 297 8, 298 true, 299 false, 300 new String [] { "faultIndic" }, 301 new Object [] { new Byte ((byte) - 3)}, 302 ASYNC); 303 } 304 305 public void testPropOnlyAsync() { 306 doit( 307 "throwProperties", 308 9, 309 true, 310 false, 311 new String [] { "faultProp" }, 312 new Object [] { "Another JMS Property" }, 313 ASYNC); 314 } 315 316 public void testNullFaultAsync() { 317 doit("throwProperties", 10, true, false, null, null, ASYNC); 318 } 319 320 private void doit( 321 String method, 322 int choice, 323 boolean faultExpected, 324 boolean exceptionExpected, 325 String [] names, 326 Object [] parts, 327 boolean blocks) { 328 329 if (!TestUtilities.areWeTesting("jms")) 330 return; 331 332 try { 333 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 334 WSIFService service = 335 factory.getService( 336 wsdlLocation, 337 null, 338 null, 339 "http://jms/", 340 "JmsFault"); 341 342 WSIFPort port = service.getPort("default"); 343 WSIFOperation operation = port.createOperation(method); 344 345 WSIFMessage inputMessage = operation.createInputMessage(); 346 inputMessage.setIntPart("choice",choice); 347 WSIFMessage outputMessage = operation.createOutputMessage(); 348 WSIFMessage faultMessage = operation.createFaultMessage(); 349 350 boolean operationSucceeded = false; 351 if (blocks == SYNC) { 352 operationSucceeded = 353 operation.executeRequestResponseOperation( 354 inputMessage, 355 outputMessage, 356 faultMessage); 357 358 } else if (blocks == ASYNC) { 359 WSIFMessage context = operation.getContext(); 360 context.setObjectPart( 361 WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 362 TestUtilities.getWsifProperty("wsif.async.replytoq2")); 363 operation.setContext(context); 364 365 WSIFCorrelationId id = 366 operation.executeRequestResponseAsync(inputMessage); 367 System.out.println( 368 "async operation done, correlation id=" 369 + id.getCorrelationId()); 370 371 Object jmsResponse = 372 TestUtilities.getJMSAsyncResponse( 373 id.getCorrelationId(), 374 TestUtilities.getWsifProperty("wsif.async.replytoq2")); 375 376 operationSucceeded = 377 operation.processAsyncResponse( 378 jmsResponse, 379 outputMessage, 380 faultMessage); 381 382 } else 383 assertTrue(false); 384 385 System.out.println( 386 "JmsFaultTest " 387 + method 388 + " " 389 + operationSucceeded 390 + " " 391 + (names == null)); 392 393 assertTrue( 394 "Bad boolean success value from executeRequestReponseOperation", 395 (operationSucceeded && !faultExpected) 396 || (!operationSucceeded && faultExpected)); 397 398 if (!operationSucceeded) { 399 Iterator it = faultMessage.getPartNames(); 400 int i = 0; 401 while (it.hasNext()) { 402 it.next(); 403 i++; 404 } 405 406 if (names == null) 407 names = new String [] {}; 408 if (parts == null) 409 parts = new Object [] {}; 410 411 assertTrue( 412 "Bad number of parts in the fault message expected=" 413 + names.length 414 + " got=" 415 + i, 416 i == names.length); 417 418 for (i = 0; i < names.length; i++) { 419 Object o = faultMessage.getObjectPart(names[i]); 420 421 assertTrue( 422 "Bad value for partName=" + names[i] + " " + o, 423 parts[i].equals(o)); 424 } 425 } 426 427 assertTrue(!exceptionExpected); 428 } catch (Exception e) { 429 System.err.println("JmsFaultTest(" + method + ") caught exception " + e); 430 if (!exceptionExpected || !(e instanceof WSIFException)) 431 e.printStackTrace(); 432 assertTrue(exceptionExpected && e instanceof WSIFException); 433 } 434 } 435 } | Popular Tags |