1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.extend;
17
18 import org.apache.camel.Exchange;
19 import org.junit.Test;
20 import org.springframework.test.context.ContextConfiguration;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25
26
27
28 @ContextConfiguration(locations = { "/context-core-extend-validation.xml" })
29 public class ValidationExtensionTest extends AbstractExtensionTest {
30
31 @Test
32 public void testResponderObjectSuccess() throws InterruptedException {
33 testSuccess("direct:input1");
34 }
35
36 @Test
37 public void testResponderObjectFault() throws InterruptedException {
38 testFault("direct:input2");
39 }
40
41 @Test
42 public void testResponderObjectError() throws InterruptedException {
43 testError("direct:input3");
44 }
45
46 @Test
47 public void testResponderEndpointSuccess() throws InterruptedException {
48 testSuccess("direct:input4");
49 }
50
51 @Test
52 public void testResponderEndpointFault() throws InterruptedException {
53 testFault("direct:input5");
54 }
55
56 @Test
57 public void Endpoint() throws InterruptedException {
58 testError("direct:input6");
59 }
60
61 @Test
62 public void testResponderClosureSuccess() throws InterruptedException {
63 testSuccess("direct:input7");
64 }
65
66 @Test
67 public void testResponderClosureFault() throws InterruptedException {
68 testFault("direct:input8");
69 }
70
71 @Test
72 public void testResponderClosureError() throws InterruptedException {
73 testError("direct:input9");
74 }
75
76 public void testSuccess(String endpoint) throws InterruptedException {
77 mockOutput.expectedBodiesReceived("blah");
78 Exchange result = producerTemplate.request(endpoint, exchange -> exchange.getIn().setBody("blah"));
79 assertEquals("result", result.getOut().getBody());
80 mockOutput.assertIsSatisfied();
81 }
82
83 public void testFault(String endpoint) throws InterruptedException {
84 mockOutput.expectedMessageCount(0);
85 Exchange result = producerTemplate.request(endpoint, exchange -> exchange.getIn().setBody("blah"));
86 assertEquals("failed", result.getOut().getBody());
87 assertTrue(result.getOut().isFault());
88 mockOutput.assertIsSatisfied();
89 }
90
91 public void testError(String endpoint) throws InterruptedException {
92 mockOutput.expectedMessageCount(0);
93 Exchange result = producerTemplate.request(endpoint, exchange -> exchange.getIn().setBody("blah"));
94 assertEquals("failed", result.getException().getMessage());
95 mockOutput.assertIsSatisfied();
96 }
97
98
99 }