View Javadoc

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