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.adapter;
17  
18  import org.apache.camel.Exchange;
19  import org.apache.camel.impl.DefaultCamelContext;
20  import org.apache.camel.impl.DefaultExchange;
21  import org.apache.camel.processor.aggregate.AggregationStrategy;
22  import org.junit.Test;
23  import org.openehealth.ipf.platform.camel.core.support.transform.min.TestAggregator;
24  
25  import static org.apache.camel.builder.Builder.outBody;
26  import static org.junit.Assert.assertEquals;
27  
28  /**
29   * @author Martin Krasser
30   */
31  public class AggregatorAdapterTest {
32  
33      private AggregationStrategy strategy;
34  
35      @Test
36      public void testAggregateDefault() {
37          strategy = new AggregatorAdapter(new TestAggregator());
38          Exchange a = exchangeWithInBody("a");
39          Exchange b = exchangeWithInBody("b");
40          strategy.aggregate(a, b);
41          assertEquals("a:b", a.getIn().getBody());
42      }
43      
44      @Test
45      public void testAggregateCustom() {
46          strategy = new AggregatorAdapter(new TestAggregator()).aggregationInput(outBody());
47          Exchange a = exchangeWithInBody("a");
48          Exchange b = exchangeWithOutBody("b");
49          strategy.aggregate(a, b);
50          assertEquals("a:b", a.getIn().getBody());
51      }
52      
53      private static Exchange exchangeWithInBody(Object body) {
54          Exchange exchange = exchange();
55          exchange.getIn().setBody(body);
56          return exchange;
57      }
58      
59      private static Exchange exchangeWithOutBody(Object body) {
60          Exchange exchange = exchange();
61          exchange.getOut().setBody(body);
62          return exchange;
63      }
64      
65      private static Exchange exchange() {
66          return new DefaultExchange(new DefaultCamelContext());
67      }
68  }