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