我想在camel路由中模拟WS客户端调用,检查请求并提供响应。
这里有一个测试
package com.example.helloworld;
import org.apache.camel.*;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author deveproject
* @version 9/15/14
*/
public class WsClientMockTest extends CamelSpringTestSupport {
@Produce(uri = "direct:test-ws-client-mock")
protected ProducerTemplate template;
@Override
public String isMockEndpoints() {
return "cxf:bean:greeterService";
}
@Test
public void testGetActionRoute() throws Exception {
MockEndpoint greeterService = getMockEndpoint("mock:cxf:bean:greeterService");
greeterService.expectedMessagesMatches(new Predicate() {
@Override
public boolean matches(Exchange exchange) {
assertEquals("U.S.", exchange.getIn().getBody(String.class));
return true;
}
});
template.sendBody("U.S.");
greeterService.assertIsSatisfied();
}
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
}
}
字符串
predicate 检查请求是否正确。我找不到一个方法来提供一个答案。
我有上面测试的工作示例。我可以按需出版。
- 谢谢-谢谢
1条答案
按热度按时间fykwrbwg1#
您可以使用
returnReplyBody(Expession expression)
方法进行模拟响应。字符串