我需要为使用CXF组件调用SOAP web服务的Camel路由编写一些单元测试。
跳过SOAP请求并返回stubbed响应的最干净的方法是什么?
我尝试使用模拟endpoint,但是请求要么被传递到真正的endpoint,要么在WhenanyExchangeReceed
处理器回调时被忽略。
我用Blueprint配置Camel,并用camel-test-blueprint 2.17.1运行它。这就是我的Blueprint.xml配置的样子。
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder id="routeConfiguration"
persistent-id="my.app" />
<camelcxf:cxfEndpoint id="myWebService"
address="${myWebService.url}"
wsdlURL="classpath:wsdl/MyWebService.wsdl"
serviceClass="my.web.service.Ws"
serviceName="s:MyWebServiceImpl"
xmlns:s="http://mywebservice.it/"/>
<camelContext trace="false" id="myCamelContext"
xmlns="http://camel.apache.org/schema/blueprint">
<propertyPlaceholder location="blueprint:routeConfiguration" />
<route id="IwantToStubInsideHere">
<from uri="activemq:someQueue"/>
<to uri="cxf:bean:myWebService"/>
<to uri="direct:processWebServiceResponse"/>
</route>
</camelContext>
</blueprint>
测试类
public class RouteTest extends CamelBlueprintTestSupport {
@Override
public String isMockEndpointsAndSkip() {
return "cxf*";
}
@Test
public void testMethod() {
MockEndpoint mockEndpoint = getMockEndpoint("mock:cxf:bean:myWebService");
mockEndpoint.expectedMessageCount(1);
mockEndpoint.whenAnyExchangeReceived(new StubWsProcessor());
// run route here
}
}
我在张贴我的解决方案。我从路由中完全删除了CXF bean,并用一个属性替换了它的endpoint。在测试期间,属性值被更改为适当的endpoint,例如direct:something
。
我的设置有点复杂,因为它涉及到动态路由器,但要点如下:
<cm:property-placeholder id="routeConfiguration"
persistent-id="my.app">
<cm:default-properties>
<cm:property name="cxfEndpoint" value="cxf:bean:myWebService"/>
</cm:default-properties>
</cm:property-placeholder>
.....
<route id="IwantToStubInsideHere">
<from uri="activemq:someQueue"/>
<to uri="${cxfEndpoint}"/>
<to uri="direct:processWebServiceResponse"/>
</route>
默认值对于生产使用是可以的,并且只有在测试期间通过在适当的my.app.cfg文件中定义cxfendpoint
来重写默认值。
我正在尝试使用Cypress存根一个模块。这是我到目前为止尝试过的,但不起作用。 这是我的组件/页面的简短版本 这是我定制的钩子的样子 下面是getData的外观 方法通过db.js(实际上是db/index.js)公开 我正在尝试存根getData。js使e2e测试更加一致。这就是我所做的。 上面的存根不起作用。运行测试时,对外部服务的API调用仍在进行。文档本身让我推断我应该这样写,但它不起作
我创建了express应用程序,有一条路线可以使用许多中间件: 这是我的中间件。js: 它工作得很好。但当我试着写测试时遇到了问题。这是我的测试,我使用mocha、chai、supertest和sinon: 问题是什么 您可以看到有3个存根,1个用于,2个用于在路由的同一个文件中。 问题是,2个存根工作,而1个用于<代码>中间件。saveUser不工作,请始终触发原始用户。 我想,当我调用setu
问题内容: 我曾经使用过JUnit和Mocks,但我想知道,JUnit中的Mocks和Stub之间有什么区别,以及如何在JUnit,Java中使用Stub?作为具有EasyMock,Mockito等的Mocks,Stubs在Java中使用什么? 请提供Java中的存根示例代码。 问题答案: 要在junit中使用存根,您不需要任何框架。 如果您想存根某些接口,只需实现它: 然后创建一个新的存根对象并
如果我已经通过< code > var a = sinon . createstuinstance(my contractor)创建了一个实例。 如何替换其中一个存根函数,如 。 我这样做的主要原因是想实现这个提到的多个回调解决方法
我正在尝试使用typescript、mocha、sinon和chai http为我的express路由器编写一个集成测试。这个路由器使用我编写的自定义中间件,它检查头中的JWT。 理想情况下,我想存根我的authMiddleware,这样我就可以控制它的行为,而不必为每个测试用例提供有效/无效的JWT。 当我尝试在测试中存根时,我意识到Express使用的实际实现,而不是模拟的实现。 在模拟aut