You need to sign in to do that
Don't have an account?
BHASKAR GANGULY
issue testing webservice callouts soap
Hi,
i am getting null object error while trying to test the Mock of a webservice callout.
following is my WSDL2Apex class generated :
//Generated by wsdl2apex
public class parksServices {
public class byCountryResponse {
public String[] return_x;
private String[] return_x_type_info = new String[]{'return','http://parks.services/',null,'0','-1','false'};
private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
private String[] field_order_type_info = new String[]{'return_x'};
}
public class byCountry {
public String arg0;
private String[] arg0_type_info = new String[]{'arg0','http://parks.services/',null,'0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
private String[] field_order_type_info = new String[]{'arg0'};
}
public class ParksImplPort {
public String endpoint_x = 'https://th-apex-soap-service.herokuapp.com/service/parks';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://parks.services/', 'parksServices'};
public String[] byCountry(String arg0) {
parksServices.byCountry request_x = new parksServices.byCountry();
request_x.arg0 = arg0;
parksServices.byCountryResponse response_x;
Map<String, parksServices.byCountryResponse> response_map_x = new Map<String, parksServices.byCountryResponse>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'http://parks.services/',
'byCountry',
'http://parks.services/',
'byCountryResponse',
'parksServices.byCountryResponse'}
);
response_x = response_map_x.get('response_x');
return response_x.return_x;
}
}
}
My Main Callout class :
public class Parkstub {
public static list<string> parkstub1( string a)
{
parksServices.ParksImplPort parklist = new parksServices.ParksImplPort();
return parklist.byCountry(a);
}
}
Mock Class
@isTest
global class ParkstubMock implements WebServiceMock {
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
// start - specify the response you want to send
parksServices.byCountryResponse response_x1 = new parksServices.byCountryResponse();
response_x1.return_x.add('Yellowstone');
response_x1.return_x.add('Mackinac National Park');
response_x1.return_x.add('Yosemite');
// response_x.return_x = 3.0;
// end
response.put('response_x', response_x1);
}
}
Test Class :
@isTest
public class ParkStubTest {
@isTest static void testCallout1() {
// This causes a fake response to be generated
Test.setMock(WebServiceMock.class, new ParkstubMock());
// Call the method that invokes a callout
string a = 'United States';
// Double y = 2.0;
list<string> result = Parkstub.parkstub1(a);
// Verify that a fake result is returned
//System.assertEquals(3.0, result);
}
}
While running the test class its giving me the error of attempt to dereference Null object for Mockclass.How should i create the instance for the list of string?
Please help me.
Thanks,
Bhaskar
i am getting null object error while trying to test the Mock of a webservice callout.
following is my WSDL2Apex class generated :
//Generated by wsdl2apex
public class parksServices {
public class byCountryResponse {
public String[] return_x;
private String[] return_x_type_info = new String[]{'return','http://parks.services/',null,'0','-1','false'};
private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
private String[] field_order_type_info = new String[]{'return_x'};
}
public class byCountry {
public String arg0;
private String[] arg0_type_info = new String[]{'arg0','http://parks.services/',null,'0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
private String[] field_order_type_info = new String[]{'arg0'};
}
public class ParksImplPort {
public String endpoint_x = 'https://th-apex-soap-service.herokuapp.com/service/parks';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://parks.services/', 'parksServices'};
public String[] byCountry(String arg0) {
parksServices.byCountry request_x = new parksServices.byCountry();
request_x.arg0 = arg0;
parksServices.byCountryResponse response_x;
Map<String, parksServices.byCountryResponse> response_map_x = new Map<String, parksServices.byCountryResponse>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'http://parks.services/',
'byCountry',
'http://parks.services/',
'byCountryResponse',
'parksServices.byCountryResponse'}
);
response_x = response_map_x.get('response_x');
return response_x.return_x;
}
}
}
My Main Callout class :
public class Parkstub {
public static list<string> parkstub1( string a)
{
parksServices.ParksImplPort parklist = new parksServices.ParksImplPort();
return parklist.byCountry(a);
}
}
Mock Class
@isTest
global class ParkstubMock implements WebServiceMock {
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
// start - specify the response you want to send
parksServices.byCountryResponse response_x1 = new parksServices.byCountryResponse();
response_x1.return_x.add('Yellowstone');
response_x1.return_x.add('Mackinac National Park');
response_x1.return_x.add('Yosemite');
// response_x.return_x = 3.0;
// end
response.put('response_x', response_x1);
}
}
Test Class :
@isTest
public class ParkStubTest {
@isTest static void testCallout1() {
// This causes a fake response to be generated
Test.setMock(WebServiceMock.class, new ParkstubMock());
// Call the method that invokes a callout
string a = 'United States';
// Double y = 2.0;
list<string> result = Parkstub.parkstub1(a);
// Verify that a fake result is returned
//System.assertEquals(3.0, result);
}
}
While running the test class its giving me the error of attempt to dereference Null object for Mockclass.How should i create the instance for the list of string?
Please help me.
Thanks,
Bhaskar