You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Baalu <go...@gmail.com> on 2013/03/12 21:57:32 UTC

Where to start with Unit testing

Hello Guys,

I am trying to write a unit test for my first camel route. Below is my camel
route: I am updating the database using jdbc component. 
Also,can you guys tell me is the below route the right way to update the
database?

DataSource ds = this.getContext().getRegistry()
				.lookup("oracleDataSource", DataSource.class);
		final JdbcTemplate jdbc = new JdbcTemplate(ds);
from("timer://foo?period=5000")
				.setBody(constant("select * from customers where last_changed_date >=
trunc(sysdate)"))
				.to("jdbc:oracleDataSource").process(new Processor() {
					@Override
					public void process(Exchange exchange) throws Exception {
						ArrayList<HashMap&lt;String, Object>> data = exchange
								.getIn().getBody(ArrayList.class);
						for (HashMap<String, Object> item : data) {
							System.out.println("Hitting Database::::::::::::"
									+ ((String) item.get("STATE_ABBREVIATION")));
							jdbc.execute("update Orders set Order_Date =" + "to_date('"
									+ (Date) item.get("O_DATE") + "',"
									+ "'YYYY-MM-DD')"
									+ " where order_number = "
									+ (BigDecimal) item.get("O_NUMBER")
									);
						System.out.println("UPDATE DONE**********************");
						}
					}
				});



--
View this message in context: http://camel.465427.n5.nabble.com/Where-to-start-with-Unit-testing-tp5729044.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Where to start with Unit testing

Posted by Baalu <go...@gmail.com>.
Also, can you tell me whether my route is the best way to do it or not?



--
View this message in context: http://camel.465427.n5.nabble.com/Where-to-start-with-Unit-testing-tp5729044p5729112.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Where to start with Unit testing

Posted by Willem jiang <wi...@gmail.com>.
Hi,

You may take a look at this unit test[1] which send insert SQL to the JDBC endpoint , and you can do the same thing like that in Camel route.

[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcGeneratedKeysTest.java  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Wednesday, March 13, 2013 at 4:57 AM, Baalu wrote:

> Hello Guys,
>  
> I am trying to write a unit test for my first camel route. Below is my camel
> route: I am updating the database using jdbc component.  
> Also,can you guys tell me is the below route the right way to update the
> database?
>  
> DataSource ds = this.getContext().getRegistry()
> .lookup("oracleDataSource", DataSource.class);
> final JdbcTemplate jdbc = new JdbcTemplate(ds);
> from("timer://foo?period=5000")
> .setBody(constant("select * from customers where last_changed_date >=
> trunc(sysdate)"))
> .to("jdbc:oracleDataSource").process(new Processor() {
> @Override
> public void process(Exchange exchange) throws Exception {
> ArrayList<HashMap&lt;String, Object>> data = exchange
> .getIn().getBody(ArrayList.class);
> for (HashMap<String, Object> item : data) {
> System.out.println("Hitting Database::::::::::::"
> + ((String) item.get("STATE_ABBREVIATION")));
> jdbc.execute("update Orders set Order_Date =" + "to_date('"
> + (Date) item.get("O_DATE") + "',"
> + "'YYYY-MM-DD')"
> + " where order_number = "
> + (BigDecimal) item.get("O_NUMBER")
> );
> System.out.println("UPDATE DONE**********************");
> }
> }
> });
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Where-to-start-with-Unit-testing-tp5729044.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).