You need to sign in to do that
Don't have an account?
lakshman.matti
Testing WSDL-Based Asynchronous Callouts
Hi everyone,
I'm having an issue of writing test class for asynchronous callouts which i have used in controller.
can some one help me to write test class to code coverage to max.
i followed the way in the below link and i'm getting the following Error.
System.NoSuchElementException: Iterator has no more elements
link for test class provided by salesforce.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_continuation_callout_soap.htm
Thanks in advance.
Lakshman
I'm having an issue of writing test class for asynchronous callouts which i have used in controller.
can some one help me to write test class to code coverage to max.
i followed the way in the below link and i'm getting the following Error.
System.NoSuchElementException: Iterator has no more elements
link for test class provided by salesforce.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_continuation_callout_soap.htm
Thanks in advance.
Lakshman
Lakshman,
Do you mind posting your test class code?
Regards,
Gaurav
@isTest
public class GSDBOMPageController_Test{
public GSDBOMPageController.Wrapper WObj;
// custom setting data.
private static void createCustomSetting(){
HPTriggerFrameworkObjectMapping__c CSPOobj=new HPTriggerFrameworkObjectMapping__c(Name='GSD_Part_Order__c ', DispatcherCalssName__c='GSDPartOrder');
insert CSPOobj;
HPTriggerFrameworkObjectMapping__c CSPOLobj=new HPTriggerFrameworkObjectMapping__c(Name='GSD_Part_Order_Line__c', DispatcherCalssName__c='GSDPartOrderLine');
insert CSPOLobj;
HPTriggerFrameworkObjectMapping__c trigFramework = new HPTriggerFrameworkObjectMapping__c(name = 'CKSW__Task__c',DispatcherCalssName__c = 'GSDTask');
insert trigFramework;
HPTriggerFrameworkObjectMapping__c resourceCS = new HPTriggerFrameworkObjectMapping__c(name = 'CKSW__Engineer_Equipment__c',DispatcherCalssName__c = 'GSDResource');
insert resourceCS;
HPTriggerFrameworkObjectMapping__c GsdCaseQuote=new HPTriggerFrameworkObjectMapping__c(name='GSD_Case_Quote__c',DispatcherCalssName__c='GSDCaseQuote');
insert GsdCaseQuote;
Record_Type_Mapping__c GsdRecordType= new Record_Type_Mapping__c();
GsdRecordType.name='GSD_CSC_CKSW__Task';
GsdRecordType.Object_API_name__c='CKSW__Task__c';
GsdRecordType.Record_Type_Names__c='GSD_CSC_Task_Creation;GSD_CSC_Task;GSD_CSC_Task_Click_Submitted;GSD_CSC_Task_Closed';
insert GsdRecordType;
Record_Type_Mapping__c GsdCaseRecordType= new Record_Type_Mapping__c();
GsdCaseRecordType.name='GSD_CSC_Case';
GsdCaseRecordType.Object_API_name__c='Case';
GsdCaseRecordType.Record_Type_Names__c='GSD_CSC_Case_Closed;GSD_CSC_Case_Creation;GSD_CSC_Case_Open';
insert GsdCaseRecordType;
Record_Type_Mapping__c GsdTaskRecordType= new Record_Type_Mapping__c();
GsdTaskRecordType.name='GSD_CSC_Task';
GsdTaskRecordType.Object_API_name__c='Task';
GsdTaskRecordType.Record_Type_Names__c='GSD_Standard_Task;GSD_Attachment_Task;GSD_Onsite_Task';
insert GsdTaskRecordType;
GSD_Integration_Data__c inti = new GSD_Integration_Data__c();
inti.End_point_URL__c='https://it-services-gw-csc-stg.itcs.hp.com/gw/hpit/egit/billofmaterial.itg';
inti.Time_out__c=120000;
inti.Client_Certificate__c='SFDC_Certificate';
inti.name='BOM';
insert inti;
}
private static user createFsmUser(){
profile fsmManagerPro=[select id,name from profile where name='GSD FSM Sub Regional Resource' limit 1];
user fsmProfileUser=new user(profileid=fsmManagerPro.id,username='testmail@hp.com',email='abc@hp.com',emailencodingkey='UTF-8',localesidkey='en_US',languagelocalekey='en_US',timezonesidkey='America/Los_Angeles',alias='cspu',lastname='lastname',Adoption_Role_Type__c='IT',Email_Address__c='testemail1@hp.com');
insert fsmProfileUser;
return fsmProfileUser;
}
private static testMethod void GSDBOMPageController_Method1(){
GSD_Integration_Data__c inti = new GSD_Integration_Data__c();
inti.End_point_URL__c='https://it-services-gw-csc-stg.itcs.hp.com/gw/hpit/egit/bomspareitems.itg';
inti.Time_out__c=120000;
inti.Client_Certificate__c='SFDC_Certificate';
inti.name='SpareBomParts';
insert inti;
String Env='Production';
String Source='GPG';
String CompoNum='382641-111';
string Transactionids;
MonitorUtility objmonitorutility=new MonitorUtility();
Transactionids = objmonitorutility.beginMon('SF-SpareParts');
createCustomSetting();
GSDBOMPageController GBObj=new GSDBOMPageController();
GBObj.monitorMethod();
BusinessHours newBusHours= new BusinessHours(Name='Default');
Case newCase= new Case(status='open', BusinessHours=newBusHours,source_system_case_id__c='98000057131',
Severity__c='3-NORMAL', Description='Test Description', OwnerId=userinfo.getUserId(),Reason='ABP Support');
newCase.Mission_Critical__c=true;
newCase.NBD_SBD__c='SBD';
insert newCase;
GSD_Part_Order__c POObj=new GSD_Part_Order__c(name='Po',legacy_part_order_number__C='1234567891-123-1');
POObj.ISO2_Character_Country_Code__c='AX';
POObj.Case_Number__c=newcase.id;
insert POObj;
GBObj.partorderid=POObj.Id;
GBObj.queryParamPartOrderId=GBObj.partorderid;
GBObj.legacypartordernumber=POObj.Legacy_Part_Order_number__c;
GBObj.submit();
GSDBOMPageController.Wrapper WObj = new GSDBOMPageController.Wrapper();
WObj.isCheckBox = true;
WObj.PartIdentifier2 = '';
WObj.PartExtendedDescription2='';
WObj.CSR='';
WObj.ROHS='';
WObj.SourceSystemKey='';
WObj.ROHSComplaint='';
WObj.Returnable='';
WObj.PartImageFlag='';
WObj.PartImageUrl='';
WObj.isPartOrderabilityStatusCode='';
WObj.selectchk=false;
WObj.qty =2;
WObj.PartCategoryCode='';
GBObj.spareBomList.add(WObj);
GBObj.spareBomList_Secondary.add(WObj);
GBObj.CallBack();
GBObj.selectRecords();
GBObj.RefreshPage();
GBObj.checkBoxStaus();
GBObj.bomSpareItems();
GSDBomSpareItemsReqeust.PortTypeEndpoint0 objsoap=new GSDBomSpareItemsReqeust.PortTypeEndpoint0();
GSDBomSpareItemsReqeust.PortTypeEndpoint0 BOMSpareItems;
GSDBOMPageController.compnentBOMItem CMObj=new GSDBOMPageController.compnentBOMItem();
}
private static testMethod void GSDBOMPageController_MethodCont(){
createCustomSetting();
test.startTest();
GSDBOMPageController GBObj=new GSDBOMPageController();
BusinessHours newBusHours= new BusinessHours(Name='Default');
Case newCase= new Case(status='open', BusinessHours=newBusHours,source_system_case_id__c='98000057131',
Severity__c='3-NORMAL', Description='Test Description', OwnerId=userinfo.getUserId(),Reason='ABP Support');
newCase.Mission_Critical__c=true;
newCase.NBD_SBD__c='SBD';
insert newCase;
GSD_Part_Order__c POObj=new GSD_Part_Order__c(name='Po',legacy_part_order_number__C='1234567891-123-1');
POObj.ISO2_Character_Country_Code__c='AX';
POObj.Case_Number__c=newcase.id;
insert POObj;
GBObj.partorderid=POObj.Id;
GBObj.queryParamPartOrderId=GBObj.partorderid;
GBObj.legacypartordernumber=POObj.Legacy_Part_Order_number__c;
GSDBomclass.SerializedProductAndSupportPartList output1;
output1=GBObj.output;
AsyncGSDBomclass.SerializedProductAndSupportPartListFuture GetBOM1=new AsyncGSDBomclass.SerializedProductAndSupportPartListFuture();
GSDBomclass.ProductSupportPart PSPObj=new GSDBomclass.ProductSupportPart();
PSPObj.ProductIdentifier='test';
PSPObj.PartIdentifier='test';
PSPObj.LocaleCode='test';
PSPObj.PartCategoryCode='test';
PSPObj.PartSubCategoryCode='test';
PSPObj.PartDescription='test';
PSPObj.PartExtendedDescription='test';
PSPObj.RestrictionOnHazardousSubstanceCode='test';
PSPObj.CustomerSelfRepairCode='test';
PSPObj.PartTechnicalCourierCode='test';
PSPObj.PartImageFlag='test';
PSPObj.PartOrderabilityStatusCode='test';
PSPObj.SalesRestrictionCode='test';
PSPObj.SalesRestrictionDescription='test';
PSPObj.SourceSystemKey='test';
PSPObj.PartReturnableCode='test';
PSPObj.CompliantWithProductFlag='test';
PSPObj.WholeUnitFlag='test';
PSPObj.CompliantWithRoHSJurisdictionFlag='test';
list<GSDBomclass.ProductSupportPart> LPSPObj=new list<GSDBomclass.ProductSupportPart>();
LPSPObj.add(PSPObj);
GSDBomclass.ProductSupportPartList PSPLObj=new GSDBomclass.ProductSupportPartList();
PSPLObj.ProductSupportPartList=LPSPObj;
GSDBomclass.SerializedProductInstance SPILObj=new GSDBomclass.SerializedProductInstance();
SPILObj.ProductSerialNumber='test';
SPILObj.ProductIdentifier='test';
SPILObj.PartIdentifier='test';
SPILObj.LocaleCode='test';
SPILObj.PartCategoryCode='test';
SPILObj.PartSubCategoryCode='test';
SPILObj.PartDescription='test';
SPILObj.PartQuantity='test';
SPILObj.PartSerialNumber='test';
SPILObj.PartReturnableCode='test';
list<GSDBomclass.SerializedProductInstance> gSPILObj=new list<GSDBomclass.SerializedProductInstance>();
gSPILObj.add(SPILObj);
GSDBomclass.SerializedProductInstanceList SPILObj1=new GSDBomclass.SerializedProductInstanceList();
SPILObj1.SerializedProductInstanceList=gSPILObj;
GSDBomclass.SerializedProductAndSupportPartList GSDSPObj=new GSDBomclass.SerializedProductAndSupportPartList();
GSDSPObj.ProductSerialNumber='test';
GSDSPObj.ProductIdentifier='test';
GSDSPObj.RestrictionOnHazardousSubstancesCode='test';
GSDSPObj.LocaleCode='test';
GSDSPObj.ProductDescription='test';
GSDSPObj.ProductName='test';
GSDSPObj.HasMinimumRoHSException='test';
GSDSPObj.MessageCode='test';
GSDSPObj.MessageContent='test';
GSDSPObj.ProductSupportPartList=PSPLObj;
GSDSPObj.SerializedProductInstanceList=SPILObj1;
GBObj.GetBOM=GetBOM1;
output1=GBObj.output;
GetBOM1=GBObj.GetBOM;
GBObj.output=GSDSPObj;
system.debug('GBObj.output'+GBObj.output);
system.debug('gSPILObj'+gSPILObj);
GBObj.casenumbervalue=new List<String>{'123','456'};
GBObj.output.SerializedProductInstanceList.SerializedProductInstanceList=gSPILObj;
//GBObj.submit();
GBObj.CallBack();
test.stopTest();
}
private testmethod static void testAsyncCal(){
createCustomSetting();
BusinessHours newBusHours= new BusinessHours(Name='Default');
Case newCase= new Case(status='open', BusinessHours=newBusHours,source_system_case_id__c='98000057131',
Severity__c='3-NORMAL', Description='Test Description', OwnerId=userinfo.getUserId(),Reason='ABP Support');
newCase.Mission_Critical__c=true;
newCase.NBD_SBD__c='SBD';
insert newCase;
GSD_Part_Order__c POObj=new GSD_Part_Order__c(name='Po',legacy_part_order_number__C='1234567891-123-1');
POObj.ISO2_Character_Country_Code__c='AX';
POObj.Case_Number__c=newcase.id;
insert POObj;
GSDBOMPageController GBObj=new GSDBOMPageController();
GBObj.partorderid=POObj.Id;
GBObj.queryParamPartOrderId=GBObj.partorderid;
GBObj.legacypartordernumber=POObj.Legacy_Part_Order_number__c;
continuation conti=GBObj.submit();
system.debug('conti'+conti);
// Verify that the continuation has the proper requests
Map<String, HttpRequest> requests = conti.getRequests();
system.assert(requests.size() == 1);
// Perform mock callout
// (i.e. skip the callout and call the callback method)
HttpResponse response = new HttpResponse();
response.setBody('Mock response body');
// Set the fake response for the continuation
String requestLabel = requests.keyset().iterator().next();
Test.setContinuationResponse(requestLabel, response);
// Invoke callback method
Object result = Test.invokeContinuationMethod(GBObj, conti);
// result is the return value of the callback
System.assertEquals(null, result);
// Verify that the controller's result variable
// is set to the mock response.
}
}
Did you get the answer for your error?