Re: Mocking SQL results in a route

2014-06-23 Thread Claus Ibsen
Hi You can intercept from SQL * and then use a content based router or recipient list or dynamic router or something, and use the exchange property with key: http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#INTERCEPTED_ENDPOINT as it holds the endpoint that

Re: Mocking SQL results in a route

2014-06-19 Thread Matt Raible
Is it possible to mock the first and second sql endpoints using a sort of regular expression? The following seems to intercept all my "sql" endpoints. interceptSendToEndpoint("sql:*") As does this: interceptSendToEndpoint("sql:.*") I'd like to mock the first one and the 2nd one separately. The

Re: Mocking SQL results in a route

2014-06-12 Thread Claus Ibsen
Hi The weave methods of advice with has all kinds of addFirst / addList, replace et all you can use http://camel.apache.org/advicewith.html On Thu, Jun 12, 2014 at 6:48 PM, Matt Raible wrote: > > On Jun 12, 2014, at 10:14 AM, Matt Raible wrote: > >> OK, I got that to work by using @UseAdviceWit

Re: Mocking SQL results in a route

2014-06-12 Thread Matt Raible
On Jun 12, 2014, at 10:14 AM, Matt Raible wrote: > OK, I got that to work by using @UseAdviceWith. Here's my @Before method that > sets everything up and returns SQL results: > > static List results = new ArrayList() {{ > add(new HashMap() {{ > put("fo

Re: Mocking SQL results in a route

2014-06-12 Thread Matt Raible
OK, I got that to work by using @UseAdviceWith. Here's my @Before method that sets everything up and returns SQL results: static List results = new ArrayList() {{ add(new HashMap() {{ put("foo", "bar"); }}); }}; @Bef

Re: Mocking SQL results in a route

2014-06-12 Thread Claus Ibsen
Hi @ EndpointInject does not match wildcards. Do this as I said before in my previous mail But as the SQL endpoint is dynamic calculated then its easier to use interceptSendToEndpoint and skip, as shown in the book on page 182 with the advice with. On Thu, Jun 12, 2014 at 4:47 PM, Matt Raible

Re: Mocking SQL results in a route

2014-06-12 Thread Matt Raible
Possibly. If I have the following annotations on my class: @MockEndpoints("sql:.*") @UseAdviceWith And I mock the SQL endpoint: @EndpointInject(uri = "mock:sql:*") MockEndpoint mockSql; Then I try to set the mocked endpoint's results: @Test public void testMockS

Re: Mocking SQL results in a route

2014-06-12 Thread Claus Ibsen
Hi Is it the @AdviceWith you are looking for ? http://camel.apache.org/spring-testing.html On Thu, Jun 12, 2014 at 4:30 PM, Matt Raible wrote: > Is it possible to use adviceWith when using Spring/Camel's annotation > support? I was originally trying to use this method, but had to extend > Came

Re: Mocking SQL results in a route

2014-06-12 Thread Matt Raible
Is it possible to use adviceWith when using Spring/Camel's annotation support? I was originally trying to use this method, but had to extend CamelTestSupport and its context did not have my routes in it. On Jun 11, 2014, at 11:39 PM, Claus Ibsen wrote: > Hi > > You may want to use @MockEndpoi

Re: Mocking SQL results in a route

2014-06-12 Thread Matt Raible
This looks like exactly what I was looking for. However, it doesn't seem to work. If I set a breakpoint in the "process" method, it's never called in my unit test. Here's what my test currently looks like: @MockEndpoints("sql:.*") public class DrugRouteTests { @Autowired CamelCo

Re: Mocking SQL results in a route

2014-06-11 Thread Claus Ibsen
Hi You may want to use @MockEndpointsAndSkip so you do not call the SQL component. The camel-spring-test with the annotations was added to Camel later, after the book was published. But you can find the annotations and more details here http://camel.apache.org/spring-testing.html But as the SQL

Re: Mocking SQL results in a route

2014-06-11 Thread Minh Tran
Awesome, you got that bit working. To get the mock end point to behave a certain way once it receives an exchange, you can do something like endpoint.whenAnyExchangeReceived(new Processor() { @Override public void process(Exchange exchange) throws

Re: Mocking SQL results in a route

2014-06-11 Thread Matt Raible
Nope, my routes are defined using the Java DSL, not XML. Changing from: @ContextConfiguration(classes = CamelConfig.class) To: @ContextConfiguration(loader = CamelSpringDelegatingTestContextLoader.class, classes = CamelConfig.class) Solved my problem. I don't know if the regex needs to change

Re: Mocking SQL results in a route

2014-06-11 Thread Minh Tran
It appears to me like you have your routes defined in xml and not actually in JavaConfig? In that case, you can simplify your configuration even further and not refer to your JavaConfig class like this @RunWith(CamelSpringJUnit4ClassRunner.class) @ContextConfiguration(loader = CamelSpringDelegat

Re: Mocking SQL results in a route

2014-06-11 Thread Matt Raible
Thanks for your advice. Here's my attempt to modify my test to use CamelSpringJUnit4ClassRunner and annotations to mock my SQL endpoint. @RunWith(CamelSpringJUnit4ClassRunner.class) @ContextConfiguration(classes = CamelConfig.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_

Re: Mocking SQL results in a route

2014-06-11 Thread Minh Tran
If you're using Spring, I recommend not extending any of the Camel Test classes and using the Camel Enhanced Spring Test as described here http://camel.apache.org/spring-testing.html The docs take a bit of getting use to because it describes several different ways of testing via Spring but you j

Re: Mocking SQL results in a route

2014-06-11 Thread Matt Raible
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.

Re: Mocking SQL results in a route

2014-06-11 Thread Claus Ibsen
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 wrote: > Hello, > > I have a route that looks as fol

Mocking SQL results in a route

2014-06-11 Thread Matt Raible
Hello, I have a route that looks as follows: from(uri) .to("log:input") .recipientList(simple("direct:${header.operationName}")); from("direct:lookup") .process(new Pro