我很难为apachecamel路由编写测试用例。我有两条路线定义如下:
重新路由生成器.java
@Override
public void configure() throws Exception {
rest("/test")
.get()
.param().name("UPDATED_DATE").endParam()
.produces(MediaType.APPLICATION_JSON_VALUE)
.to("direct:db");
}
dbroutebuilder.java文件
@Override
public void configure() throws Exception {
from("direct:db")
.log(LoggingLevel.INFO, logger, "Headers: ${header.UPDATED_DATE}")
.bean(Service.class, "testMethod(${header.UPDATED_DATE})")
.split(body(), new AggregateData())
.to("direct:transformer");
}
我尝试过:
public class RestApiRouteBuilderTest extends CamelTestSupport {
@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new RestApiRouteBuilder();
}
@Test
public void testMock() throws Exception {
template.sendBodyAndHeader("rest://get:/test", null, "UPDATED_DATE", "2020-11-11");
final Exchange receive = consumer.receive("direct:db");
System.out.println("Body===>" + receive.getIn().getBody());
// assert logic here
}
}
我得到以下例外:
org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: rest://get:/test?hostname=localhost. Reason: java.lang.IllegalArgumentException: Hostname must be configured on either restConfiguration or in the rest endpoint uri as a query parameter with name host, eg rest:get:/test?host=someserver
有人能帮我理解这个吗?如何在测试类中配置主机名?我找不到解决问题的办法。
暂无答案!
目前还没有任何答案,快来回答吧!