View Javadoc
1   /*
2    * Copyright 2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Martin Krasser
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  }