• himanshu Soni 31
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
public class corona {

public List<coronawrap> ConsoleWrapperList{get;set;}
public List<coronawrap> ConsoleWrapperList2{get;set;}
    
 public static String str{get; set;}
 public String str2{get; set;}
 

public List<coronawrap> getperformcallout(){

ConsoleWrapperList = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/countries');

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    

return consolewrapperlist;

}
public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        for(coronawrap crRec : ConsoleWrapperList){
            options.add(new SelectOption(crRec.Slug , crRec.Country ));
        }   
        return options;
    }
 public  List<coronawrap> getperformcallout2(){
  ConsoleWrapperList2 = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/total/country/'+str);

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList2=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    
return ConsoleWrapperList2;

}
public void open()
    {
      ConsoleWrapperList2 = new List<coronawrap>();
       for(coronawrap c : ConsoleWrapperList)
           ConsoleWrapperList2.add(c); 
    }
}
public class corona {

public List<coronawrap> ConsoleWrapperList{get;set;}
public List<coronawrap> ConsoleWrapperList2{get;set;}
    
 public String str{get; set;}
 public String str2{get; set;}
 

public List<coronawrap> getperformcallout(){

ConsoleWrapperList = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/countries');

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    

return consolewrapperlist;

}
public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        for(coronawrap crRec : ConsoleWrapperList){
            options.add(new SelectOption(crRec.Slug , crRec.Country ));
        }   
        return options;
    }
 public List<coronawrap> getperformcallout2(){
  ConsoleWrapperList2 = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/total/country/'+str);

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList2=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    
return ConsoleWrapperList2;

}
public void open()
    {
      ConsoleWrapperList2 = new List<coronawrap>();
       for(coronawrap c : ConsoleWrapperList)
           ConsoleWrapperList2.add(c); 
    }
}
apex class


public class corona {

public List<coronawrap> ConsoleWrapperList{get;set;}
public List<coronawrap> ConsoleWrapperList2{get;set;}
    
 public String str{get; set;}
 public String str2{get; set;}
 

public List<coronawrap> getperformcallout(){

ConsoleWrapperList = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/countries');

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    

return consolewrapperlist;

}
public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        for(coronawrap crRec : ConsoleWrapperList){
            options.add(new SelectOption(crRec.Slug , crRec.Country ));
        }   
        return options;
    }
 public List<coronawrap> getperformcallout2(){
  ConsoleWrapperList2 = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/total/country/'+str);

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList2=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    
return ConsoleWrapperList2;

}
public void open()
    {
      ConsoleWrapperList2 = new List<coronawrap>();
       for(coronawrap c : ConsoleWrapperList)
           ConsoleWrapperList2.add(c); 
    }
}

// controller //

<apex:page controller="corona" title="JSON table" >

<apex:form >

<apex:pageBlock >
<apex:selectList size="1" value="{!str}">
           PickList from CallOut : &nbsp; <apex:selectOptions value="{!items}"/>
</apex:selectList> 
  

<apex:commandButton action="{!open}" value="GetCall" reRender="detail"/>
      <apex:pageBlock id="detail" >
    </apex:pageBlock>             


<apex:pageBlockTable value="{!performcallout}" var="wrap" width="100%">

<apex:column headerValue="country" value="{!wrap.Country}"/>
<apex:column headerValue="Slug" value="{!wrap.Slug}"/>
 

</apex:pageBlockTable>
    
    
    
<apex:pageBlockTable  value="{!performcallout2}" var="wrap" width="100%">

<apex:column headerValue="country" value="{!wrap.Country}"/>
<apex:column headerValue="Slug" value="{!wrap.Slug}"/>
<apex:column headerValue="Confirmed" value="{!wrap.Confirmed}"/>
 

</apex:pageBlockTable>
    

</apex:pageBlock>
    

</apex:form>

</apex:page>

// wrapper class //


public class coronawrap {

public String Country{get;set;}
public String Slug{get;set;}
public integer Confirmed{get;set;}
public integer Deaths{get;set;}
public integer Recovered{get;set;}
}
public class corona {

public List<coronawrap> ConsoleWrapperList{get;set;}
public List<coronawrap> ConsoleWrapperList2{get;set;}
    
 public String str{get; set;}
 public String str2{get; set;}
 

public List<coronawrap> getperformcallout(){

ConsoleWrapperList = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/countries');

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    

return consolewrapperlist;

}
public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        for(coronawrap crRec : ConsoleWrapperList){
            options.add(new SelectOption(crRec.Slug , crRec.Country ));
        }   
        return options;
    }
 public List<coronawrap> getperformcallout2(){
  ConsoleWrapperList2 = new List<coronawrap>();

  

HttpRequest req = new HttpRequest();

HttpResponse res = new HttpResponse();

Http http = new Http();
    

req.setEndpoint('https://api.covid19api.com/total/country/'+str);

req.setMethod('GET');

res = http.send(req);

if(res.getstatusCode() == 200 && res.getbody() != null){

ConsoleWrapperList2=(List<coronawrap>)json.deserialize(res.getbody(),List<coronawrap>.class);

}
    
return ConsoleWrapperList2;

}
public void open()
    {
      ConsoleWrapperList2 = new List<coronawrap>();
       for(coronawrap c : ConsoleWrapperList)
           ConsoleWrapperList2.add(c); 
    }
}
Hi Please help write test class and get code coverage for my class

Class:-
public class IssuersCalloutController{

    public IssuersCalloutController(ApexPages.StandardController controller) {

    }


public PageReference saveCalloutResult(){
         
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://test/getIssueList');
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('Accept','application/json');
         system.debug('request endpoint '+ req);    
        String username = 'amit';
        String password = 'password';
        
        Blob headerValue= Blob.valueOf(username + ':' + password);
        system.debug('headerValue'+ headerValue);
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setTimeout(60000);
        
        system.debug('###req### '+ req);            
        HttpResponse res = h.send(req);
        system.debug('###res### '+ res);
        
        string response = res.getBody();
        system.debug('response'+ response);
               
                
        Set<String> bankNames = New Set<String>();
        // declare issuer list to inser 
        List<Issuers__c> InsertedIssuers = New List<Issuers__c>();
        // I used limit in below query, but its better to use any filter to limit the data
        for(Issuers__c issuer : [Select Id,Bankdir_Name__c from Issuers__c LIMIT 50000]){
           If(!string.isBlank(issuer.Bankdir_Name__c)){
             bankNames.add(issuer.Bankdir_Name__c);
             
             //system.debug('###Bank Name### '+ bankNames); 
             //system.debug('issuerbankdir'+ issuer.Bankdir_Name__c);
            }
        }
        system.debug('###Bank Name### '+ bankNames.size());
        List<JsonParserDetail> responseDetails = JsonParserDetail.parse(response); 
        system.debug('****responseDetails****** '+responseDetails);
        
        if(responseDetails.size() > 0){
            for(JsonParserDetail jpd : responseDetails){
                If(!bankNames.contains(jpd.issuerBankdirName)){                
                 InsertedIssuers.add(getIssuer(jpd.issuername,jpd.issuerBankdirName,jpd.processorName,jpd.subProcessorName,jpd.siloName));
                }
            }
        }
        If(InsertedIssuers.size() >0){
            insert InsertedIssuers;
            
      
        }
        PageReference p = apexPages.currentPage();
      ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.CONFIRM,'Preview 2 list Successfully updated'+InsertedIssuers.size()+'"Thank you!');
      ApexPages.addMessage(msg);
      return p;
    }
  public Issuers__c getIssuer(string iName, string ibName, string pName, string spName,string siloName){
        Issuers__c issuer = New Issuers__c();
        issuer.Name = iName;
        issuer.Bankdir_Name__c = ibName;
        issuer.Processor_Name__c = pName;
        issuer.SubProcessor_Name__c = spName;
        issuer.Silo_Name__c = siloName;
        return issuer;
    }
}

Thanks
i have created
1.AnimalLocator User-added image



2.AnimalLocatorMock
User-added image

3.AnimalLocatorTest

User-added image


error i am getting

User-added image

please help me