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.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   * @author Martin Krasser
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  }