You need to sign in to do that
Don't have an account?
Sfdc11
Urgent!! Http Webservice Test Class
Im gettin the folowing error when I abt to save the below test class for webservice class.
Method does not exist or incorrect signature: Test.setMock(Type, DMDMockHttpResponseGenerator) at line 5 column 8
@isTest
private class DMDCalloutClassTest {
@isTest static void testDMDCallout() {
Test.setMock(HttpCalloutMock.class,new DMDMockHttpResponseGenerator());
HttpResponse res = Dmd_HttpCallTest.getCountryInfo();
//HttpResponse res;
String contentType = res.getHeader('Content-Type');
System.assert(contentType == 'application/soap+xml; charset=utf-8');
String actualValue = res.getBody();
String expectedValue = '<birId>15625017</birId>';
System.assertEquals(actualValue, expectedValue);
System.assertEquals(200, res.getStatusCode());
}
}
private class DMDCalloutClassTest {
@isTest static void testDMDCallout() {
Test.setMock(HttpCalloutMock.class,new DMDMockHttpResponseGenerator());
HttpResponse res = Dmd_HttpCallTest.getCountryInfo();
//HttpResponse res;
String contentType = res.getHeader('Content-Type');
System.assert(contentType == 'application/soap+xml; charset=utf-8');
String actualValue = res.getBody();
String expectedValue = '<birId>15625017</birId>';
System.assertEquals(actualValue, expectedValue);
System.assertEquals(200, res.getStatusCode());
}
}
@isTest
global class DMDMockHttpResponseGenerator implements HttpCalloutMock {
global HTTPResponse respond(HTTPRequest req) {
System.assertEquals('https://webservice/loc', req.getEndpoint());
System.assertEquals('GET', req.getMethod());
// Create a fake response
HttpResponse res = new HttpResponse();
res.setHeader('Content-Type','application/soap+xml; charset=utf-8');
res.setBody('<birId>15625017</birId>');
res.setStatusCode(200);
return res;
}
}
global class DMDMockHttpResponseGenerator implements HttpCalloutMock {
global HTTPResponse respond(HTTPRequest req) {
System.assertEquals('https://webservice/loc', req.getEndpoint());
System.assertEquals('GET', req.getMethod());
// Create a fake response
HttpResponse res = new HttpResponse();
res.setHeader('Content-Type','application/soap+xml; charset=utf-8');
res.setBody('<birId>15625017</birId>');
res.setStatusCode(200);
return res;
}
}
Please help me out!!
Might want to try this: