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.apache.camel.RuntimeCamelException;
20  import org.junit.Test;
21  import org.springframework.test.context.ContextConfiguration;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNull;
25  
26  /**
27   * @author Martin Krasser
28   */
29  @ContextConfiguration(locations = { "/context-core-extend-validator.xml" })
30  public class ValidatorExtensionTest extends AbstractExtensionTest {
31  
32      @Test
33      public void testBooleanClosureOneParamSuccess() throws InterruptedException {
34          mockOutput.expectedBodiesReceived("blah");
35          Exchange result = producerTemplate.request("direct:input1", exchange -> exchange.getIn().setBody("blah"));
36          assertNull(result.getException());
37          mockOutput.assertIsSatisfied();
38      }
39      
40      @Test
41      public void testBooleanClosureOneParamInOutFailure() throws InterruptedException {
42          mockOutput.expectedMessageCount(0);
43          Exchange result = producerTemplate.request("direct:input1", exchange -> exchange.getIn().setBody("blub"));
44          assertEquals("validation closure returned false", result.getException().getMessage());
45          mockOutput.assertIsSatisfied();
46      }
47      
48      @Test
49      public void testExceptionClosureOneParamInOutFailure() throws InterruptedException {
50          mockOutput.expectedMessageCount(0);
51          Exchange result = producerTemplate.request("direct:input2", exchange -> exchange.getIn().setBody("blub"));
52          assertEquals("juhu", result.getException().getMessage());
53          mockOutput.assertIsSatisfied();
54      }
55      
56      @Test
57      public void testBooleanClosureOneParamInOnlySuccess() throws InterruptedException {
58          mockOutput.expectedBodiesReceived("blah");
59          producerTemplate.sendBody("direct:input1", "blah");
60          mockOutput.assertIsSatisfied();
61      }
62      
63      @Test(expected=RuntimeCamelException.class)
64      public void testBooleanClosureOneParamInOnlyFailure() throws InterruptedException {
65          producerTemplate.sendBody("direct:input1", "blub");
66      }
67      
68      @Test
69      public void testClosureTwoParamsDefaultProfile() throws InterruptedException {
70          mockOutput.expectedBodiesReceived("blah");
71          producerTemplate.sendBody("direct:input3", "blah");
72          mockOutput.assertIsSatisfied();
73      }
74      
75      @Test
76      public void testClosureTwoParamsCustomProfile() throws InterruptedException {
77          mockOutput.expectedBodiesReceived("blah");
78          producerTemplate.sendBody("direct:input4", "blah");
79          mockOutput.assertIsSatisfied();
80      }
81      
82      @Test
83      public void testClosureTwoParamsCustomProfileAndInput() throws InterruptedException {
84          mockOutput.expectedBodiesReceived("abcd");
85          producerTemplate.sendBody("direct:input5", "abcd");
86          mockOutput.assertIsSatisfied();
87      }
88      
89      @Test
90      public void testValidatorBean() throws InterruptedException {
91          mockOutput.expectedBodiesReceived("bean");
92          producerTemplate.sendBody("direct:input6", "bean");
93          mockOutput.assertIsSatisfied();
94      }
95      
96      @Test
97      public void testValidatorObject() throws InterruptedException {
98          mockOutput.expectedBodiesReceived("object");
99          producerTemplate.sendBody("direct:input7", "object");
100         mockOutput.assertIsSatisfied();
101     }
102     
103     @Test
104     public void testValidatorProfileExpression() throws InterruptedException {
105         mockOutput.expectedBodiesReceived("blah");
106         producerTemplate.sendBodyAndHeader("direct:input8", "blah", "profile", "derived");
107         mockOutput.assertIsSatisfied();
108     }
109     
110 }