Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 12th, 2012  |  syntax: Java  |  size: 2.11 KB  |  views: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import org.apache.camel.*;
  2. import org.apache.camel.builder.AdviceWithRouteBuilder;
  3. import org.apache.camel.builder.NotifyBuilder;
  4. import org.apache.camel.builder.RouteBuilder;
  5. import org.apache.camel.builder.ValueBuilder;
  6. import org.apache.camel.component.mock.MockEndpoint;
  7. import org.junit.Test;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.test.annotation.DirtiesContext;
  12. import org.springframework.test.context.ContextConfiguration;
  13. import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
  14.  
  15. import java.util.List;
  16.  
  17. @ContextConfiguration(locations = "classpath:applicationContext.xml")
  18. public class JeroenTest extends AbstractTransactionalJUnit4SpringContextTests {
  19.     private static final Logger log = LoggerFactory.getLogger(JeroenTest.class);
  20.  
  21.     @Produce(uri = "direct:start")
  22.     protected ProducerTemplate inputTemplate;
  23.  
  24.     @EndpointInject(uri = "mock:output")
  25.     protected MockEndpoint resultEndpoint;
  26.  
  27.     @Autowired
  28.     private CamelContext context;
  29.  
  30.     @DirtiesContext
  31.     @Test
  32.     public void test() throws Exception {
  33.  
  34.         RouteBuilder rb = new RouteBuilder() {
  35.             @Override
  36.             public void configure() throws Exception {
  37.                 from("direct:start")
  38.                         .split().tokenizeXML("order","orders").streaming().shareUnitOfWork()
  39.                         .to("mock:output")
  40.                         .end();
  41.             }
  42.         };
  43.  
  44.         context.addRoutes(rb);
  45.  
  46.         inputTemplate.sendBody("<foo:orders xmlns:foo=\"http://foo.com\">\n" +
  47.                 "  <foo:order id=\"1\">Camel in Action</foo:order>\n" +
  48.                 "  <foo:order id=\"1\">ActiveMQ in Action</foo:order>\n" +
  49.                 "  <foo:order id=\"1\">DSL in Action</foo:order>\n" +
  50.                 "</foo:orders>");
  51.  
  52.         List<Exchange> list = resultEndpoint.getExchanges();
  53.  
  54.         for (Exchange exchange : list) {
  55.             log.debug("splitted xml: {}", exchange.getIn().getBody(String.class));
  56.         }
  57.     }
  58.  
  59. }
clone this paste RAW Paste Data