I can't understand why my tests don't work. I try intercept and skip sending
to endpoint which is bean reference and nothing happens. I'm using version
2.16.2.

test-camel.xml

<bean id="eb" class="com.rencap.emf.bpipe.EndpointBean"/>    
<camel:camelContext xmlns="http://camel.apache.org/schema/spring";>  
    <camel:endpoint id="requestEP" uri="direct:request"/>
    <endpoint id="beanEP" uri="bean:eb?method=processMessage" />
    <camel:route id="testRoute">
        <camel:from ref="requestEP"/>
        <camel:to ref="sendEP" />
    </camel:route>
</camel:camelContext>
EndpointBean.java

package com.rencap.emf.bpipe;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EndpointBean {
    private static Logger LOG = LoggerFactory.getLogger(EndpointBean.class);

    public void processMessage( String msg ){
        LOG.info("Processing message: {} ",msg);
    }
}
Unit test:

@EndpointInject(ref="requestEP")
ProducerTemplate requestEP;
@EndpointInject(ref="beanEP")
ProducerTemplate beanEP;
@Autowired
ModelCamelContext camelContext; 
@Test
public void test() throws Exception{

    camelContext.getRouteDefinition("testRoute").adviceWith( camelContext ,
new AdviceWithRouteBuilder(){
        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint(
beanEP.getDefaultEndpoint().getEndpointUri() ).
                to("mock:send").
                skipSendToOriginalEndpoint();
        }
    });     
    TestUtils.waitingFor("Configuration applied", 2000);

    MockEndpoint mockEP =
camelContext.getEndpoint("mock:send",MockEndpoint.class);
    mockEP.setExpectedCount( 1 );

    requestEP.sendBody("Message");

    mockEP.assertIsSatisfied();

    TestUtils.waitingFor("All rows commited", 2000);
}
Test always fails. Logs:

13:11:02.512 [main] INFO  o.apache.camel.model.RouteDefinition - AdviceWith
route after: Route(testRoute)[[From[ref:requestEP]] ->
[InterceptSendToEndpoint[bean://eb?method=processMessage ->
[To[mock:send]]], To[ref:beanEP]]]
13:11:02.537 [main] INFO  o.a.camel.spring.SpringCamelContext - Route:
testRoute started and consuming from: Endpoint[direct://request]
13:11:02.538 [main] INFO  com.rencap.emf.bpipe.test.TestUtils - Wait 2000
ms. Configuration applied 
13:11:04.554 [main] INFO  com.rencap.emf.bpipe.EndpointBean - Processing
message: Message 
13:11:04.556 [main] INFO  o.a.c.component.mock.MockEndpoint - Asserting:
Endpoint[mock://send] is satisfied
It means that sending to endpoint isn't being intercepted and skipped. May
be I don't understand something but I coudn't find any restriction on use
this method.

In additional I noticed the same problem for endpoint with log. If I replace
beanEP on :

<endpoint id="beanEP" uri="log:LOGMESSAGE" />
that I receive the same result. But if I replace it on

<endpoint id="beanEP" uri="seda:send" />
and add new route :

<camel:route id="route2">
        <camel:from ref="sendEP"/>
        <camel:log message="msg received ${body}"/>
    </camel:route>
that I will get expected result and test will be successed.

What do I do wrong? Or maybe Are there some restrictions on this method?



--
View this message in context: 
http://camel.465427.n5.nabble.com/Apache-camel-InterceptSendTo-doesn-t-work-with-bean-endpoint-tp5779474.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to