You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mikeycmccarthy <Mi...@gmail.com> on 2012/02/21 14:00:37 UTC

Testing a transacted route with CamelTestSupport

Not a big issue but I just switched to transacted routes, and found that the
tests where I extend CamelTestSupport and don't use the Spring context start
failing:

org.apache.camel.FailedToCreateRouteException: Failed to create route route1
at: >>> Policy[ref:null] <<< in route: Route[[From[direct:start]] ->
[Policy[ref:null]]] because of No bean could be found in the registry of
type: PlatformTransactionManager

In these kind of tests I return my route POJO from within the
createRouteBuilder method, normally setting a couple of mocks on it which I
can use for assertions.

Just wondering what the best practice might be in this case. I could move
all these tests to classes where the actual spring context is loaded? Or is
there a way I can change this route to be non transacted within the
createRouteBuilder method?

Thanks


--
View this message in context: http://camel.465427.n5.nabble.com/Testing-a-transacted-route-with-CamelTestSupport-tp5502129p5502129.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Testing a transacted route with CamelTestSupport

Posted by Mikeycmccarthy <Mi...@gmail.com>.
Thanks Christian, that's really useful. 

Is it possible to do this at all without naming the transactional policy
(it's named as required in the test you linked to)? I'm on 2.9.0 of Camel
and it's nice that I can accept the defaults of not needing to explicitly
name my transaction policy.

Thanks!

--
View this message in context: http://camel.465427.n5.nabble.com/Testing-a-transacted-route-with-CamelTestSupport-tp5502129p5536977.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Testing a transacted route with CamelTestSupport

Posted by Christian Müller <ch...@gmail.com>.
This unit test show how it works:
https://svn.apache.org/repos/asf/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlTransactedRouteTest.java

Best,
Christian

On Tue, Feb 21, 2012 at 2:00 PM, Mikeycmccarthy <Mi...@gmail.com>wrote:

> Not a big issue but I just switched to transacted routes, and found that
> the
> tests where I extend CamelTestSupport and don't use the Spring context
> start
> failing:
>
> org.apache.camel.FailedToCreateRouteException: Failed to create route
> route1
> at: >>> Policy[ref:null] <<< in route: Route[[From[direct:start]] ->
> [Policy[ref:null]]] because of No bean could be found in the registry of
> type: PlatformTransactionManager
>
> In these kind of tests I return my route POJO from within the
> createRouteBuilder method, normally setting a couple of mocks on it which I
> can use for assertions.
>
> Just wondering what the best practice might be in this case. I could move
> all these tests to classes where the actual spring context is loaded? Or is
> there a way I can change this route to be non transacted within the
> createRouteBuilder method?
>
> Thanks
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Testing-a-transacted-route-with-CamelTestSupport-tp5502129p5502129.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Testing a transacted route with CamelTestSupport

Posted by "roman.stumm" <ro...@gmx.de>.
When I write a unit-test or use a test-spring.xml, I can use my
DummyTransactionManager like this:

 <bean id="transactionManager"
class="de.viaboxx.spring.DummyTransactionManager"/>

or programmatically:

class MyTest extends CamelTestSupport {

@Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext context = new
DefaultCamelContext(createSimpleRegistry());
        return context;
    }
    private Registry createSimpleRegistry() {
        registry = new SimpleRegistry(); 
        registry.put("transactionManager", new DummyTransactionManager());
        return registry;
    }
}

So I can use transacted() in camel-routes, but without accessing a
JMS-TransactionManager or any DataSource, just as a unit-test...

Here is the class:
public class DummyTransactionManager implements PlatformTransactionManager {
    public TransactionStatus getTransaction(TransactionDefinition
transactionDefinition)
            throws TransactionException {
        return new SimpleTransactionStatus();
    }

    public void commit(TransactionStatus transactionStatus) throws
TransactionException {
    }

    public void rollback(TransactionStatus transactionStatus) throws
TransactionException {

    }
}




--
View this message in context: http://camel.465427.n5.nabble.com/Testing-a-transacted-route-with-CamelTestSupport-tp5502129p5735768.html
Sent from the Camel - Users mailing list archive at Nabble.com.