1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.camel.transaction;
17
18 import org.apache.camel.EndpointInject;
19 import org.apache.camel.ExchangePattern;
20 import org.apache.camel.component.mock.MockEndpoint;
21 import org.junit.After;
22 import org.junit.Ignore;
23 import org.junit.Test;
24 import org.openehealth.ipf.platform.camel.core.camel.TestSupport;
25 import org.springframework.test.context.ContextConfiguration;
26
27
28
29
30
31 @ContextConfiguration(locations = {
32 "/context-camel-transaction.xml",
33 "/context-camel-transaction-process.xml",
34 "/context-camel-transaction-delivery.xml"
35 })
36 public class TransactionalMessagingTest extends TestSupport {
37
38 private static final long TIMEOUT = 2000L;
39
40 @EndpointInject(uri="mock:txm-mock")
41 private MockEndpoint txmMock;
42
43 @EndpointInject(uri="mock:txm-error")
44 private MockEndpoint txmError;
45
46 @EndpointInject(uri="mock:error")
47 private MockEndpoint errorMock;
48
49 @After
50 public void tearDown() throws Exception {
51 txmMock.reset();
52 txmError.reset();
53 errorMock.reset();
54 }
55
56 @Test
57 public void testRollbackDelivery() throws InterruptedException {
58 txmMock.expectedBodiesReceived("blub");
59 txmError.expectedBodiesReceived("blub", "blub");
60 sendBodies("amqProcess:queue:txm-input", ExchangePattern.InOnly, "blub", 1);
61 txmError.assertIsSatisfied();
62 txmMock.assertIsSatisfied();
63 }
64
65 @Test @Ignore
66 public void testRollbackProcess() throws InterruptedException {
67 txmMock.expectedMessageCount(0);
68 txmError.expectedBodiesReceived("blah");
69 sendBodies("amqProcess:queue:txm-input", ExchangePattern.InOnly, "blah", 1);
70 txmError.assertIsSatisfied();
71 Thread.sleep(TIMEOUT);
72 txmMock.assertIsSatisfied();
73 }
74
75 @Test
76 public void testCommit() throws InterruptedException {
77 txmError.expectedMessageCount(0);
78 txmMock.expectedBodiesReceived("clean", "clean");
79 sendBodies("amqProcess:queue:txm-input", ExchangePattern.InOnly, "clean", 1);
80 txmMock.assertIsSatisfied();
81 Thread.sleep(TIMEOUT);
82 txmError.assertIsSatisfied();
83 }
84
85 }