View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.example.loanbroker.bpm;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.client.MuleClient;
11  import org.mule.example.loanbroker.messages.Customer;
12  import org.mule.example.loanbroker.messages.CustomerQuoteRequest;
13  import org.mule.example.loanbroker.messages.LoanQuote;
14  import org.mule.example.loanbroker.tests.AbstractAsynchronousLoanBrokerTestCase;
15  import org.mule.transport.NullPayload;
16  
17  import static org.junit.Assert.assertFalse;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class JBpmFunctionalTestCase extends AbstractAsynchronousLoanBrokerTestCase
22  {
23  
24      public JBpmFunctionalTestCase()
25      {
26          super();
27          setDisposeContextPerClass(true);
28      }
29      
30      @Override
31      protected String getConfigResources()
32      {
33          return "mule-config.xml";
34      }
35  
36      @Override
37      protected int getDelay()
38      {
39          return 20000;
40      }
41  
42      @Override
43      protected int getNumberOfRequests()
44      {
45          return 100;
46      }
47  
48      @Override
49      public void testLotsOfLoanRequests() throws Exception
50      {
51          final MuleClient client = muleContext.getClient();
52          Customer c = new Customer("Ross Mason", 1234);
53          CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
54  
55          for (int i = 0; i < getNumberOfRequests(); i++)
56          {
57              client.dispatch("CustomerRequests", request, null);
58          }
59          
60          MuleMessage result;
61          for (int i = 0; i < getNumberOfRequests(); i++)
62          {
63              result = client.request("CustomerResponses", getDelay());
64              assertNotNull("Result is null", result);
65              assertFalse("Result is null", result.getPayload() instanceof NullPayload);
66              assertTrue("Result should be LoanQuote but is " + result.getPayload().getClass().getName(),
67                      result.getPayload() instanceof LoanQuote);
68              LoanQuote quote = (LoanQuote) result.getPayload();
69              assertTrue(quote.getInterestRate() > 0);
70              assertNotNull(quote.getBankName());
71          }
72      }
73  }