Here is what I do to run just my jarred components (paraphrased)...
I have a baseCamelTest class that uses the SpringTestNG support to start-up
a spring context.
Then, in my applicationContext-test.xml, I start my test broker and will add
my test routes.
Now when i plan to go into a real system, like dev, stage, prod, I have my
'live' routes in my applicationContextProd.xml that has my live broker, and
my live routes.
I guess the way you are mentioning would alos work, but means I have to
maintain an application.properties, or a filter. I guess i feel because I am
already using the applicationContext-test.xml to replace my broker, it just
seems more natural to me to switch the routes the same way.
On Fri, Sep 19, 2008 at 9:44 AM, Claus Ibsen <[EMAIL PROTECTED]> wrote:
> Hi
>
> Mick can you give an example how you can easily switch between test and
> prod routes using Spring? I am looking into best practices as well using
> Spring and having Java DSL routing.
>
> What I was doing is to use Java DSL with alias names for the endpoints, and
> have the endpoints properly configured in spring XML. Then I can have spring
> XML with property placeholders.
> <endpoint id="input1" uri="activemq:${someQueueName}"/>
>
> Then I can use the "input1" alias in my java DSL.
> from("input1").to("xxx");
>
>
>
> Med venlig hilsen
>
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
>
> -----Original Message-----
> From: Mick Knutson [mailto:[EMAIL PROTECTED]
> Sent: 19. september 2008 18:29
> To: [email protected]
> Subject: Re: testNG test harness for Camel, sending and receiving messages
>
> The tcp issue was because in my @BeforeClass(), I had camelContext = new
> DefaultCamelContext(); whiche seemed to start the default tcp broker. But I
> am actually using Spring to start my broker, so I just removed that line
> and
> it worked fine.
>
> For the producer, I am using:
> @EndpointInject(uri = Constants.CR_INPUT_CHANNEL)
> ProducerTemplate producerTemplate;
>
> This works fine, but I would like some design input as to how to inject
> routes in TestNG for testing when I see that DSL is prefered over Spring
> Routing. With Spring Routing I can easily switch test, and prod routes. But
> not sure how easily to do this with dsl.
>
>
>
>
>
> On Thu, Sep 18, 2008 at 10:44 PM, Claus Ibsen <[EMAIL PROTECTED]> wrote:
>
> > Hi
> >
> > You get the ProducerTemplate from the CamelContext directly with the
> > createProducerTemplate() method.
> >
> > I have no clue why ActiveMQ embeds the TCP listener, maybe there is
> > somekind of spring .xml files included in one of the .jars or on your
> > classpath when running the test.
> >
> >
> >
> > Med venlig hilsen
> >
> > Claus Ibsen
> > ......................................
> > Silverbullet
> > Skovsgårdsvænget 21
> > 8362 Hørning
> > Tlf. +45 2962 7576
> > Web: www.silverbullet.dk
> >
> > -----Original Message-----
> > From: Mick Knutson [mailto:[EMAIL PROTECTED]
> > Sent: 18. september 2008 20:59
> > To: [email protected]
> > Subject: Re: testNG test harness for Camel, sending and receiving
> messages
> >
> > I am making some headway.
> >
> > I have create a startup method:
> > [EMAIL PROTECTED](groups = {"init"})
> > public void startCamel() {
> > try {
> > log.debug("Start Camel Context");
> > // create the camel context:
> > camelContext = new DefaultCamelContext();
> >
> > // add the routes to the camel Context
> > camelContext.addRoutes(new ChangeRequestRouteBuilder());
> >
> > // start Camel Context
> > // create a camel template for sending messages:
> > camelTemplate = new CamelTemplate(camelContext);
> >
> > // I added this as the recommendation to the deprecated
> > // camelTemplate above...
> > //producerTemplate = new ProducerTemplate();
> >
> > // start the camel context
> > camelContext.start();
> > } catch (Exception e) {
> > // this is an example -> don't handle exceptions:
> > e.printStackTrace();
> > }
> > }//
> > *
> >
> > But I have an issue. *CamelTemplate is deprecated, and **ProducerTemplate
> > is
> > abstract*. How how do I start using the *ProducerTemplate instead?
> >
> > *Also, in my SpringTestNG base, I start up my test context:*
> > [EMAIL PROTECTED](*
> > * locations = {"classpath:applicationContext-test.xml"}*
> > *)*
> >
> > That includes:*
> > **<import resource="classpath:META-INF/spring/camel-context.xml" />*
> >
> > and I am using the embedded broker:
> >
> > *<!-- lets configure the default ActiveMQ broker URL -->*
> > * <bean id="activemq"
> > class="org.apache.camel.component.jms.JmsComponent">*
> > * <property name="connectionFactory">*
> > * <bean
> class="org.apache.activemq.ActiveMQConnectionFactory">*
> > * <property name="brokerURL"
> > value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>*
> > * </bean>*
> > * </property>*
> > * </bean>*
> >
> > so why do i keep getting the full default broker being searched for:
> >
> > *[myproject] DEBUG [ActiveMQ Task] FailoverTransport.doReconnect(671) |
> > Attempting connect to: tcp://localhost:61616
> > [myproject] DEBUG [ActiveMQ Task] FailoverTransport.doReconnect(699) |
> > Connect fail to: tcp://localhost:61616, reason:
> java.net.ConnectException:
> > Connection refused
> > [myproject] DEBUG [ActiveMQ Task] FailoverTransport.doReconnect(732) |
> > Waiting 30000 ms before attempting connection.
> > *
> >
> >
> >
> > On Wed, Sep 17, 2008 at 10:49 PM, James Strachan
> > <[EMAIL PROTECTED]>wrote:
> >
> > > I agree with everything Claus just said :) But another thing you can
> > > do is run the TestNG test case directly in your IDE as well without
> > > using Maven at all.
> > >
> > >
> > > 2008/9/18 Mick Knutson <[EMAIL PROTECTED]>:
> > > > I have created a base class extending
> AbstractTestNGSpringContextTests
> > as
> > > > you mentioned. I actually did the same to support bdunit.
> > > >
> > > > But there are a few things, related to camel that I am just not
> getting
> > > yet.
> > > >
> > > >
> > > >
> > > > * What does the camel-maven-plugin doing that my base class will not
> by
> > > > initializing the camel-context.xml?
> > > >
> > > > I tried to run my mvn install without the camel-maven-plugin. I get
> the
> > > > camel-context initialized, but does not run the same as when I run
> mvn
> > > > camel:run.
> > > >
> > > > *There is:*
> > > > *public class CRRouteBuilder extends RouteBuilder {
> > > > ....
> > > > public static void main(String[] args) {
> > > > new Main().run(args);
> > > > }
> > > > *
> > > >
> > > > in my RouteBuilder and I guess I am not sure if this is started by
> the
> > > > plugin to run or not.
> > > >
> > > > I tried mvn camel:run and keep getting a poll loop:
> > > >
> > > > *[myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.pollFileOrDirectory(81) | Polling directory src/data
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.isChanged(231) | file:src/data/message1.xml
> > isChanged:false
> > > > sizeCheck:false(0) lastModifiedCheck:false(0)
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.isChanged(231) | file:src/data/message2.xml
> > isChanged:false
> > > > sizeCheck:false(0) lastModifiedCheck:false(0)
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.isChanged(231) | file:src/data/message3.xml
> > isChanged:false
> > > > sizeCheck:false(0) lastModifiedCheck:false(0)
> > > > *
> > > >
> > > > so should I not use the plugin at all? And just start the
> camelContext
> > by
> > > > itself?
> > > >
> > > > Do I just need to have my testNG send a message to initiate the
> > process?
> > > >
> > > >
> > > > It seems that the process is initiated:
> > > >
> > > > *[myproject] DEBUG [VMTransport]
> > > ActiveMQConnection.onAsyncException(1695) |
> > > > Async exception with no exception listener:
> > > > org.apache.activemq.transport.TransportDisposedIOException: Peer
> > > > (vm://localhost#1) disposed.
> > > > org.apache.activemq.transport.TransportDisposedIOException: Peer
> > > > (vm://localhost#1) disposed.
> > > > at
> > > >
> > >
> >
> org.apache.activemq.transport.vm.VMTransport.iterate(VMTransport.java:203)
> > > > at
> > > >
> > >
> >
> org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
> > > > at
> > > >
> > >
> >
> org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
> > > > at
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
> > > > at
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
> > > > at java.lang.Thread.run(Thread.java:613)
> > > > [myproject] DEBUG [ActiveMQ Transport Stopper: vm://localhost#0]
> > > > TransportConnection.doStop(994) | Connection Stopped:
> vm://localhost#0
> > > > [myproject] INFO [ActiveMQ ShutdownHook] TransportConnector.stop(273)
> |
> > > > Connector vm://localhost Stopped
> > > > [myproject] DEBUG [Thread-2]
> > DefaultListableBeanFactory.destroyBean(447)
> > > |
> > > > Retrieved dependent beans for bean
> > > > 'org.apache.activemq.ActiveMQConnectionFactory#3dc0f4': [activemq]
> > > > [myproject] DEBUG [Thread-2]
> > DefaultListableBeanFactory.destroyBean(447)
> > > |
> > > > Retrieved dependent beans for bean 'camel:beanPostProcessor': [camel]
> > > > [myproject] DEBUG [Thread-2]
> > DefaultListableBeanFactory.destroyBean(447)
> > > |
> > > > Retrieved dependent beans for bean 'camel': [camel:beanPostProcessor,
> > > > org.apache.camel.component.file.FileComponent,
> > > > com.servepath.ChangeRequestTest]
> > > > myproject] DEBUG [Thread-2] DisposableBeanAdapter.destroy(148) |
> > Invoking
> > > > destroy() on bean with name 'camel'
> > > > [myproject] INFO [ActiveMQ ShutdownHook] BrokerService.stop(512) |
> > > ActiveMQ
> > > > JMS Message Broker (localhost,
> > > > ID:mick-knutsons-macbook.local-50355-1221698401973-0:0) stopped
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > ScheduledPollConsumer.run(62) | Starting to poll:
> > > > Endpoint[file:src/data?noop=true]
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.pollFileOrDirectory(81)
> > > > | Polling directory src/data
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.isChanged(231) | file:src/data/message1.xml
> isChanged:true
> > > > sizeCheck:false(0) lastModifiedCheck:true(0)
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileEndpoint.getFileStrategy(158) | Using file process strategy:
> > > >
> [EMAIL PROTECTED]
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileConsumer.pollFile(122) | About to process file:
> > src/data/message1.xml
> > > > using exchange: Exchange[FileMessage: src/data/message1.xml]
> > > > [myproject] DEBUG [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > FileProcessStrategySupport.begin(62) | Locking the file:
> > > > src/data/message1.xml using the lock file name:
> > > >
> > >
> >
> /opt/projects/changerequest/camel-example-spring/src/data/message1.xml.cameLock
> > > > [myproject] ERROR [Thread: 1
> > > > [EMAIL PROTECTED]
> > > > BrokerService.start(466) | Failed to start ActiveMQ JMS Message
> Broker.
> > > > Reason: java.lang.IllegalStateException: Shutdown in progress
> > > >
> > > > *
> > > >
> > > > But there is an error in bold above.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Tue, Sep 16, 2008 at 11:14 PM, James Strachan
> > > > <[EMAIL PROTECTED]>wrote:
> > > >
> > > >> 2008/9/16 Mick Knutson <[EMAIL PROTECTED]>:
> > > >> > I am trying to setup camel within Maven to start my camel context
> > via
> > > the
> > > >> > <plugin>
> > > >> > <groupId>org.apache.camel</groupId>
> > > >> > <artifactId>camel-maven-plugin</artifactId>
> > > >> > <version>1.4.0</version>
> > > >> > </plugin>
> > > >> >
> > > >> > Now I was hoping that someone has already created a
> baseCamelTestNG
> > > class
> > > >> to
> > > >> > start/stop camel, then helper class to send and receive messages.
> > > >> >
> > > >> > Then after the tests have run, the plugin can shutdown.
> > > >>
> > > >> BTW there's a Camel user list, I've CC'd so other camel users can
> > listen
> > > >> too...
> > > >> http://activemq.apache.org/camel/discussion-forums.html
> > > >>
> > > >> The best approach for unit testing and sending & receiving messages
> is
> > > >> to use the Spring Testing mechanism which works with JUnit 3.x, 4.x
> or
> > > >> TestNG
> > > >> http://activemq.apache.org/camel/spring-testing.html
> > > >>
> > > >> for TestNG you might want to derive from
> > > AbstractTestNGSpringContextTests
> > > >> see
> > > >>
> > > >>
> > >
> >
> http://static.springframework.org/spring/docs/2.5.x/reference/testing.html#testcontext-fixture-di
> > > >>
> > > >> this then does the dependency injection with Spring and runs your
> test
> > > >> case.
> > > >>
> > > >> To send messages you can inject a ProducerTemplate; then to receive
> > > >> messages you can then use the @MessageDriven annotation on a method
> -
> > > >> see the examples here
> > > >> http://activemq.apache.org/camel/bean-integration.html
> > > >>
> > > >> plus you can then inject mock endpoints for testing as well as
> > described
> > > >> here
> > > >> http://activemq.apache.org/camel/spring-testing.html
> > > >> http://activemq.apache.org/camel/mock.html
> > > >>
> > > >> --
> > > >> James
> > > >> -------
> > > >> http://macstrac.blogspot.com/
> > > >>
> > > >> Open Source Integration
> > > >> http://open.iona.com
> > > >>
> > > >
> > > >
> > > >
> > > > --
> > > > ---
> > > > Thank You...
> > > >
> > > > Mick Knutson
> > > > BASE Logic, inc.
> > > > (415) 354-4215
> > > >
> > > > Website: http://baselogic.com
> > > > Blog: http://baselogic.com/blog
> > > > BLiNC Magazine: http://blincmagazine.com
> > > > Linked IN: http://linkedin.com/in/mickknutson
> > > > DJ Mick: http://djmick.com
> > > > MySpace: http://myspace.com/mickknutson
> > > > Vacation Rental: http://tahoe.baselogic.com
> > > >
> > >
> > >
> > >
> > > --
> > > James
> > > -------
> > > http://macstrac.blogspot.com/
> > >
> > > Open Source Integration
> > > http://open.iona.com
> > >
> >
> >
> >
> > --
> > ---
> > Thank You...
> >
> > Mick Knutson
> > BASE Logic, inc.
> > (415) 354-4215
> >
> > Website: http://baselogic.com
> > Blog: http://baselogic.com/blog
> > BLiNC Magazine: http://blincmagazine.com
> > Linked IN: http://linkedin.com/in/mickknutson
> > DJ Mick: http://djmick.com
> > MySpace: http://myspace.com/mickknutson
> > Vacation Rental: http://tahoe.baselogic.com
> >
>
>
>
> --
> ---
> Thank You...
>
> Mick Knutson
> BASE Logic, inc.
> (415) 354-4215
>
> Website: http://baselogic.com
> Blog: http://baselogic.com/blog
> BLiNC Magazine: http://blincmagazine.com
> Linked IN: http://linkedin.com/in/mickknutson
> DJ Mick: http://djmick.com
> MySpace: http://myspace.com/mickknutson
> Vacation Rental: http://tahoe.baselogic.com
>
--
---
Thank You…
Mick Knutson
BASE Logic, inc.
(415) 354-4215
Website: http://baselogic.com
Blog: http://baselogic.com/blog
BLiNC Magazine: http://blincmagazine.com
Linked IN: http://linkedin.com/in/mickknutson
DJ Mick: http://djmick.com
MySpace: http://myspace.com/mickknutson
Vacation Rental: http://tahoe.baselogic.com