- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Camel 新手,我需要了解如何对具有两个端点的路线进行单元测试。第一个端点获取用户 ID 并将其用于第二个端点。
public RouteBuilder routeBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws HttpOperationFailedException {
this.from(MyServiceConstant.ROUTE)
.setHeader(...)
.setHeader(...)
.to(MyConstants.THE_FIRST_ROUTE)
.setHeader(...)
.setHeader(...)
.process(...)
.setProperty(...)
.to(MyConstants.THE_SECOND_ROUTE)
}
};
}
所以我必须在我的测试类中模拟 MyConstants.THE_FIRST_ROUTE 和 MyConstants.THE_SECOND_ROUTE 。我这样做了,但不知道如何编写测试。我所做的只是到达第二个端点,但不知道如何触发第一个端点。
@Produce(uri = MyServiceConstant.ROUTE)
private MyService myService;
@EndpointInject(uri = "mock:" + MyConstants.THE_FIRST_ROUTE)
private MockEndpoint mockFirstService;
@EndpointInject(uri = ""mock:" + MyConstants.THE_SECOND_ROUTE)
private MockEndpoint mockSecondService;
@Test
@DirtiesContext
public void getDetails()throws Exception {
// **The missing part**: Is this the right way to call my first service?
this.mockFirstService.setUserId("123456");
// this returns a JSON that I'll compare the service response to
this.mockSecondService.returnReplyBody(...PATH to JSON file);
UserDetail userDetailsInfo = this.myService.getUserDetails(...args)
// all of my assertions
assertEquals("First name", userDetailsInfo.getFirstName());
MockEndpoint.assertIsSatisfied();
}
最佳答案
我今天有时间使用 Camel Spring boot 原型(prototype)快速破解一些演示代码。开始了。我的路线从计时器组件生成消息。不使用向端点的显式传递。
//Route Definition - myBean::saySomething() always returns String "Hello World"
@Component
public class MySpringBootRouter extends RouteBuilder {
@Override
public void configure() {
from("timer:hello?period={{timer.period}}").routeId("hello_route")
.transform().method("myBean", "saySomething")
.to("log:foo")
.setHeader("test_header",constant("test"))
.to("log:bar");
}
}
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
public class MySpringBootRouterTest {
@Autowired
SpringCamelContext defaultContext;
@EndpointInject("mock:foo")
private MockEndpoint mockFoo;
@EndpointInject("mock:bar")
private MockEndpoint mockBar;
@Test
@DirtiesContext
public void getDetails() throws Exception {
assertNotNull(defaultContext);
mockBar.expectedHeaderReceived("test_header", "test");
mockBar.expectedMinimumMessageCount(5);
MockEndpoint.setAssertPeriod(defaultContext, 5_000L);
MockEndpoint.assertIsSatisfied(mockFoo, mockBar);
mockFoo.getExchanges().stream().forEach( exchange -> assertEquals(exchange.getIn().getBody(),"Hello World"));
//This works too
//mockBar.assertIsSatisfied();
//mockFoo.assertIsSatisfied();
}
@Before
public void attachTestProbes() throws Exception {
//This is Camel 3.0 API with RouteReifier
RouteReifier.adviceWith(defaultContext.getRouteDefinition("hello_route"), defaultContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
//Hook into the current route, intercept log endpoints and reroute them to mock
interceptSendToEndpoint("log:foo").to("mock:foo");
interceptSendToEndpoint("log:bar").to("mock:bar");
}
});
}
}
对 future 访问者的警告:此处的测试用例演示了如何使用 mock:
拦截 log:
端点并对其设置期望。测试用例可能没有测试任何有值(value)的东西。
关于java - Camel : How to mock a route with two endpoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58311414/
我正在使用 winsock 和 C++ 来设置服务器应用程序。我遇到的问题是对 listen 的调用会导致第一次机会异常。我想通常这些可以忽略(?),但我发现其他人也有同样的问题,它导致应用程序偶尔挂
我对 Wireguard 的理解是服务器和客户端的接口(interface)(虽然看起来听不清?)每个都有自己的 .conf 文件。例如,考虑以下 .conf 文件。 [Interface] Priv
如何将多个实体从客户端传递到 Google Cloud Endpoint? 例如,传递单个实体很容易在服务器的 Endpoint api 源文件中完成: public class SomeEndpoi
我试图建立一个路径来将文件从一个目录复制到另一个目录。但不是使用:从(文件://源目录)到(文件://目标目录)我想做这样的事情: from(direct:start) .to(direct:do
我有一个非常小的网站,在 Azure 上以共享托管配置运行。我上面有一堆涉及打开套接字的网络代码,所有这些代码都成功运行。 我编写了一些发送 ping 的代码,但抛出了 PingException,内
我试图了解如何将 Cloud Endpoints 与自定义身份验证结合使用。从文档中我了解到它从 securityDefinitions 开始: securityDefinitions: yo
我在理解有关此文档的过程中遇到了一些麻烦。位于 ... https://developers.google.com/appengine/docs/java/endpoints/consume_js 具
我一直在尝试在生成的 Endpoint 类中创建一些新方法,但发现了这种奇怪的行为:我可以向生成的类添加一个方法,但我无法添加其中两个方法,无论我选择这两个方法中的哪一个添加。这是我生成的类的代码,我
azure 中的“输入端点”和“内部端点”是什么?如何创建新的“输入端点”? &如何将数据发送到“输入端点”? 输入端点端口 65400 端口是什么? 最佳答案 输入端点是云服务和 Internet
首先,对您可能犯的语法错误表示歉意。我的英语不是很好。 我是 Spring 新手,我正在尝试创建基本身份验证安全性。 我正在尝试配置一个端点具有公共(public)访问权限,而其他端点则具有用户访问权
我试图让图标部分包含我自己的图标,而不是通过尝试猴子补丁 ApiConfigGenerator.get_descriptor_defaults 来谷歌搜索图标。不幸的是,当发现文档完成时,这些将被忽略
我正在尝试跟随初学者到 WCF 页面上的演示视频 MSDN . 第一个视频或多或少地工作得很好。我现在接近第二个视频的结尾。我使用的是 VS2010/.NET 4.0,而视频似乎使用的是 VS2008
这个问题完全来自我在这里问过(并得到回答)的相关问题:Error when trying to retrieve a single entity 据我了解,要使用已提供的辅助方法以外的属性(例如 'i
WSL1 没有问题。我想升级到 WSL 2。 当我尝试升级到 wsl2 时,命令行失败。我试图删除 Ubuntu 并重新安装它,没有区别。 虚拟机平台处于事件状态。 Windows 内部版本号:190
我有一个代理lambda函数的AWS api。我目前使用不同的端点和单独的 lambda 函数: api.com/getData --> getData api.com/addData --> add
我正在构建一个 Chrome 应用,我真的希望它能够通过云端点与我的服务器进行通信,但有两个问题我不确定如何克服: Google apis javascript 库是一个外部脚本,我无法在 Chrom
我正在我的 gke 集群上运行 kubernetes 1.9.4 我有两个 pod,gate,它正在尝试连接到 coolapp,它们都是用 elixir 编写的 我正在使用libcluster连接我的
阅读Where to place the Asynctask in the Application和 http://android-developers.blogspot.com/2009/05/pa
我不清楚 @Named 在 Google Cloud Endpoints 中的用途。文档说: This annotation indicates the name of the parameter i
我正在关注 Getting Started guide对于使用 Maven 的 Java 中的 Google Cloud Endpoints,我无法使用 API Explorer 访问我的端点。 尽管
我是一名优秀的程序员,十分优秀!