开发者

How to mock entire JAX-RPC communication session?

I have a legacy application, which is working with third-party web service through JAX-RPC. Now I need to unit-test the application by mocking certain XML RPC calls with test data. Actually, I need to replace Apac开发者_运维知识库he Axis, which is used by the application, by some other library that will be JAX-RPC compliant, but will return what I'm telling it to return. I'm pretty sure I'm not alone with such a problem... Are there any open source libraries for this purpose?


You can do it with Spring framework and EasyMock.

What's the best mock framework for Java?


I have had some success with WireMock. It's a Jetty server that you set up programmatically to respond to certain request patterns with content that you also specify. I have been able to set it up to respond to XML-RPC requests from my class. E.g.,

stubFor(post(urlEqualTo("/RPC2"))
        .withRequestBody(containing("<methodName>...</methodName>"))
        .willReturn(aResponse()
            .withBody("<methodResponse>...</methodResponse>")));


For Mocking the calls to external services you can use EasyMock+Powermock or Mockito you can do something like this

Easymock.expect(your function calling external Systems).andReturn(your required output)

hope this helps!

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜