1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.camel.exception;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.fail;
20
21 import org.apache.camel.EndpointInject;
22 import org.apache.camel.RuntimeCamelException;
23 import org.apache.camel.component.mock.MockEndpoint;
24 import org.junit.After;
25 import org.junit.Test;
26 import org.openehealth.ipf.platform.camel.core.camel.TestSupport;
27 import org.springframework.test.context.ContextConfiguration;
28
29
30
31
32
33 @ContextConfiguration(locations = {"/context-camel-error.xml"})
34 public class ErrorHandlingTest extends TestSupport {
35
36 @EndpointInject(uri="mock:output")
37 private MockEndpoint output;
38
39 @EndpointInject(uri="mock:inter")
40 private MockEndpoint inter;
41
42 @EndpointInject(uri="mock:check")
43 private MockEndpoint check;
44
45 @EndpointInject(uri="mock:error")
46 private MockEndpoint error;
47
48 @After
49 public void tearDown() throws Exception {
50 output.reset();
51 inter.reset();
52 check.reset();
53 error.reset();
54 }
55
56 @Test
57 public void testGlobal() throws Exception {
58 output.expectedMessageCount(0);
59 inter.expectedMessageCount(1);
60 error.expectedMessageCount(0);
61 try {
62 producerTemplate.sendBody("direct:input-1", "blah");
63 fail("failure not reported");
64 } catch (RuntimeCamelException e) {
65 assertEquals("message rejected", e.getCause().getMessage());
66 }
67 output.assertIsSatisfied();
68 inter.assertIsSatisfied();
69 error.assertIsSatisfied();
70 }
71
72 @Test
73 public void testLocal() throws Exception {
74 output.expectedMessageCount(0);
75 inter.expectedMessageCount(1);
76 check.expectedMessageCount(3);
77 error.expectedMessageCount(1);
78 try {
79 producerTemplate.sendBody("direct:input-2", "blah");
80 fail("failure not reported");
81 } catch (RuntimeCamelException e) {
82 assertEquals("message rejected", e.getCause().getMessage());
83 }
84 output.assertIsSatisfied();
85 inter.assertIsSatisfied();
86 check.assertIsSatisfied();
87 error.assertIsSatisfied();
88 }
89
90 }