use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class DirectClientAPITest method testDirectCallFromCamelWithConversion.
@Test
public void testDirectCallFromCamelWithConversion() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:source").to("direct:stream").setBody().simple("after stream: ${body}").to("mock:dest");
}
}.addRoutesToCamelContext(context);
context.start();
camel.process("direct:stream", Integer.class, p -> Flowable.fromPublisher(p).map(i -> -i));
for (int i = 1; i <= 3; i++) {
template.sendBody("direct:source", i);
}
MockEndpoint mock = getMockEndpoint("mock:dest");
mock.expectedMessageCount(3);
mock.assertIsSatisfied();
int id = 1;
for (Exchange ex : mock.getExchanges()) {
String content = ex.getIn().getBody(String.class);
assertEquals("after stream: " + (-id++), content);
}
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class EventTypeTest method testOnCompleteHeaderForwarded.
@Test
public void testOnCompleteHeaderForwarded() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("reactive-streams:numbers?forwardOnComplete=true").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
Subscriber<Integer> numbers = CamelReactiveStreams.get(context).streamSubscriber("numbers", Integer.class);
context.start();
Flowable.<Integer>empty().subscribe(numbers);
MockEndpoint endpoint = getMockEndpoint("mock:endpoint");
endpoint.expectedMessageCount(1);
endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onComplete");
endpoint.expectedBodiesReceived(new Object[] { null });
endpoint.assertIsSatisfied();
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BeanCallTest method beanCallTest.
@Test
public void beanCallTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processBody").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBody("direct:num", 1);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
assertEquals("HelloBody 1", exchange.getIn().getBody());
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BeanCallTest method beanCallWithErrorTest.
@Test
public void beanCallWithErrorTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processBodyWrongType").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBody("direct:num", 1);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
assertEquals("ERR", exchange.getIn().getBody());
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BeanCallTest method beanCallEmptyPublisherTest.
@Test
public void beanCallEmptyPublisherTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processBodyEmpty").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBody("direct:num", 1);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
Object body = exchange.getIn().getBody();
// unchanged
assertEquals(new Integer(1), body);
}
Aggregations