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-exception.xml"})
34 public class ExceptionHandlingTest extends TestSupport {
35
36 @EndpointInject(uri="mock:success")
37 private MockEndpoint success;
38
39 @EndpointInject(uri="mock:error1")
40 private MockEndpoint error1;
41
42 @EndpointInject(uri="mock:error2")
43 private MockEndpoint error2;
44
45 @EndpointInject(uri="mock:error3")
46 private MockEndpoint error3;
47
48 @After
49 public void tearDown() throws Exception {
50 success.reset();
51 error1.reset();
52 error2.reset();
53 error3.reset();
54 }
55
56 @Test
57 public void testError1() throws Exception {
58 error1.expectedMessageCount(1);
59 error2.expectedMessageCount(0);
60 error3.expectedMessageCount(0);
61 success.expectedMessageCount(0);
62 try {
63 producerTemplate.sendBody("direct:input", "blah");
64 fail("failure not reported");
65 } catch (RuntimeCamelException e) {
66 assertEquals(Exception1.class, e.getCause().getClass());
67 }
68 error1.assertIsSatisfied();
69 error2.assertIsSatisfied();
70 error3.assertIsSatisfied();
71 success.assertIsSatisfied();
72 }
73
74 @Test
75 public void testError2() throws Exception {
76 error1.expectedMessageCount(0);
77 error2.expectedMessageCount(1);
78 error3.expectedMessageCount(0);
79 success.expectedMessageCount(0);
80 try {
81 producerTemplate.sendBody("direct:input", "blub");
82 } catch (RuntimeCamelException e) {
83 assertEquals(Exception2.class, e.getCause().getClass());
84 }
85 error1.assertIsSatisfied();
86 error2.assertIsSatisfied();
87 error3.assertIsSatisfied();
88 success.assertIsSatisfied();
89 }
90
91 @Test
92 public void testError3() throws Exception {
93 error1.expectedMessageCount(0);
94 error2.expectedMessageCount(0);
95 error3.expectedMessageCount(1);
96 success.expectedMessageCount(0);
97 try {
98 producerTemplate.sendBody("direct:input", "oink");
99 } catch (RuntimeCamelException e) {
100 assertEquals(Exception3.class, e.getCause().getClass());
101 }
102 error1.assertIsSatisfied();
103 error2.assertIsSatisfied();
104 error3.assertIsSatisfied();
105 success.assertIsSatisfied();
106 }
107
108 @Test
109 public void testSuccess() throws Exception {
110 error1.expectedMessageCount(0);
111 error2.expectedMessageCount(0);
112 error3.expectedMessageCount(0);
113 success.expectedMessageCount(1);
114 producerTemplate.sendBody("direct:input", "clean");
115 error1.assertIsSatisfied();
116 error2.assertIsSatisfied();
117 error3.assertIsSatisfied();
118 success.assertIsSatisfied();
119 }
120
121 }