Tom, what class reads in the files and mappings and is there a method that could be overridden for a custom implementation?
Yep, you can create your own implementation of FileSource and pass that into the rule or server constructor.
stubFor(any(anyUrl())
.atPriority(10)
.willReturn(aResponse().proxiedFrom("http://mobileapi.jumbo.com")));
// stub config because of http missing in prod
stubFor(any(urlEqualTo("/v2/configuration"))
.atPriority(1)
.willReturn(aResponse()
.withStatus(200)
.withBody(Utils.asset("testdata/configuration.json"))));
/**
* Returns the content of a file in the path
* @param assetPath File path
* @return
*/
public static String asset(String assetPath) {
Context context = getInstrumentation().getContext();
try {
InputStream inputStream = context.getAssets().open(assetPath);
return inputStreamToString(inputStream, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static final int BUFFER_SIZE = 4 * 1024;
private static String inputStreamToString(InputStream inputStream, String charsetName)
throws IOException {
StringBuilder builder = new StringBuilder();
InputStreamReader reader = new InputStreamReader(inputStream, charsetName);
char[] buffer = new char[BUFFER_SIZE];
int length;
while ((length = reader.read(buffer)) != -1) {
builder.append(buffer, 0, length);
}
return builder.toString();
}