You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ManishGupta <ma...@gmail.com> on 2014/12/16 09:24:58 UTC

Junit Test Failing with AdviceWith

Afternoon all,

I have created Junit for existing production routes , Requirement was not to
change anything from the route and test it with dummy data. From
cameInAction and camel.apache.org i found the best approach will be to use
adviceWith. I am using camel 2.10.

When i run the Junit it starts of with replacing the From using
replaceFromWith , New Route is created with changes from AdviceWith after
the ContextStart ( I use isUseAdviceWith = True) and as soon as it starts it
starts shutting down. The Route is not executed as expected , Please help.

Given Below is my Test class :

@UseAdviceWith
public class AMSTest extends CamelSpringTestSupport{

	@Override
	protected AbstractApplicationContext createApplicationContext() {
		return new ClassPathXmlApplicationContext(
				"ams-context.xml");
	}
	
	
    @Override
    public boolean isUseAdviceWith() {
        return true;
    }

	@Test
	public void testLAMS() throws Exception 
	{
		
		context.getRouteDefinition("compare-request").adviceWith(context, new
AdviceWithRouteBuilder() {
	        @Override
	        public void configure() throws Exception {

	        	
replaceFromWith("file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE");
	        }
	    });
		
		context.start();
	}
}

StackTrace :

12:05:19,213 DEBUG AMSTest:240 - setUp test
12:05:19,231 DEBUG AMSTest:297 - Using created route builder: Routes: []
12:05:19,232  INFO AMSTest:304 - Skipping starting CamelContext as
isUseAdviceWith is set to true.
12:05:19,232 DEBUG AMSTest:311 - Routing Rules are: []
12:05:19,236  INFO AdviceWithTasks:313 - AdviceWith replace input from
[file:{{outbound_home}}/Compare?fileName=STARTCOMPARE&move={{data_home}}]
--> [file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE]
12:05:19,237  INFO RouteDefinition:267 - AdviceWith route after: "NEW Route
With Changes"
12:05:19,650  INFO SpringCamelContext:1381 - Apache Camel 2.10.0
(CamelContext: myCamel) is starting
12:05:19,686  INFO DefaultManagementAgent:431 - JMX Connector thread started
and listening at:
service:jmx:rmi:///jndi/rmi://ubuntu12-virtual-machine:8000/jmxrmi/camel
12:05:19,690  INFO DefaultManagementLifecycleStrategy:849 - StatisticsLevel
at All so enabling load performance statistics
12:05:20,269  INFO FileConsumer:27 - using Oceanview FileConsumer
12:05:20,688  INFO SpringCamelContext:2015 - Route: compare-request started
and consuming from:
Endpoint[file:///home/manish/cameldata/Compare?fileName=STARTCOMPARE]
12:05:20,691  INFO SpringCamelContext:1416 - Total 1 routes, of which 1 is
started.
12:05:20,692  INFO SpringCamelContext:1417 - Apache Camel 2.10.0
(CamelContext: myCamel) started in 1.042 seconds
12:05:20,692  INFO AMSTest:322 -
********************************************************************************
12:05:20,692  INFO AMSTest:323 - Testing done:
testAMS(com.ocean.ams.AMSTest)
12:05:20,692  INFO AMSTest:324 - Took: 1.460 seconds (1460 millis)
12:05:20,693  INFO AMSTest:325 -
********************************************************************************
12:05:20,693  INFO SpringCamelContext:1557 - Apache Camel 2.10.0
(CamelContext: myCamel) is shutting down



--
View this message in context: http://camel.465427.n5.nabble.com/Junit-Test-Failing-with-AdviceWith-tp5760732.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Junit Test Failing with AdviceWith

Posted by ManishGupta <ma...@gmail.com>.
Thanks for the help claus :) I read through the Javadocs and understood that
start method is non blocking. If i have to use in a standalone application i
have to use main function provided by camel.

http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

I inturn used the ProducerTemplate to keep the camelContext in running state
with following code.

@UseAdviceWith 
public class AMSTest extends CamelSpringTestSupport{ 

        @Override 
        protected AbstractApplicationContext createApplicationContext() { 
                return new ClassPathXmlApplicationContext( 
                                "ams-context.xml"); 
        } 
        
        
    @Override 
    public boolean isUseAdviceWith() { 
        return true; 
    } 

        @Test 
        public void testLAMS() throws Exception 
        { 
                
               
context.getRouteDefinition("compare-request").adviceWith(context, new
AdviceWithRouteBuilder() { 
                @Override 
                public void configure() throws Exception { 

                replaceFromWith("direct:start"); 
                } 
            }); 
                
                context.start(); 
                template.sendBody("direct:start",String.class);

        } 
} 

I bumped in to another issue from my actual code i had

*
replaceFromWith("file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE");
*

if i want to use the same replace statement from my original code i.e.

*
replaceFromWith("file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE&amp;doneFileName=LOADGSMPRICING");
*

I am unable to use the ProducerTemplate for the same 

InputStream f = getClass().getResourceAsStream("LOADTRIGGER");

template.sendBody("file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE&amp;doneFileName=LOADTRIGGER",file);

Can you please help me with this ?



--
View this message in context: http://camel.465427.n5.nabble.com/Junit-Test-Failing-with-AdviceWith-tp5760732p5760823.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Junit Test Failing with AdviceWith

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

See the javadoc of the start method and class javadoc of CamelContext

On Tue, Dec 16, 2014 at 9:54 AM, ManishGupta <ma...@gmail.com> wrote:
> Thanks for the Prompt reply Claus , I know about the mockEndpoint (assertions
> and Expectations) , It is very well explained in the book  I didn't use them
> to make it simpler at first.
>
> I didn't get your point on
> //"You need to run the test for a longer time. The start method is non
> blocking."
>
> Can you please elaborate or give me another hint.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Junit-Test-Failing-with-AdviceWith-tp5760732p5760735.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Junit Test Failing with AdviceWith

Posted by ManishGupta <ma...@gmail.com>.
Thanks for the Prompt reply Claus , I know about the mockEndpoint (assertions
and Expectations) , It is very well explained in the book  I didn't use them
to make it simpler at first. 

I didn't get your point on 
//"You need to run the test for a longer time. The start method is non
blocking."

Can you please elaborate or give me another hint.




--
View this message in context: http://camel.465427.n5.nabble.com/Junit-Test-Failing-with-AdviceWith-tp5760732p5760735.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Junit Test Failing with AdviceWith

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

You need to run the test for a longer time. The start method is non
blocking. And for testing you may want to use mocks to set
expectations and whatnot.

Since you got the book, then read the entire testing chapter to learn more.



On Tue, Dec 16, 2014 at 9:24 AM, ManishGupta <ma...@gmail.com> wrote:
> Afternoon all,
>
> I have created Junit for existing production routes , Requirement was not to
> change anything from the route and test it with dummy data. From
> cameInAction and camel.apache.org i found the best approach will be to use
> adviceWith. I am using camel 2.10.
>
> When i run the Junit it starts of with replacing the From using
> replaceFromWith , New Route is created with changes from AdviceWith after
> the ContextStart ( I use isUseAdviceWith = True) and as soon as it starts it
> starts shutting down. The Route is not executed as expected , Please help.
>
> Given Below is my Test class :
>
> @UseAdviceWith
> public class AMSTest extends CamelSpringTestSupport{
>
>         @Override
>         protected AbstractApplicationContext createApplicationContext() {
>                 return new ClassPathXmlApplicationContext(
>                                 "ams-context.xml");
>         }
>
>
>     @Override
>     public boolean isUseAdviceWith() {
>         return true;
>     }
>
>         @Test
>         public void testLAMS() throws Exception
>         {
>
>                 context.getRouteDefinition("compare-request").adviceWith(context, new
> AdviceWithRouteBuilder() {
>                 @Override
>                 public void configure() throws Exception {
>
>
> replaceFromWith("file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE");
>                 }
>             });
>
>                 context.start();
>         }
> }
>
> StackTrace :
>
> 12:05:19,213 DEBUG AMSTest:240 - setUp test
> 12:05:19,231 DEBUG AMSTest:297 - Using created route builder: Routes: []
> 12:05:19,232  INFO AMSTest:304 - Skipping starting CamelContext as
> isUseAdviceWith is set to true.
> 12:05:19,232 DEBUG AMSTest:311 - Routing Rules are: []
> 12:05:19,236  INFO AdviceWithTasks:313 - AdviceWith replace input from
> [file:{{outbound_home}}/Compare?fileName=STARTCOMPARE&move={{data_home}}]
> --> [file:/home/manish/cameldata/Compare?fileName=STARTCOMPARE]
> 12:05:19,237  INFO RouteDefinition:267 - AdviceWith route after: "NEW Route
> With Changes"
> 12:05:19,650  INFO SpringCamelContext:1381 - Apache Camel 2.10.0
> (CamelContext: myCamel) is starting
> 12:05:19,686  INFO DefaultManagementAgent:431 - JMX Connector thread started
> and listening at:
> service:jmx:rmi:///jndi/rmi://ubuntu12-virtual-machine:8000/jmxrmi/camel
> 12:05:19,690  INFO DefaultManagementLifecycleStrategy:849 - StatisticsLevel
> at All so enabling load performance statistics
> 12:05:20,269  INFO FileConsumer:27 - using Oceanview FileConsumer
> 12:05:20,688  INFO SpringCamelContext:2015 - Route: compare-request started
> and consuming from:
> Endpoint[file:///home/manish/cameldata/Compare?fileName=STARTCOMPARE]
> 12:05:20,691  INFO SpringCamelContext:1416 - Total 1 routes, of which 1 is
> started.
> 12:05:20,692  INFO SpringCamelContext:1417 - Apache Camel 2.10.0
> (CamelContext: myCamel) started in 1.042 seconds
> 12:05:20,692  INFO AMSTest:322 -
> ********************************************************************************
> 12:05:20,692  INFO AMSTest:323 - Testing done:
> testAMS(com.ocean.ams.AMSTest)
> 12:05:20,692  INFO AMSTest:324 - Took: 1.460 seconds (1460 millis)
> 12:05:20,693  INFO AMSTest:325 -
> ********************************************************************************
> 12:05:20,693  INFO SpringCamelContext:1557 - Apache Camel 2.10.0
> (CamelContext: myCamel) is shutting down
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Junit-Test-Failing-with-AdviceWith-tp5760732.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/