-
-
Save noeticpenguin/b71ef196ebd2114e6d4e to your computer and use it in GitHub Desktop.
mockClass
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
@isTest | |
public class RestClientHTTPMocks implements HttpCalloutMock { | |
Protected Integer code; | |
Protected String status; | |
Protected String bodyAsString; | |
Protected Blob bodyAsBlob; | |
Protected Map<String, String> responseHeaders; | |
/* | |
* Constructors. | |
*/ | |
public RestClientHTTPMocks(Integer code, String status, String body, Map<String, String> responseHeaders) { | |
this.code = code; | |
this.status = status; | |
this.bodyAsString = body; | |
this.bodyAsBlob = null; | |
this.responseHeaders = responseHeaders; | |
} | |
/* | |
* This is the interface method need to implement. | |
*/ | |
public HTTPResponse respond(HTTPRequest req) { | |
// craft the return response. | |
HttpResponse res = new HttpResponse(); | |
res.setStatusCode(this.code); | |
res.setStatus(this.status); | |
res.setBody(this.bodyAsString); | |
if (responseHeaders != null) { | |
for (String key : this.responseHeaders.keySet()) { | |
res.setHeader(key, this.responseHeaders.get(key)); | |
} | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment