1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| public class SplitTokenizeTest extends CamelTestSupport {
@Test public void testSplitTokenizerA() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); mock.expectedBodiesReceived("Claus", "James", "Willem");
template.sendBody("direct:a", "Claus,James,Willem");
assertMockEndpointsSatisfied(); }
@Test public void testSplitTokenizerB() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); mock.expectedBodiesReceived("Claus", "James", "Willem");
template.sendBodyAndHeader("direct:b", "Hello World", "myHeader", "Claus,James,Willem");
assertMockEndpointsSatisfied(); }
@Test public void testSplitTokenizerC() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); mock.expectedBodiesReceived("Claus", "James", "Willem");
template.sendBody("direct:c", "Claus James Willem");
assertMockEndpointsSatisfied(); }
@Test public void testSplitTokenizerD() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); mock.expectedBodiesReceived("[Claus]", "[James]", "[Willem]");
template.sendBody("direct:d", "[Claus][James][Willem]");
assertMockEndpointsSatisfied(); }
@Test public void testSplitTokenizerE() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); mock.expectedBodiesReceived("<person>Claus</person>", "<person>James</person>", "<person>Willem</person>");
String xml = "<persons><person>Claus</person><person>James</person><person>Willem</person></persons>"; template.sendBody("direct:e", xml);
assertMockEndpointsSatisfied(); }
@Test public void testSplitTokenizerEWithSlash() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); String xml = "<persons><person attr='/' /></persons>"; mock.expectedBodiesReceived("<person attr='/' />"); template.sendBody("direct:e", xml); mock.assertIsSatisfied(); assertMockEndpointsSatisfied(); }
@Test public void testSplitTokenizerF() throws Exception { MockEndpoint mock = getMockEndpoint("mock:split"); mock.expectedBodiesReceived("<person name=\"Claus\"/>", "<person>James</person>", "<person>Willem</person>");
String xml = "<persons><person/><person name=\"Claus\"/><person>James</person><person>Willem</person></persons>"; template.sendBody("direct:f", xml);
assertMockEndpointsSatisfied(); }
@Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override public void configure() {
from("direct:a") .split().tokenize(",") .to("mock:split");
from("direct:b") .split().tokenize(",", "myHeader") .to("mock:split");
from("direct:c") .split().tokenize("(\\W+)\\s*", null, true) .to("mock:split");
from("direct:d") .split().tokenizePair("[", "]", true) .to("mock:split");
from("direct:e") .split().tokenizeXML("person") .to("mock:split");
from("direct:f") .split().xpath("//person") .filter().simple("${body}") .to("mock:split");
} }; } }
|