1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.components;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.message.DefaultExceptionPayload;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.AbstractServiceAndFlowTestCase;
17
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.HashMap;
21
22 import org.junit.Test;
23 import org.junit.runners.Parameterized.Parameters;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
29
30
31
32 public class EntryPointResolverCacheTestCase extends AbstractServiceAndFlowTestCase
33 {
34 @Parameters
35 public static Collection<Object[]> parameters()
36 {
37 return Arrays.asList(new Object[][]{
38 {ConfigVariant.SERVICE, "org/mule/test/components/entry-point-resolver-cache-service.xml"},
39 {ConfigVariant.FLOW, "org/mule/test/components/entry-point-resolver-cache-flow.xml"}});
40 }
41
42 public EntryPointResolverCacheTestCase(ConfigVariant variant, String configResources)
43 {
44 super(variant, configResources);
45 }
46
47 @Test
48 public void testCache() throws Exception
49 {
50 MuleClient clt = new MuleClient(muleContext);
51
52 MuleMessage response = null;
53 HashMap<String, Object> propertyMap = new HashMap<String, Object>();
54 propertyMap.put("method", "retrieveReferenceData");
55
56 response = clt.send("refOneInbound", "a request", propertyMap);
57 Object payload = response.getPayload();
58
59 assertTrue("should be a string", payload instanceof String);
60 assertEquals("ServiceOne", payload);
61
62 response = clt.send("refTwoInbound", "another request", propertyMap);
63 payload = response.getPayload();
64 if ((payload == null) || (response.getExceptionPayload() != null))
65 {
66 DefaultExceptionPayload exPld = (DefaultExceptionPayload) response.getExceptionPayload();
67 if (exPld.getException() != null)
68 {
69 fail(exPld.getException().getMessage());
70 }
71 else
72 {
73 fail(exPld.toString());
74 }
75 }
76 assertTrue("should be a string", payload instanceof String);
77 assertEquals("ServiceTwo", payload);
78
79 }
80
81 public interface ReferenceDataService
82 {
83 String retrieveReferenceData(String refKey);
84 }
85
86 public static class RefDataServiceOne implements ReferenceDataService
87 {
88 @Override
89 public String retrieveReferenceData(String refKey)
90 {
91 return "ServiceOne";
92 }
93 }
94
95 public static class RefDataServiceTwo implements ReferenceDataService
96 {
97 @Override
98 public String retrieveReferenceData(String refKey)
99 {
100 return "ServiceTwo";
101 }
102 }
103 }