Пример #1
0
 public void run() {
   int i = 0;
   try {
     Thread.sleep(2000);
     MuleClient client = new MuleClient();
     MuleMessage result = null;
     for (i = 0; i < numberOfRequests; i++) {
       try {
         result = client.request("CustomerResponses", getDelay());
       } catch (MuleException e) {
         exListener.exceptionThrown(e);
         break;
       }
       // System.out.println("Received: " + i);
       assertNotNull("Result is null", result);
       assertFalse("Result is null", result.getPayload() instanceof NullPayload);
       assertTrue(
           "Result should be LoanQuote but is " + result.getPayload().getClass().getName(),
           result.getPayload() instanceof LoanQuote);
       LoanQuote quote = (LoanQuote) result.getPayload();
       assertTrue(quote.getInterestRate() > 0);
     }
   } catch (Throwable e) {
     // e.printStackTrace();
     System.out.println(StringMessageUtils.getBoilerPlate("Processed Messages=" + i));
     if (e instanceof Error) {
       // throw (Error)e;
       exListener.exceptionThrown(new Exception(e));
     } else {
       exListener.exceptionThrown((Exception) e);
     }
   } finally {
     latch.countDown();
   }
 }
Пример #2
0
  public void testSingleLoanRequest() throws Exception {
    MuleClient client = new MuleClient();
    Customer c = new Customer("Ross Mason", 1234);
    CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
    // Send asynchronous request
    client.dispatch("CustomerRequests", request, null);

    // Wait for asynchronous response
    MuleMessage result = client.request("CustomerResponses", getDelay());
    assertNotNull("Result is null", result);
    assertFalse("Result is null", result.getPayload() instanceof NullPayload);
    assertTrue(
        "Result should be LoanQuote but is " + result.getPayload().getClass().getName(),
        result.getPayload() instanceof LoanQuote);
    LoanQuote quote = (LoanQuote) result.getPayload();
    assertTrue(quote.getInterestRate() > 0);
  }