You need to sign in to do that
Don't have an account?
Nitin Kumar 162
Test Class for a class that have multiple HTTPRequest callout
I am using a class, in this I am using three HttpRequest on different URL for getting the data.
Now I am creating the test class and for HTTP request I have used HttpCalloutMock but when i am run the test class it threw the error -
12:55:15:828 FATAL_ERROR System.AssertException: Assertion Failed: Expected: http://abcd/donor, Actual: http://xyz/oauth
My code -
@Istest
public class SyncDonorToGCTest {
@Istest
static void testCallout(){
List<sObject> records = new List<sObject>();
records.add(new Contact(firstname='TestFirstApi',lastname='LastMiddle',Email='TestEmailApi@gmail.com'));
insert records;
List<Id> ContactId = new List<Id>();
Contact ContactVal;
ContactVal = [SELECT Id FROM Contact];
ContactId.add(ContactVal.Id);
Test.starttest();
Test.setMock(HttpCalloutMock.class, new SyncDonorCalloutHttpCallout());
SyncDonorCallout.ContactDataCallout(ContactId);
System.assertEquals(200, 200);
Test.StopTest();
}
}
@Istest
global class SyncDonorCalloutHttpCallout implements HttpCalloutMock{
global HTTPResponse respond(HTTPRequest req){
System.assertEquals(Label.NewDonorApi, req.getEndpoint());
System.assertEquals('POST', req.getMethod());
// Create a fake response
HttpResponse res = new HttpResponse();
res.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer sfdsdfdfs');
res.setBody('{"userid":"sffsdf","password":"","first_name":"first_name","last_name":"last_name","email":"email","address1":"address1","address2":"address2","city":"city","state":"state","country":"country","zip":"zip","phone":"phone","date_of_birth":"date_of_birth","phone2":"phone2","suppressConfirmationEmail":"0","sf_api_call":"0"}');
res.setStatusCode(200);
return res;
}
}
Please suggest me what should I do.
Now I am creating the test class and for HTTP request I have used HttpCalloutMock but when i am run the test class it threw the error -
12:55:15:828 FATAL_ERROR System.AssertException: Assertion Failed: Expected: http://abcd/donor, Actual: http://xyz/oauth
My code -
@Istest
public class SyncDonorToGCTest {
@Istest
static void testCallout(){
List<sObject> records = new List<sObject>();
records.add(new Contact(firstname='TestFirstApi',lastname='LastMiddle',Email='TestEmailApi@gmail.com'));
insert records;
List<Id> ContactId = new List<Id>();
Contact ContactVal;
ContactVal = [SELECT Id FROM Contact];
ContactId.add(ContactVal.Id);
Test.starttest();
Test.setMock(HttpCalloutMock.class, new SyncDonorCalloutHttpCallout());
SyncDonorCallout.ContactDataCallout(ContactId);
System.assertEquals(200, 200);
Test.StopTest();
}
}
@Istest
global class SyncDonorCalloutHttpCallout implements HttpCalloutMock{
global HTTPResponse respond(HTTPRequest req){
System.assertEquals(Label.NewDonorApi, req.getEndpoint());
System.assertEquals('POST', req.getMethod());
// Create a fake response
HttpResponse res = new HttpResponse();
res.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer sfdsdfdfs');
res.setBody('{"userid":"sffsdf","password":"","first_name":"first_name","last_name":"last_name","email":"email","address1":"address1","address2":"address2","city":"city","state":"state","country":"country","zip":"zip","phone":"phone","date_of_birth":"date_of_birth","phone2":"phone2","suppressConfirmationEmail":"0","sf_api_call":"0"}');
res.setStatusCode(200);
return res;
}
}
Please suggest me what should I do.