use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class EventTypeTest method testOnErrorHeaderForwarded.
@Test
public void testOnErrorHeaderForwarded() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("reactive-streams:numbers?forwardOnError=true").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
Subscriber<Integer> numbers = CamelReactiveStreams.get(context).streamSubscriber("numbers", Integer.class);
context.start();
RuntimeException ex = new RuntimeException("1");
Flowable.just(1).map(n -> {
if (n == 1) {
throw ex;
}
return n;
}).subscribe(numbers);
MockEndpoint endpoint = getMockEndpoint("mock:endpoint");
endpoint.expectedMessageCount(1);
endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onError");
endpoint.assertIsSatisfied();
Exchange exch = endpoint.getExchanges().get(0);
assertEquals(ex, exch.getIn().getBody());
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class AbstractPlatformTestSupport method testSubscriber.
@Test
public void testSubscriber() throws Exception {
int num = 20;
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("reactive-streams:integers").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);
List<Integer> elements = new LinkedList<>();
for (int i = 1; i <= num; i++) {
elements.add(i);
}
changeSign(elements, camel.streamSubscriber("integers", Integer.class));
context.start();
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(num);
mock.assertIsSatisfied();
for (Exchange ex : mock.getExchanges()) {
Integer number = ex.getIn().getBody(Integer.class);
assertNotNull(number);
assertTrue(number < 0);
}
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CamelPublisherConversionVerificationTest method createPublisher.
@Override
public Publisher<Long> createPublisher(long l) {
CamelContext context = new DefaultCamelContext();
RouteBuilder builder = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:tick?delay=500&period=50&repeatCount=" + l).setBody().simple("random(1000)").to("reactive-streams:prod");
}
};
Publisher<Long> pub = CamelReactiveStreams.get(context).fromStream("prod", Long.class);
try {
builder.addRoutesToCamelContext(context);
context.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
return pub;
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CamelPublisherVerificationTest method createPublisher.
@Override
public Publisher<Exchange> createPublisher(long l) {
CamelContext context = new DefaultCamelContext();
RouteBuilder builder = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:tick?delay=500&period=50&repeatCount=" + l).to("reactive-streams:prod");
}
};
Publisher<Exchange> pub = CamelReactiveStreams.get(context).fromStream("prod");
try {
builder.addRoutesToCamelContext(context);
context.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
return pub;
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class DirectClientAPITest method testDirectCallFromCamel.
@Test
public void testDirectCallFromCamel() 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", p -> Flowable.fromPublisher(p).map(exchange -> {
int val = exchange.getIn().getBody(Integer.class);
exchange.getOut().setBody(-val);
return exchange;
}));
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);
}
}
Aggregations