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
  • 102,010
  • 123
  • 446
  • 597

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,378
  • 5
  • 47
  • 79
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,626
  • 2
  • 24
  • 47
0

You can do it with Spring framework and EasyMock.

What's the best mock framework for Java?

Community
  • 1
  • 1
EricParis16
  • 809
  • 5
  • 9