Search in sources :

Example 6 with UnwrapStreamProcessor

use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.

the class BeanCallTest method beanCallStdReturnTypeTest.

@Test
public void beanCallStdReturnTypeTest() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(Throwable.class).to("direct:handle").handled(true);
            from("direct:num").bean(BeanCallTest.this, "processBodyStd").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();
    assertEquals("Hello", body);
}
Also used : Exchange(org.apache.camel.Exchange) UnwrapStreamProcessor(org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 7 with UnwrapStreamProcessor

use of org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor in project camel by apache.

the class BeanCallTest method beanCallTwoElementsTest.

@Test
public void beanCallTwoElementsTest() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(Throwable.class).to("direct:handle").handled(true);
            from("direct:num").bean(BeanCallTest.this, "processBodyTwoItems").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();
    assertTrue(body instanceof Collection);
    @SuppressWarnings("unchecked") List<String> data = new LinkedList<>((Collection<String>) body);
    assertListSize(data, 2);
    assertEquals("HelloBody 1", data.get(0));
    assertEquals("HelloBody 1", data.get(1));
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) LinkedList(java.util.LinkedList) Exchange(org.apache.camel.Exchange) UnwrapStreamProcessor(org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 UnwrapStreamProcessor (org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor)7 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)6 Test (org.junit.Test)6 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1