Thanks for the advice. I bought the book, read chapter 6 and I'm trying to use
the advice builder. Chapter 6 talks about using mocks quite a bit, which seems
useful in building a route, but not when it's already built.
My routes are configured with Spring and JavaConfig in a CamelConfig class.
When I try to use CamelTestSupport as my parent class, the context doesn't have
any route definitions in it. In other words, context.getRouteDefinitions()
returns an empty list. How do I get CamelTestSupport to recognize my routes
configured in Spring? Or is it possible to inject the context and template and
use adviceWith w/o extending CamelTestSupport?
Thanks,
Matt
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CamelConfig.class)
public class FooRouteTests extends CamelTestSupport {
@Test
public void testAdvised() throws Exception {
context.getRouteDefinition("routeId").adviceWith(context, new
RouteBuilder() {
@Override
public void configure() throws Exception {
// intercept sending to mock:foo and do
something else
interceptSendToEndpoint("sql:*")
.skipSendToOriginalEndpoint()
.to("log:foo")
.to("mock:advised");
}
});
// we must manually start when we are done with all the advice
with
context.start();
template.sendBody("direct:foo", "bar");
getMockEndpoint("mock:advised").expectedMessageCount(1);
assertMockEndpointsSatisfied();
}
@Override
public boolean isUseAdviceWith() {
// tell we are using advice with, which allows us to advice the
route
// before Camel is being started, and thus can replace sql with
something else.
return true;
}
On Jun 11, 2014, at 12:16 PM, Claus Ibsen <[email protected]> wrote:
> Hi
>
> Yeah if you have Camel in Action book, read chapter 6.
>
> And see bottom of this page
> http://camel.apache.org/testing
>
> The advice builder is quite nifty and can "rework" the routes before testing.
>
>
> On Wed, Jun 11, 2014 at 8:10 PM, Matt Raible <[email protected]> wrote:
>> Hello,
>>
>> I have a route that looks as follows:
>>
>> from(uri)
>> .to("log:input")
>>
>> .recipientList(simple("direct:${header.operationName}"));
>> from("direct:lookup")
>> .process(new Processor() {
>> public void process(Exchange
>> exchange) throws Exception {
>> // grab parameters from
>> request and set as headers for SQL statement
>> }
>> })
>>
>> .recipientList(simple("sql:{{sql.lookup}}")).delimiter("false")
>> .to("log:output")
>> .process(new Processor() {
>> public void process(Exchange
>> exchange) throws Exception {
>> List<HashMap> data =
>> (ArrayList<HashMap>) exchange.getIn().getBody();
>>
>> // convert data to response
>>
>>
>> exchange.getOut().setBody(response);
>> }
>> })
>>
>> Is it possible to unit test this route and mock the data returned from the
>> "sql" call? It'd love to be able to verify headers after the first .process,
>> mock the results from the SQL call and verify the results from the 2nd
>> .process method.
>>
>> All of the routes I've developed with Camel so far make SQL calls, but I see
>> SOAP calls in the future. I'll eventually need to mock SOAP calls as well.
>>
>> Thanks,
>>
>> Matt
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: [email protected]
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/