Created
October 19, 2012 14:14
-
-
Save metadaddy/3918438 to your computer and use it in GitHub Desktop.
MultiJSONResponseCalloutMock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class MultiJSONResponseCalloutMock implements HttpCalloutMock { | |
private HTTPResponse res; | |
private Map<String, String> m; | |
global MultiJSONResponseCalloutMock() { | |
this.res = new HTTPResponse(); | |
this.m = new Map<String, String>(); | |
this.res.setStatusCode(200); | |
this.res.setStatus('OK'); | |
} | |
global void setJSONResponse(String url, String jsonResponse) { | |
this.m.put(url, jsonResponse); | |
} | |
global void setStatusCode(integer code) { | |
this.res.setStatusCode(code); | |
} | |
global void setStatus(String status) { | |
this.res.setStatus(status); | |
} | |
global void setHeader(String key, String val) { | |
this.res.setHeader(key, val); | |
} | |
global HTTPResponse respond(HTTPRequest request) { | |
String json = this.m.get(request.getEndpoint()); | |
this.res.setBody(json); | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment