我有以下春天路线:弹簧试验骆驼基于内容的路由
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:topic:inbox" />
<choice>
<when>
<simple>${in.header.Value}</simple>
<log message="Cc: ${in.header.Value}" />
</when>
</choice>
<to uri="mock:result" />
</route>
</camelContext>
我必须使用弹簧试验(CamelSpringJUnit4ClassRunner)的要求,但我发现很容易理解如何测试条件实例与Java DSL。我的测试类是这样的:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(locations = "file:src/main/resources/META-INF/spring/camel-context-activemq-embedded.xml")
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("log:*")
@DisableJmx(false)
public class MyTest{
private Logger LOG = LogManager.getLogger(MyTest.class.getName());
protected Exchange exchange;
protected CustomComponent customComponent= new CustomComponent();
@Produce(uri = "activemq:topic:inbox")
protected ProducerTemplate template;
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Test
public void tes1() throws InterruptedException {
String headerValue= MyComponent.Value;
EmailAddress recipients = new EmailAddress("[email protected]");
template.sendBodyAndHeader("activemq:topic:inbox", recipients.toString(), headerValue);
resultEndpoint.expectedBodiesReceived(headerValue);
resultEndpoint.expectedHeaderReceived("header value", headerValue);
resultEndpoint.expectedMessageCount(1);
}
我努力理解如何测试由CBR所规定的实际情况,但更重要的是,我怀疑这是否是即便是为了测试它的正确方法。 MyComponent.VALUEConstant是在我的自定义组件中指定的属性,上面的测试实际上是通过的。但是,如果我使用组件上的其他属性实例化headerValue,并且因此条件应该失败,则测试会通过。你能帮忙吗?
谢谢
我
嗨,谢谢你的帮助。我相信我对简单表达式本身非常困惑,因为Value是我自定义组件中的一个实际属性(仅由我部分编写)只映射到“Value”。所以,如果我错了,请纠正我的错误,我相信我需要用实际的电子邮件地址创建该值的实例,然后通过sendBodyAndHeader发送它,对吧? – paranza
是的,我以为自己需要有一个端点(模拟)来验证消息是否被接收(在之内)。但是,我无法改变春季路线。有没有什么方法(我真的在寻找)注入另一个模拟,但只有在测试中? –
paranza
我的路线中可以有多个模拟端点吗?我有一些简单的日志:我想验证的消息以及选择条件。 – paranza