繁体   English   中英

用Spring配置测试Camel的问题

[英]Problems testing Camel with Spring config

我有一个在CamelRoutes.xml定义的路由,我想通过使用http://camel.apache.org/mock.html底部描述的包装技术来测试它们。

我的CamelRoutes.xml

 <route autoStartup="true"  xmlns="http://camel.apache.org/schema/spring">
        <from uri="direct:start"/>
        <to uri="direct:end"/>
    </route>

所以我创建了CamelRoutesTest.xml其中包含:

<import resource="CamelRoutes.xml"/>
<bean id="mockAllEndpoints" class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>

但我不知道如何创建一个测试,加载spring xml并提供对模拟端点的访问。

如果我用..

@ContextConfiguration( locations=("/CamelRoutesTest"))
public class CamelTest extends AbstractJUnit38SpringContextTests

}

然后我不知道如何获得模拟端点

如果我用..

public class CamelTest extends CamelTestSupport

}

然后我不知道如何加载我的骆驼上下文..

我似乎无法在使用CamelTestSupport的网站上找到一个示例测试并从spring xml加载路由。

汤姆你已经在Camel邮件列表上发布了这个。 我建议您在此处发布Q时也写这个。

答案已经发布在这里http://camel.465427.n5.nabble.com/Problems-testing-Camel-with-Spring-config-tp4267754p4267754.html

解决了使用:

public class CamelTest extends CamelSpringTestSupport {  

    @Override
    protected AbstractXmlApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("/CamelRoutesTest.xml");
    }

    @Test
    @DirtiesContext
    public void discover() throws Exception {

        getMockEndpoint("mock:my.route.out").expectedMessageCount(1);

        template.sendBody("direct:my.route.in", FileUtils.slurpClassPathFile("/samples/sample.data.xml"));

        assertMockEndpointsSatisfied();

    }


}

感谢这个解决方案,@ Tom!

我也很难让Camel使用我的Spring驱动的JUnit测试,问题是建议的CamelSpringJUnit4ClassRunner现在已经从camel-spring.jar转移到一个单独的模块camel-spring-test.jar,这是不可用的从2.9.2开始的标准骆驼分布。

所以我不能使用@RunWith,但不得不诉诸解决方案中描述的手动方法......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM