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
Valentina Doda 7Valentina Doda 7 

test clasess for web services

Hi there,

I a trying to start a test class for this apex class but I find it difficult to construct the test class. Can sb please help?

The apex class is: 

public with sharing class OCSRecuperaCampagneC5SASInvoker { public class OCSRecuperaCampagneC5SASInvokerRequest extends APIRequest { public String serviceId = 'recuperaCampagneC5SAS'; public Map<String, String> companyType = new Map<String, String>{'value' => 'COMPASS'}; public String authorization; public Map<String, String> recuperaCampagneC5SASRequest; public OCSRecuperaCampagneC5SASInvokerRequest(String codFiscale) { this.recuperaCampagneC5SASRequest = new Map<String, String>{'codFiscale' => codFiscale, 'codCliente' => ''}; } } public class OCSRecuperaCampagneC5SASInvokerResponse extends APIResponse { public Integer resultCode; public String resultMessage; public Map<String, String> recuperaCampagneC5SASResponse; } public static Boolean isValidSASFiscalCode(String fiscalCode, Date dueDate) { Boolean isValid = false; OCSRecuperaCampagneC5SASInvokerRequest request = new OCSRecuperaCampagneC5SASInvokerRequest(fiscalCode); OCSRecuperaCampagneC5SASInvokerResponse response = (OCSRecuperaCampagneC5SASInvokerResponse)ApiUtils.callApi('ocs.recuperaCampagneC5SAS', request, OCSRecuperaCampagneC5SASInvokerResponse.class); System.debug('---> OCSRecuperaCampagneC5SASInvokerResponse: ' + response); if(response.resultMessage == 'OK' && response.recuperaCampagneC5SASResponse != null && String.isNotBlank(response.recuperaCampagneC5SASResponse.get('codFiscale')) && response.recuperaCampagneC5SASResponse.get('codFiscale').trim() == fiscalCode && String.isNotBlank(response.recuperaCampagneC5SASResponse.get('dataEstrazione'))) { Date dataEstrazione = Date.valueOf(response.recuperaCampagneC5SASResponse.get('dataEstrazione')); isValid = dataEstrazione <= dueDate && dataEstrazione.daysBetween(dueDate) <= 180; } return isValid; } public static Boolean isValidSASFiscalCode(String fiscalCode) { return isValidSASFiscalCode(fiscalCode, System.today()); } public static String getOpportunitySourceCode(String fiscalCode, Date dueDate) { return isValidSASFiscalCode(fiscalCode, dueDate) ? 'L02' : 'L00'; } public static String getOpportunitySourceCode(String fiscalCode) { return getOpportunitySourceCode(fiscalCode, System.today()); } public class FlowInputVariables { @InvocableVariable(Required = true) public String fiscalCode ; @InvocableVariable(Required = true) public Date dueDate; } public class FlowOutputVariables { @InvocableVariable public Boolean isValidSASFiscalCode; @InvocableVariable public String opportunitySourceCode; } @InvocableMethod(Callout=true Label='Check Codice Fiscale SAS' Description='Restituisce true se il codice fiscale è presente su SAS e la relativa data di estrazione è ancora valida.') public static List<FlowOutputVariables> isValidSASFiscalCode(List<FlowInputVariables> flowInputVariablesList) { List<FlowOutputVariables> flowOutputVariablesList = new List<FlowOutputVariables>(); for(FlowInputVariables flowInputVariables: flowInputVariablesList) { FlowOutputVariables flowOutputVariables = new FlowOutputVariables(); flowOutputVariables.isValidSASFiscalCode = isValidSASFiscalCode(flowInputVariables.fiscalCode, flowInputVariables.dueDate); flowOutputVariables.opportunitySourceCode = flowOutputVariables.isValidSASFiscalCode ? 'L02' : 'L00'; flowOutputVariablesList.add(flowOutputVariables); } return flowOutputVariablesList; } }

Thnx,
Valentina

AnkaiahAnkaiah (Salesforce Developers) 
Hi Valentina,

Refer the below help article will help you to proceed further.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm

Thanks!!