You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hilde <hi...@yahoo.de> on 2012/06/25 09:21:19 UTC

Testing routes: Get route definition by id gets null

Hello folks!

When I test a existing route i prefer to work with AdviceWith. However it is
not possible to get the Route Definition over the ID, but also only via the
index in the collection. That way however is bad for readability.

That doesn't work:
@Test
public void testMainRoutePass() throws Exception {		
				
	context.getRouteDefinition("dkflsd").adviceWith(context, new
AdviceWithRouteBuilder() {
		@Override
		public void configure() throws Exception {
			weaveAddLast().to("mock:mainRoute");				
		}
	});
...

But that works instead:
@Test
public void testMainRoutePass() throws Exception {	
		
	context.getRouteDefinitions().get(0).adviceWith(context, new
AdviceWithRouteBuilder() {
		@Override
		public void configure() throws Exception {
			weaveAddLast().to("mock:mainRoute");		
		}
	});
...

Here comes the camel-context.xml:

<bean id="mainRoute"
	class="com.routes.MainRoute">
	<property name="endpointTo" ref="endpointToTestImpl" />
</bean>

<camel:camelContext>
	
	<camel:routeBuilder ref="mainRoute" id="dkflsd"/>
        ...
</camel:camelContext>


Could you help me?

Cheers
Hilde


--
View this message in context: http://camel.465427.n5.nabble.com/Testing-routes-Get-route-definition-by-id-gets-null-tp5715014.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Testing routes: Get route definition by id gets null

Posted by Omar Atia <om...@its.ws>.

Sent from my iPad

On Jun 25, 2012, at 12:24 PM, "Claus Ibsen" <cl...@gmail.com> wrote:

> Hi
> 
> In your route using Java DSL, you need to declare the id of the route
> in the DSL using .routeId("foo")
> 
> eg
> 
> from("file:foo").routeId("foo")
>  .to("blah")
> 
> Then you can refer to the route id "foo" in the advice with.
> 
> 
> 
> On Mon, Jun 25, 2012 at 9:21 AM, Hilde <hi...@yahoo.de> wrote:
>> Hello folks!
>> 
>> When I test a existing route i prefer to work with AdviceWith. However it is
>> not possible to get the Route Definition over the ID, but also only via the
>> index in the collection. That way however is bad for readability.
>> 
>> That doesn't work:
>> @Test
>> public void testMainRoutePass() throws Exception {
>> 
>>        context.getRouteDefinition("dkflsd").adviceWith(context, new
>> AdviceWithRouteBuilder() {
>>                @Override
>>                public void configure() throws Exception {
>>                        weaveAddLast().to("mock:mainRoute");
>>                }
>>        });
>> ...
>> 
>> But that works instead:
>> @Test
>> public void testMainRoutePass() throws Exception {
>> 
>>        context.getRouteDefinitions().get(0).adviceWith(context, new
>> AdviceWithRouteBuilder() {
>>                @Override
>>                public void configure() throws Exception {
>>                        weaveAddLast().to("mock:mainRoute");
>>                }
>>        });
>> ...
>> 
>> Here comes the camel-context.xml:
>> 
>> <bean id="mainRoute"
>>        class="com.routes.MainRoute">
>>        <property name="endpointTo" ref="endpointToTestImpl" />
>> </bean>
>> 
>> <camel:camelContext>
>> 
>>        <camel:routeBuilder ref="mainRoute" id="dkflsd"/>
>>        ...
>> </camel:camelContext>
>> 
>> 
>> Could you help me?
>> 
>> Cheers
>> Hilde
>> 
>> 
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Testing-routes-Get-route-definition-by-id-gets-null-tp5715014.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen

Re: Testing routes: Get route definition by id gets null

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Jun 25, 2012 at 12:14 PM, Hilde <hi...@yahoo.de> wrote:
> Hello Claus!
>
> You are right, thanks a lot!
>
> When I look into the Camel API I can see that the method
> getRouteDefinition(String routeId) in class CamelContext is deprecated. Is
> there already a new way existing to bypass that way?
>

No but there is a ModelCamelContext interface from the model package,
which has all the APIs for working with the model classes.
So you can cast CamelContext to ModelCamelContext and use these APIs

Its a sort of API separation so the root package where CamelContext is
do not have deps to model package where the route defs are.


> Hilde
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Testing-routes-Get-route-definition-by-id-gets-null-tp5715014p5715033.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Testing routes: Get route definition by id gets null

Posted by Hilde <hi...@yahoo.de>.
Hello Claus!

You are right, thanks a lot! 

When I look into the Camel API I can see that the method
getRouteDefinition(String routeId) in class CamelContext is deprecated. Is
there already a new way existing to bypass that way?

Hilde 

--
View this message in context: http://camel.465427.n5.nabble.com/Testing-routes-Get-route-definition-by-id-gets-null-tp5715014p5715033.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Testing routes: Get route definition by id gets null

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

In your route using Java DSL, you need to declare the id of the route
in the DSL using .routeId("foo")

eg

from("file:foo").routeId("foo")
  .to("blah")

Then you can refer to the route id "foo" in the advice with.



On Mon, Jun 25, 2012 at 9:21 AM, Hilde <hi...@yahoo.de> wrote:
> Hello folks!
>
> When I test a existing route i prefer to work with AdviceWith. However it is
> not possible to get the Route Definition over the ID, but also only via the
> index in the collection. That way however is bad for readability.
>
> That doesn't work:
> @Test
> public void testMainRoutePass() throws Exception {
>
>        context.getRouteDefinition("dkflsd").adviceWith(context, new
> AdviceWithRouteBuilder() {
>                @Override
>                public void configure() throws Exception {
>                        weaveAddLast().to("mock:mainRoute");
>                }
>        });
> ...
>
> But that works instead:
> @Test
> public void testMainRoutePass() throws Exception {
>
>        context.getRouteDefinitions().get(0).adviceWith(context, new
> AdviceWithRouteBuilder() {
>                @Override
>                public void configure() throws Exception {
>                        weaveAddLast().to("mock:mainRoute");
>                }
>        });
> ...
>
> Here comes the camel-context.xml:
>
> <bean id="mainRoute"
>        class="com.routes.MainRoute">
>        <property name="endpointTo" ref="endpointToTestImpl" />
> </bean>
>
> <camel:camelContext>
>
>        <camel:routeBuilder ref="mainRoute" id="dkflsd"/>
>        ...
> </camel:camelContext>
>
>
> Could you help me?
>
> Cheers
> Hilde
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Testing-routes-Get-route-definition-by-id-gets-null-tp5715014.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen