Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DFD36E5C9 for ; Tue, 26 Feb 2013 02:54:59 +0000 (UTC) Received: (qmail 36758 invoked by uid 500); 26 Feb 2013 02:54:59 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 36716 invoked by uid 500); 26 Feb 2013 02:54:59 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 36703 invoked by uid 99); 26 Feb 2013 02:54:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Feb 2013 02:54:59 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of willem.jiang@gmail.com designates 209.85.160.43 as permitted sender) Received: from [209.85.160.43] (HELO mail-pb0-f43.google.com) (209.85.160.43) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Feb 2013 02:54:52 +0000 Received: by mail-pb0-f43.google.com with SMTP id md12so2072580pbc.30 for ; Mon, 25 Feb 2013 18:54:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:message-id:in-reply-to:references:subject :x-mailer:mime-version:content-type:content-transfer-encoding :content-disposition; bh=77/niBKZ+rqB1VdzQDYY8ull6SVEmWYTtBT70es+BGw=; b=yehkvFvjupRAAFjKrA6zEGZwnsvcN8H74ev6cDBrtiKsVBHDjQVQUyg9vvcOlYXXVX IgcxNRSdFM5BIVGC/X8NprnMcd/W7/weLBYuQ/tLoF9Q3wc+Dcb3W5M8bID6lOKxXEHA 7q6NvCTI2Zpg9zL6bXNeWts6Tq9ycwdli6WUaqfORWlnhiiIXuL+ScGC4NUR+93DfmpO wXGEIWj1EmAhfTxVtO4b4yxjT9T9kUTXlbTUNj8lMYLTdfK1oJfyNkt/SFvaT2jJqkAd SRbM3gRU/1Zu3/9OX166MMLz3xe5DzD5/V5zSk5vZsIE06i1M1ijSSF0PRwBiDsLvruk Q/3w== X-Received: by 10.66.147.137 with SMTP id tk9mr22354506pab.106.1361847271615; Mon, 25 Feb 2013 18:54:31 -0800 (PST) Received: from [192.168.1.135] ([125.33.121.160]) by mx.google.com with ESMTPS id a10sm14706069pbq.29.2013.02.25.18.54.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Feb 2013 18:54:30 -0800 (PST) Date: Tue, 26 Feb 2013 10:54:26 +0800 From: Willem jiang To: users@camel.apache.org Message-ID: <97AA26E02CCA41EAB6ABE6911F78835C@gmail.com> In-Reply-To: <1361826117511-5728122.post@n5.nabble.com> References: <1361826117511-5728122.post@n5.nabble.com> Subject: Re: My First Camel Route. Need help unit testing and refactoring. X-Mailer: sparrow 1.6.4 (build 1176) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Checked: Checked by ClamAV on apache.org When we write the unit tests for the camel route, we just want test the r= oute logical. =20 Because it is hard to setup all the environment, we don't want to get tou= ch with the other camel component in the unit test. You can break the whole route into some small pieces with the help of dir= ect endpoints, and you can just feed the message to it by using the Produ= cerTemplate. Back to the component, you can use the intercept=5B1=5D to change the beh= avior of camel route to avoiding using the other compomnent and verify th= e result at the same time. =5B1=5Dhttp://camel.apache.org/intercept.html -- =20 Willem Jiang Red Hat, Inc. =46useSource is now part of Red Hat Web: http://www.fusesource.com =7C 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 =20 Weibo: =E5=A7=9C=E5=AE=81willem On Tuesday, =46ebruary 26, 2013 at 5:01 AM, shyenuganti wrote: > Here is a sample route written in Camel for our application. This is ou= r > first ever route in camel. =20 > =20 > This route reads Event Table in Oracle and AS400 systems, extracts an X= ML > message from the record and send the message to JMS queue. > =20 > All the JDBC and JMS endpoints are based on JNDI Lookup. > =20 > This is working fine. Now I am a bit confused on how to write > unit/integration tests for this route. Can anyone help me with a sample= > unit test methods for this route=3F =20 > =20 > Do we have to use =22mocks=22 for testing=3F Cant we replace the compon= ents with > mocks on the fly =3F Should we have multiple application context files = in > test/resources thaat mocks the JPA and jms endpoints for testing =3F =20 > =20 > =20 > Any comments on the route structure or any refactoring/best practice id= eas > are welcome. Please assist. > =20 > =20 > public class EventListenerRoute =20 > extends RouteBuilder > implements InitializingBean, DisposableBean=7B > =20 > public void configure() throws Exception =7B > =20 > =20 > from(=22as400Jpa://org.model.EventQueue=3FconsumeDelete=3Dfalse&consume= r.delay=3D5000=22) > .id(=22AS400ReaderEndpoint=22) > .convertBodyTo(org.model.EventQueue.class) > .to(=22direct:eventMessageList=22); > =20 > =20 > from(=22oracleJpa://org.model.EventQueue=3FconsumeDelete=3Dfalse&consum= er.delay=3D5000=22) > .id(=22OracleReaderEndpoint=22) > .convertBodyTo(org.model.EventQueue.class) > .to(=22direct:eventMessageList=22); > =20 > from(=22direct:eventMessageList=22).id(=22PseudoEventQueue=22) > .log(=22Sending Message to Queue: jbossEventQueue=22) > .to(=22jms:queue/jbossEventQueue=3FmessageConverter=3D=23myMessageConve= rter=22) > .log(=22Sent message to jbossEventQueue=22); > =20 > =7D > =20 > =20 > =20 > -- > View this message in context: http://camel.465427.n5.nabble.com/My-=46i= rst-Camel-Route-Need-help-unit-testing-and-refactoring-tp5728122.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://= Nabble.com).