function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Atul Pandey 4Atul Pandey 4 

Test Class For Batch apex class having webservice callout?

I am New in SFDC development, i have written an apex batch class for webservice callout. please suggest me how can i write the test class for below class.
global class CoDoc implements Database.Batchable, Database.AllowsCallouts {
global final String QODoc; global final String CMOOId; global final boolean V; global final boolean R; global CoDoc( String QODoc , String CMOOId , Boolean V , Boolean R ) { this.QODoc = QODoc; this.CMOOId = CMOOId; this.V = V; this.R = R; } global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(QODoc); } global void execute(Database.BatchableContext BC, List<sObject> scope){ List <Cust> CMO = [SELECT Id ,OpNumber__c ,R_No__c ,V_No__c FROM Cust WHERE id = :CMOOId ]; String EndPoingtUrl = Label.EndPointURL; String APIKey = Label.API_Key; if( V== true && R == false ) { for(Sobject sObj : scope) { Document__c Doc = (Document__c)sObj; Integer countL = Doc.Name.Length()- Doc.Name.replace('_','').Length(); String newName = CMO[0].OpNumber__c +'_V'+ CMO[0].V_No__c +'_R'+ CMO[0].R_No__c +'_'+ Doc.Name.split('_',countL).get(countL-1); Http h = new Http(); HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); req.setEndpoint(EndPoingtUrl+Doc.TId__c+'?api_key='+APIKey); req.setMethod('GET'); req.setHeader('Accept', 'application/json'); res = h.send(req); //Server has send the Response if( res.getStatusCode() == 200 && !String.isEmpty( res.getBody()) ){ String resBody = res.getBody(); Map< String , Ids__c > IdsMap = Ids__c.getall(); for( String templateIsStr : IdsMap.keySet() ) { if( resBody.contains(templateIsStr) ){ //Instantiate a new HTTP object Http http = new Http(); //Instantiate a new http request, specify the method (POST) as well as the endpoint HttpRequest req1 = new HttpRequest(); HttpResponse res1 = new HttpResponse(); req1.setBody('{"p":{"n": "'+newName+'","int_id":"'+CMO[0].Id+'"}}'); req1.setEndpoint(EndPoingtUrl+Doc.TId__c+'/duplicate?api_key='+APIKey); req1.setMethod('POST'); req1.setHeader('Content-Type', 'application/json ;charset=UTF-8'); req1.setHeader('Accept', 'application/json'); req1.setTimeOut(60000); res1 = http.send(req1); } } } } } } global void finish(Database.BatchableContext BC){ }