I'm working on my integration-tests and I want to mock API calls with Java's MockServer. MockServersClient have a method which mocks response but only by string as a parameter. Example:
new MockServerClient("localhost", 1080)
.when(
request()
)
.respond(
response()
.withBody("some_response_body")
);
I have a service method that returns object I want as a response and I planned to access data by calling that service method and then pass it as response to already mentioned MockServer's method in .withBody()
.
Something like:
new MockServerClient("localhost", 1080)
.when(
request()
)
.respond(
response()
.withBody(new MyServiceClass().callMyServiceMethod())
);
I guess I need to convert that response I get from service method but how?