我有一个CarService类:
public class CarService {
public Car getCar(){
Car car = new Car();
car.setBrand("hello");
car.setId("1");
return car;
}
}
我使用在通过CDI注入的RouteBuilder中定义的camel restdsl通过jetty端点公开。
restConfiguration().component("jetty")
.host("localhost")
.port("8889")
.bindingMode(RestBindingMode.json);
rest("/cars").get().route().bean(CarService.class, "getCar");
这是我的单元测试
@Test
public void restTest() throws Exception {
Main booter = new Main();
booter.start();
HttpResponse<JsonNode> carResponse =
Unirest.get("http://localhost:8889/cars").asJson();
String s = carResponse.getBody().toString();
assertEquals("{\"id\":\"1\",\"brand\":\"hello\"}", s);
booter.stop();
}
主要来自 org.apache.camel.cdi
我正在使用uniRest发送HTTP请求(http://unirest.io/java.html)
运行单元测试时,它会通过,但如果我在getCar()方法中放置一个断点,则不会触发断点。
RMQ: 我也尝试过使用producerTemplate
List<CamelContext> contexts = ngbaMain.getCamelContexts();
FluentProducerTemplate fpt = DefaultFluentProducerTemplate.on(contexts.get(0));
Object result = fpt.to("jetty:http://localhost:8889/cars?httpMethodRestrict=GET")
.request(String.class);
但它也不起作用......
有人能给我一些见解,我怎么能这样做?这是可能的......测试端点会很棒......
更新
我正在使用 IntelliJ 进行测试,如果我在以下行中点击F7:
HttpResponse<JsonNode> carResponse =
Unirest.get("http://localhost:8889/cars").asJson();
这就是我踏入(奇怪的是只有一两个F7命中就足够了)我进入我的CarService ......所以也许它比骆驼或码头或者......更像是一个intellij的东西。
答案 0 :(得分:0)
正如我在UPDATE提出的问题中所述,当我走进一个无法上课然后恢复时,我可以点击断点。所以这更像是IDE相关的问题。