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.ExchangePattern;
20  import org.junit.Test;
21  import org.openehealth.ipf.platform.camel.core.AbstractRouteTest;
22  import org.openehealth.ipf.platform.camel.core.support.domain.Cat;
23  import org.openehealth.ipf.platform.camel.core.support.domain.Dog;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertTrue;
27  
28  
29  /**
30   * @author Martin Krasser
31   */
32  public class TransmogrifierRouteTest extends AbstractRouteTest {
33  
34      @Test
35      public void testTransmogrifier1() throws InterruptedException {
36          Cat cat = (Cat) producerTemplate.sendBody("direct:transmogrifier-test-1",
37                  ExchangePattern.InOut, new Dog("Willi"));
38          assertEquals(new Cat("Willi"), cat);
39      }
40  
41      @Test
42      public void testTransmogrifier2() throws InterruptedException {
43          Cat cat = (Cat) producerTemplate.sendBody("direct:transmogrifier-test-2",
44                  ExchangePattern.InOut, new Dog("Willi"));
45          assertEquals(new Cat("Willi eats mice"), cat);
46      }
47  
48      @Test
49      public void testTransmogrifier3() throws InterruptedException {
50          Cat cat = (Cat) producerTemplate.requestBodyAndHeader("direct:transmogrifier-test-3", "wrong", "foo",
51                  new Dog("Fritz"));
52          assertEquals(new Cat("Fritz likes fish"), cat);
53      }
54  
55      @Test
56      public void testTransmogrifier4() throws InterruptedException {
57          Exchange exchange = producerTemplate.request("direct:transmogrifier-test-4", exchange1 -> {
58              exchange1.getIn().setHeader("x", "y");
59              exchange1.getIn().setBody(new Dog("Willi"));
60          });
61          assertTrue(exchange.hasOut());
62          assertEquals("y", exchange.getOut().getHeader("x"));
63      }
64  
65  }