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.test.components;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.message.DefaultExceptionPayload;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import java.util.HashMap;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertTrue;
20  import static org.junit.Assert.fail;
21  
22  /**
23   * Test an entry-point resolver used for multiple classes
24   */
25  public class EntryPointResolverCacheTestCase extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "org/mule/test/components/entry-point-resolver-cache.xml";
32      }
33  
34      @Test
35      public void testCache() throws Exception
36      {
37          MuleClient clt = new MuleClient(muleContext);
38  
39          MuleMessage response = null;
40          HashMap<String, Object> propertyMap = new HashMap<String, Object>();
41          propertyMap.put("method", "retrieveReferenceData");
42  
43          response = clt.send("refOneInbound", "a request", propertyMap);
44          Object payload = response.getPayload();
45  
46          assertTrue("should be a string", payload instanceof String );
47          assertEquals("ServiceOne", payload);
48  
49          response = clt.send("refTwoInbound", "another request", propertyMap);
50          payload = response.getPayload();
51          if((payload == null) || (response.getExceptionPayload() != null))
52          {
53              DefaultExceptionPayload exPld = (DefaultExceptionPayload)response.getExceptionPayload();
54              if(exPld.getException() != null)
55              {
56                  fail(exPld.getException().getMessage());
57              }
58              else
59              {
60                  fail(exPld.toString());
61              }
62          }
63          assertTrue("should be a string", payload instanceof String );
64          assertEquals("ServiceTwo", payload);
65  
66      }
67  
68      public interface ReferenceDataService
69      {
70          String retrieveReferenceData(String refKey);
71      }
72  
73      public static class RefDataServiceOne implements ReferenceDataService
74      {
75          public String retrieveReferenceData(String refKey)
76          {
77              return "ServiceOne";
78          }
79      }
80  
81      public static class RefDataServiceTwo implements ReferenceDataService
82      {
83          public String retrieveReferenceData(String refKey)
84          {
85              return "ServiceTwo";
86          }
87  
88      }
89  }