11 Replies Latest reply on Aug 29, 2012 9:12 AM by Gareth Healy

    Unit testing a route with a from activemq

    Gareth Healy Newbie

      I am trying to unit test a route - i am using blueprints - which uses active mq (see below)

       

       

       

      I then have this in my java code:

       

      protected CamelContext createCamelContext() throws Exception {

          CamelContext camelContext = super.createCamelContext();

          camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"));

       

          return camelContext;

      }

       

      But when i try to run the test, it times out and fails with the following:

       

      java.lang.RuntimeException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext)

           at com.boohoo.blueprint.test.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:170)

           at com.boohoo.blueprint.test.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:130)

           at com.boohoo.blueprint.test.CamelBlueprintTestSupport.createCamelContext(CamelBlueprintTestSupport.java:90)

           at com.boohoo.esb.common.tests.route.Test_Route_loggingWithObject.createCamelContext(Test_Route_loggingWithObject.java:30)

           at org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:234)

           at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:204)

           at com.boohoo.blueprint.test.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:40)

           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

           at java.lang.reflect.Method.invoke(Method.java:597)

           at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

           at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

           at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

           at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

           at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

           at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:47)

           at org.junit.rules.RunRules.evaluate(RunRules.java:18)

           at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

           at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

           at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

           at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

           at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

           at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

           at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

           at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

           at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:249)

           at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:142)

           at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)

           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

           at java.lang.reflect.Method.invoke(Method.java:597)

           at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)

           at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)

           at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)

           at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:104)

           at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

       

      Is what i am doing possible? because i think it is. I am wanting to "mock" the activemq component so i dont have to change the xml file to be a direct.

       

      Hope the above makes sense.

      Cheers.

       

      Edited by: garethahealy on Aug 23, 2012 11:17 AM