You need to sign in to do that
Don't have an account?

TestMethod do not support Web service callouts Help
This is my test class:
@isTest(seeAllData = true)
public with sharing class NUBSCartControllerTest{
static testMethod void NUBSCartControllerTestMethod() {
Contact c = new Contact();
c.firstName = 'Charles';
c.lastName = 'Cox';
c.email = 'charliecox17@yahoo.com';
insert c;
Event_Registration__c er = new Event_Registration__c ();
er.name = 'CharlesConference';
er.hasPaid__c = false;
er.Applicant_Name__c = c.id;
insert er;
Id stnd = Test.getStandardPricebookId();
Product2 p = new Product2();
p.name = 'Thursday, March 26, Opening Reception';
insert p;
ConProd_Bridge__c cpb = new ConProd_Bridge__c();
cpb.Product__c = p.id;
cpb.Contact__c = c.id;
insert cpb;
PricebookEntry pbe= new PricebookEntry();
pbe.Product2Id = p.Id;
pbe.unitPrice = 30;
pbe.Pricebook2Id = stnd;
pbe.isActive = true;
insert pbe;
Opportunity o = new Opportunity();
o.Name = 'thisOpp';
o.Amount = 30;
o.stageName = 'Prospecting';
o.closeDate = Date.TODAY().addYears(1);
o.Contact__c = c.id;
insert o;
OpportunityLineItem ole = new OpportunityLineItem();
ole.UnitPrice = 30;
ole.OpportunityId = o.id;
ole.PriceBookEntryId = pbe.id;
ole.Quantity = 1;
insert ole;
Test.setCurrentPageReference(new PageReference('Page.myPage'));
System.currentPageReference().getParameters().put('oppId', o.id);
System.currentPageReference().getParameters().put('isConference', 'true');
NUBSCartController contr = new NUBSCartController();
contr.BillingFirst = 'Charles';
contr.BillingLast = 'Cox';
contr.BillingAddress = '26 West';
contr.BillingCity = 'Austin';
contr.BillingState = 'Texas';
contr.BillingCountry = 'United States';
contr.BillingPostcode = '78681';
contr.CardType = 'Visa';
contr.CardNumber = '4111111111111111';
contr.CardMonth = '12';
contr.CardYear = '2038';
contr.CardSecurity = '123';
contr.cancel();
contr.preCharge();
contr.processPayment();
contr.isConference = 'false';
contr.sendEmails(c);
}
}
I get the error 'TestMethod do not support Web service callouts' when I run the test with seeAlldata = true but not when seeAllData = false. I need to have seeAllData = true so I need to figure this error out. I don't see where I am using a web service call...
Any help would be great,
Thanks!
@isTest(seeAllData = true)
public with sharing class NUBSCartControllerTest{
static testMethod void NUBSCartControllerTestMethod() {
Contact c = new Contact();
c.firstName = 'Charles';
c.lastName = 'Cox';
c.email = 'charliecox17@yahoo.com';
insert c;
Event_Registration__c er = new Event_Registration__c ();
er.name = 'CharlesConference';
er.hasPaid__c = false;
er.Applicant_Name__c = c.id;
insert er;
Id stnd = Test.getStandardPricebookId();
Product2 p = new Product2();
p.name = 'Thursday, March 26, Opening Reception';
insert p;
ConProd_Bridge__c cpb = new ConProd_Bridge__c();
cpb.Product__c = p.id;
cpb.Contact__c = c.id;
insert cpb;
PricebookEntry pbe= new PricebookEntry();
pbe.Product2Id = p.Id;
pbe.unitPrice = 30;
pbe.Pricebook2Id = stnd;
pbe.isActive = true;
insert pbe;
Opportunity o = new Opportunity();
o.Name = 'thisOpp';
o.Amount = 30;
o.stageName = 'Prospecting';
o.closeDate = Date.TODAY().addYears(1);
o.Contact__c = c.id;
insert o;
OpportunityLineItem ole = new OpportunityLineItem();
ole.UnitPrice = 30;
ole.OpportunityId = o.id;
ole.PriceBookEntryId = pbe.id;
ole.Quantity = 1;
insert ole;
Test.setCurrentPageReference(new PageReference('Page.myPage'));
System.currentPageReference().getParameters().put('oppId', o.id);
System.currentPageReference().getParameters().put('isConference', 'true');
NUBSCartController contr = new NUBSCartController();
contr.BillingFirst = 'Charles';
contr.BillingLast = 'Cox';
contr.BillingAddress = '26 West';
contr.BillingCity = 'Austin';
contr.BillingState = 'Texas';
contr.BillingCountry = 'United States';
contr.BillingPostcode = '78681';
contr.CardType = 'Visa';
contr.CardNumber = '4111111111111111';
contr.CardMonth = '12';
contr.CardYear = '2038';
contr.CardSecurity = '123';
contr.cancel();
contr.preCharge();
contr.processPayment();
contr.isConference = 'false';
contr.sendEmails(c);
}
}
I get the error 'TestMethod do not support Web service callouts' when I run the test with seeAlldata = true but not when seeAllData = false. I need to have seeAllData = true so I need to figure this error out. I don't see where I am using a web service call...
Any help would be great,
Thanks!
Take a look at this post of Salesforce StackExchange :
http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data/5070#5070
public class NUBSCartController {
public String oppid {get;set;}
public String isConference {get;set;}
public list<Integer> tableSkew {get;set;}
public Event_Registration__c application {get;set;}
public String sponserName {get;set;}
public String sponserEmail {get;set;}
public Opportunity opp {get;set;}
public Student_Application__c app {get;set;}
public Boolean showConfirm {get;set;}
public Boolean showThankYou {get;set;}
public String BillingFirst {get;set;}
public String BillingLast {get;set;}
public String BillingAddress {get;set;}
public String BillingCity {get;set;}
public String BillingState {get;set;}
public String BillingCountry {get;set;}
public String BillingPostcode {get;set;}
public String CardType {get;set;}
public String CardNumber {get;set;}
public String CardMonth {get;set;}
public String CardYear {get;set;}
public String CardSecurity {get;set;}
public list<SelectOption> CardTypeList {get;set;}
public list<SelectOption> CardMonthList {get;set;}
public list<SelectOption> CardYearList {get;set;}
public list<OpportunityLineItem> oli {get;set;}
public NUBSCartController() {
oppid = ApexPages.currentPage().getParameters().get('oppId');
isConference = ApexPages.currentPage().getParameters().get('isConference');
opp = [SELECT o.Amount, o.name, o.contact__c, o.id FROM Opportunity o WHERE o.id =: oppid];
if(isConference == 'true') {
application = [SELECT name, id, hasPaid__c, Applicant_Name__c FROM Event_Registration__c WHERE Applicant_Name__c =: opp.contact__c AND name LIKE '%Conference%'];
sponserName = 'Sabine Wimmer';
sponserEmail= 'Sabine.Wimmer@mccombs.utexas.edu';
}
else if(isConference == 'false') {
application = [SELECT name, id, hasPaid__c, Applicant_Name__c FROM Event_Registration__c WHERE Applicant_Name__c =: opp.contact__c AND name LIKE '%CareerServices%'];
sponserName = 'Megan Fortson';
sponserEmail = 'Megan.Fortson@mccombs.utexas.edu';
}
oli = [SELECT o.name, o.id, o.PricebookEntry.Product2.name, o.unitprice FROM OpportunityLineItem o WHERE o.OpportunityId =: opp.id];
populatePicklists();
showConfirm = false;
showThankYou = false;
tableSkew = new list<Integer>();
tableSkew.add(1);
}
public void populatePicklists() {
list<Schema.PicklistEntry> ple; // Declare variable
/* Instansiate picklists */
CardTypeList = new list<SelectOption>();
CardMonthList = new list<SelectOption>();
CardYearList = new list<SelectOption>();
/* Get values from chargent card type and add to card type picklist */
ple = Opportunity.ChargentSFA__Card_Type__c.getDescribe().getPicklistValues();
for (Schema.PicklistEntry p:ple) {
CardTypeList.add(new SelectOption(p.getValue(), p.getValue()));
}
/* Add values to expiration month picklist */
CardMonthList.add(new SelectOption('01', '01'));
CardMonthList.add(new SelectOption('02', '02'));
CardMonthList.add(new SelectOption('03', '03'));
CardMonthList.add(new SelectOption('04', '04'));
CardMonthList.add(new SelectOption('05', '05'));
CardMonthList.add(new SelectOption('06', '06'));
CardMonthList.add(new SelectOption('07', '07'));
CardMonthList.add(new SelectOption('08', '08'));
CardMonthList.add(new SelectOption('09', '09'));
CardMonthList.add(new SelectOption('10', '10'));
CardMonthList.add(new SelectOption('11', '11'));
CardMonthList.add(new SelectOption('12', '12'));
/* Add 2014 + 50 more years to expiration year picklist */
Integer startYear = System.TODAY().year();
for (Integer i = 0; i < 50; i++) {
CardYearList.add(new SelectOption(string.valueOf(startYear + i), string.valueOf(startYear + i)));
}
}
public void preCharge() {
showConfirm = true;
assignVariables(); // Port over variables from page to opportunity fields
update opp; // Save opportunity record
}
public void cancel() {
showConfirm = false;
}
public PageReference printable() {
pageReference reRend = new PageReference('/apex/NUBSSummary?Oppid=' + opp.id);
reRend.setRedirect(true);
return reRend;
}
public void processPayment() {
application.hasPaid__c = true;
Contact c = [SELECT name, id, email, firstName FROM Contact WHERE id in (select o.contact__c from opportunity o where o.id =: oppid)];
ChargentSFA.TChargentOperations.TChargentResult result = ChargentSFA.TChargentOperations.ChargeOpportunity_Click(opp.Id);
Opportunity opp2 = [SELECT Id, ChargentSFA__Balance_Due__c FROM Opportunity WHERE Id = :opp.Id];
if (opp2.ChargentSFA__Balance_Due__c == 0) {
opp.StageName = 'Closed Won';
update opp;
showConfirm = false;
showThankYou = true;
sendEmails(c);
list<ConProd_Bridge__c> cpbs = [SELECT name, id, Status__c, Remaining_Payment__c, Product__c, Contact__c FROM ConProd_Bridge__c
WHERE Product__r.pertains_To__c = 'NUBS2015' AND (Product__r.name LIKE '%Thursday, March 26, Opening Reception%' OR
Product__r.name LIKE '%Thursday, March 26, Dinner with Keynote Speaker%' OR Product__r.name LIKE '%Friday, March 27, Lunch at the Alumni Center%'
OR Product__r.name LIKE '%Friday, March 27, Closing Dinner at the Rattle Inn%') AND Contact__c =: c.id];
if(cpbs != null) {
for(ConProd_Bridge__c cpb : cpbs) {
cpb.Remaining_Payment__c = 0;
cpb.Status__c = 'Paid';
}
}
update cpbs;
update application;
} else {
showConfirm = false;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'There was an error processing your payment. Make sure all fields are filled in correctly.'));
}
}
public void assignVariables() {
opp.ChargentSFA__Billing_First__c = BillingFirst;
opp.ChargentSFA__Billing_Last__c = BillingLast;
opp.ChargentSFA__Billing_Address__c = BillingAddress;
opp.ChargentSFA__Billing_City__c = BillingCity;
opp.ChargentSFA__Billing_State__c = BillingState;
opp.ChargentSFA__Billing_Country__c = BillingCountry;
opp.ChargentSFA__Billing_Postcode__c = BillingPostcode;
opp.ChargentSFA__Card_Type__c = CardType;
opp.ChargentSFA__Card_Number__c = CardNumber;
opp.ChargentSFA__Card_Month__c = CardMonth;
opp.ChargentSFA__Card_Year__c = CardYear;
opp.ChargentSFA__Card_Security__c = CardSecurity;
opp.ChargentSFA__Payment_Method__c = 'Credit Card';
}
}
FATAL_ERROR|System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped (ChargentBase)
This however does not make sense because the Chargent package is already installed. My org has written other test classes using Chargent so I know it can be done.
Anybody got the solution for this. Please update it.
Even i am facing the same problem. Its already more than 20 hours i spent on it.
Please update the solution.
TIA