camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eirilwan <eiril...@gmail.com>
Subject Using mockito to mock endpoint behavior
Date Thu, 27 May 2010 12:51:20 GMT

Hi

When upgrading from Camel 2.1.0 to 2.3.0 we encountered a problem using
Mockito to mock endpoint behaviour while testing camel routes. 

Our test is running with junit4 using Spring context configuration. We
inject mockito mocked endpoints into both the test and the route like this: 

    @Produce(uri = "mock:successConsumer")
    protected MockEndpoint successConsumer;

    @Resource(name = "testRepo")
    protected TestRepository someRepo;

The TestRepo is created in spring using XML configuration: 
    <bean id="someRepo" class="org.mockito.Mockito" factory-method="mock">
        <constructor-arg value="xxx.xxx.TestRepository"/>
    </bean>


The code we try to test is: 
        from("direct:calveConsumer")
                .bean(someRepo, "someRepoMethod").to(successConsumer)


When running the test, camel don't seem to find the someRepoMethod on the
"someRepo" bean. We have tracked down the problem to getTargetClass in
org.apache.camel.component.bean.BeanInfo.class. 

Since mockito is using cglib for enhancing interfaces, this method return
the superclass of the mock, which is Object. This behaviour will work fine
when an object is enhanced with cglib, but not when you use cglib to enhance
an  interface. 

An solution could be to check if the class before $$ is an interface and
return it if it is. 

Any thoughts? 

Our solution right now is to create real mock stubs of all interfaces to
work around the problem. 

regards
Eirik L. Wang

-- 
View this message in context: http://old.nabble.com/Using-mockito-to-mock-endpoint-behavior-tp28693620p28693620.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message