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;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.example.loanbroker.message.CustomerQuoteRequest;
11  import org.mule.example.loanbroker.model.Customer;
12  import org.mule.example.loanbroker.model.LoanQuote;
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.transformer.simple.ByteArrayToObject;
16  import org.mule.transport.NullPayload;
17  import org.mule.transport.http.HttpConstants;
18  
19  import java.util.Map;
20  
21  import org.apache.commons.collections.map.SingletonMap;
22  import org.junit.Ignore;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertFalse;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertNull;
28  import static org.junit.Assert.assertTrue;
29  
30  @Ignore("MULE-7122")
31  public class LoanBrokerSyncTestCase extends FunctionalTestCase
32  {
33      
34      @Override
35      protected String getConfigResources()
36      {
37          return "mule-config.xml";
38      }
39  
40      @Test
41      public void testLoanBrokerMuleClient() throws Exception
42      {
43          muleContext.getRegistry().registerObject("streamToObjectTransformer", new ByteArrayToObject());
44          MuleClient client = new MuleClient(muleContext);
45          Customer c = new Customer("Ross Mason", 1234);
46          CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
47          MuleMessage result = client.send("http://localhost:11080?responseTransformers=streamToObjectTransformer", request, null);
48          assertNotNull("Result is null", result);
49          assertFalse("Result is null", result.getPayload() instanceof NullPayload);
50          assertTrue("Result should be LoanQuote but is " + result.getPayload().getClass().getName(), 
51                      result.getPayload(Object.class) instanceof LoanQuote);
52          LoanQuote quote = (LoanQuote)result.getPayload();
53          assertTrue(quote.getInterestRate() > 0);
54      }
55  
56      @Test
57      public void testLoanBrokerHttpUrlWithDefaults() throws Exception
58      {
59          muleContext.getRegistry().registerObject("streamToObjectTransformer", new ByteArrayToObject());
60          MuleClient client = new MuleClient(muleContext);
61          // there are some default built into the http url service (note a different port)
62          @SuppressWarnings("unchecked")
63          Map<String, String> props = new SingletonMap("http.method", HttpConstants.METHOD_GET);
64          MuleMessage result = client.send("http://localhost:11081", null, props);
65          assertNotNull("Result is null", result);
66          assertFalse("Result is null", result.getPayload() instanceof NullPayload);
67          assertNull(result.getExceptionPayload());
68  
69          assertTrue("Unexpected response string", result.getPayloadAsString().matches("Bank #\\d, rate: \\d\\.(\\d)*$"));
70      }
71      
72  }
73  
74