If you've used Wiremock to mock an external service, you know its possible to set the response returned as a String.
When setting the mocked service response, I usually save the response from the real service in the src/test/resource folder and extract the file content using the method below.
Here is how to call the method above fetching the content of a file located in the test resource folder.
When setting the mocked service response, I usually save the response from the real service in the src/test/resource folder and extract the file content using the method below.
private static String getResponse(String path) throws IOException {
return new String(Files.readAllBytes(Paths.get(path)));
}
return new String(Files.readAllBytes(Paths.get(path)));
}
Here is how to call the method above fetching the content of a file located in the test resource folder.
getResponse("src/test/resources/responses/filename.json")
Comments
Post a Comment