使用Mockito的Camel路线中使用的模拟服务



我正在尝试模拟一个服务,以便模拟的服务可以在骆驼路由中使用。但当我尝试使用方法findByStatus时,它给出了以下异常:

Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route jobRoute at: >>> Transform[bean{camelJobService, method=findByStatus}] <<< in route: Route(jobRoute)[[From[direct:start]] -> [Transform[bean{came... because of org.apache.camel.component.bean.MethodNotFoundException: Method with name: findByStatus not found on bean: Mock for CamelJobService, hashCode: 1172605816 of type: com.sun.proxy.$Proxy104
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1072)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:944)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3245)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2968)
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:172)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2799)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2795)
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2818)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2795)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2764)
    at org.apache.camel.test.spring.CamelSpringTestContextLoader$7.execute(CamelSpringTestContextLoader.java:515)
    at org.apache.camel.test.spring.CamelSpringTestHelper.doToSpringCamelContexts(CamelSpringTestHelper.java:92)
    at org.apache.camel.test.spring.CamelSpringTestContextLoader.handleCamelContextStartup(CamelSpringTestContextLoader.java:509)
    at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:164)
    at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:87)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    ... 45 more
Caused by: org.apache.camel.RuntimeCamelException: org.apache.camel.component.bean.MethodNotFoundException: Method with name: findByStatus not found on bean: Mock for CamelJobService, hashCode: 1172605816 of type: com.sun.proxy.$Proxy104
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1642)
    at org.apache.camel.model.language.MethodCallExpression.validateHasMethod(MethodCallExpression.java:247)
    at org.apache.camel.model.language.MethodCallExpression.createExpression(MethodCallExpression.java:204)
    at org.apache.camel.model.language.ExpressionDefinition.createExpression(ExpressionDefinition.java:177)
    at org.apache.camel.model.TransformDefinition.createProcessor(TransformDefinition.java:57)
    at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:534)
    at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:495)
    at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:219)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1069)

我的camel-context.xml:

<bean id="camelJobService" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="target"> <bean class="org.mockito.Mockito" factory-method="mock"> <constructor-arg value="com.asklytics.camel.db.service.CamelJobService" /> </bean> </property>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <spring:route id="jobRoute" startupOrder="2">
        <spring:from uri="direct:start"/>
        <spring:transform>
            <spring:method ref="camelJobService" method="findByStatus"></spring:method>
        </spring:transform>
        <to uri="mock:result"/>
    </spring:route>
</camelContext>

我知道在mock bean服务上找不到方法findByStatus。但是,我如何才能嘲笑这项服务,让它能够找到它呢?

我认为你不能那样嘲笑bean。您只能模拟端点,这是有意义的,因为端点可能不可用。你为什么要嘲笑豆子?请参阅文档。http://camel.apache.org/mock.html

相关内容

  • 没有找到相关文章

最新更新