3

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 Apache 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?

yegor256
  • 97,508
  • 114
  • 426
  • 573

3 Answers3

0

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>")));
Chry Cheng
  • 3,298
  • 5
  • 45
  • 77
0

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!

Vihar
  • 3,543
  • 2
  • 22
  • 43
0

You can do it with Spring framework and EasyMock.

What's the best mock framework for Java?

Community
  • 1
  • 1
EricParis16
  • 769
  • 4
  • 8