1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.exceptions;
12
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
15
16 import org.mule.api.MuleEvent;
17 import org.mule.api.MuleException;
18 import org.mule.api.client.MuleClient;
19 import org.mule.api.construct.FlowConstruct;
20 import org.mule.exception.AbstractMessagingExceptionStrategy;
21 import org.mule.tck.junit4.FunctionalTestCase;
22
23 import org.junit.Test;
24
25
26
27
28
29
30 public class ExceptionPropagationMule5737TestCase extends FunctionalTestCase
31 {
32
33 @Override
34 protected String getConfigResources()
35 {
36 return "org/mule/test/integration/exceptions/exception-propagation-mule-5737-config.xml";
37 }
38
39 @Test
40 public void testVMRequestResponseEndpointExceptionPropagation() throws MuleException
41 {
42 MuleClient client = muleContext.getClient();
43 client.send("vm://flow-in", "", null);
44 }
45
46 @Test
47 public void testFlowWithChildFlowExceptionPropagation() throws MuleException
48 {
49 MuleClient client = muleContext.getClient();
50 FlowConstruct flow = muleContext.getRegistry().lookupFlowConstruct("flowWithChildFlow");
51 FlowConstruct childFlow = muleContext.getRegistry().lookupFlowConstruct("childFlow");
52 SensingExceptionStrategy parentES = (SensingExceptionStrategy) flow.getExceptionListener();
53 SensingExceptionStrategy childFlowES = (SensingExceptionStrategy) childFlow.getExceptionListener();
54
55 client.send("vm://flowWithChildFlow-in", "", null);
56
57 assertFalse(parentES.caught);
58 assertTrue(childFlowES.caught);
59
60 }
61
62 @Test
63 public void testFlowWithSubFlowExceptionPropagation() throws MuleException
64 {
65 MuleClient client = muleContext.getClient();
66 SensingExceptionStrategy parentES = (SensingExceptionStrategy) muleContext.getRegistry()
67 .lookupFlowConstruct("flowWithSubFlow")
68 .getExceptionListener();
69
70 client.send("vm://flowWithSubFlow-in", "", null);
71
72 assertTrue(parentES.caught);
73 }
74
75 @Test
76 public void testFlowWithChildServiceExceptionPropagation() throws MuleException
77 {
78 MuleClient client = muleContext.getClient();
79 SensingExceptionStrategy parentES = (SensingExceptionStrategy) muleContext.getRegistry()
80 .lookupFlowConstruct("flowWithChildService")
81 .getExceptionListener();
82 SensingExceptionStrategy childServiceES = (SensingExceptionStrategy) muleContext.getRegistry()
83 .lookupFlowConstruct("childService")
84 .getExceptionListener();
85
86 client.send("vm://flowWithChildService-in", "", null);
87
88 assertFalse(parentES.caught);
89 assertTrue(childServiceES.caught);
90 }
91
92 public static class SensingExceptionStrategy extends AbstractMessagingExceptionStrategy
93 {
94
95 public SensingExceptionStrategy()
96 {
97 super(null);
98 }
99
100 boolean caught;
101
102 @Override
103 public MuleEvent handleException(Exception e, MuleEvent event)
104 {
105 caught = true;
106 return super.handleException(e, event);
107 }
108
109 }
110
111 }