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.extend;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNull;
20  
21  import org.apache.camel.Exchange;
22  import org.junit.Test;
23  import org.springframework.test.context.ContextConfiguration;
24  
25  /**
26   * @author Martin Krasser
27   */
28  @ContextConfiguration(locations = { "/context-core-extend-expressionclause.xml" })
29  public class ExpressionClauseExtensionTest extends AbstractExtensionTest {
30  
31      @Test
32      public void testExceptionObject() throws InterruptedException {
33          mockOutput.expectedMessageCount(1);
34          Exchange result = producerTemplate.request("direct:input1", exchange -> {
35              exchange.getIn().setBody("blah");
36          });
37          mockOutput.assertIsSatisfied();
38          Exchange received = mockOutput.getExchanges().get(0);
39          Exception exception = (Exception)received.getIn().getHeader("foo");
40          assertEquals("message rejected", result.getException().getMessage());
41          assertEquals("message rejected", exception.getMessage());
42          assertNull(received.getException());
43      }
44      
45      @Test
46      public void testExceptionMessage() throws InterruptedException {
47          mockOutput.expectedMessageCount(1);
48          Exchange result = producerTemplate.request("direct:input2", exchange -> exchange.getIn().setBody("blah"));
49          mockOutput.assertIsSatisfied();
50          Exchange received = mockOutput.getExchanges().get(0);
51          assertEquals("message rejected", result.getException().getMessage());
52          assertEquals("message rejected", result.getOut().getBody());
53          assertNull(received.getException());
54      }
55      
56  }