You need to sign in to do that
Don't have an account?
guptach45
Test class for controller.PLease Help
public class DivAC_14_IntegrationController {
public static HttpResponse makeCallOut(String requestBody,String END_POINT){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(END_POINT);
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setMethod('POST');
request.setBody(requestBody);
request.setTimeout(45000);
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
system.debug('body--->'+response.getBody());
}else{
system.debug('response--->'+response);
}
return response;
}
}
public static HttpResponse makeCallOut(String requestBody,String END_POINT){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(END_POINT);
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setMethod('POST');
request.setBody(requestBody);
request.setTimeout(45000);
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
system.debug('body--->'+response.getBody());
}else{
system.debug('response--->'+response);
}
return response;
}
}
You could test the callouts in two ways as mentioned in https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing.htm this article, you could choose one to cover the class method.
Please find an example below for quick reference that is mentioned in the article:
Test Class:
I hope this helps in having a reference to implement for your usecase, do let me know if there are any question to assist further, in case if this came in handy for your implementation could you please mark this as best answer so that it could be used by others in the future.
Regards,
Anutej