• sldfkj
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I have an external web service that's called from a class generated from a wsdl file.  I've wrapped the invoke method with a Test.isRunningTest() check so that my tests don't fail due to a callout.  My assert comes back successful, but code coverage remains at 0%.

 

(code posted below)

 

Any thoughts and/or ideas would be greatly appreciated.

 

Thank you in advance!

Sam

 

APEX Test:

@isTest

private Class MyService

{

    publicstatictestMethodvoid TestMyService()

    {

        try

        {

            MyService.AccountServiceSoap cs = new MyService.AccountServiceSoap();

            DateTime dt = cs.GetFirstInstallAppointmentAvailable('token', '', '', '', '', '10023', 982);

            

            //With the callout, I know that the returned result will be 1/1/1900

            DateTime expected = DateTime.newInstanceGMT(1900,1,1);

            

            System.Debug('ClickServiceTest Pre dt:' + dt + ' / expected:' + expected);

            

            System.AssertEquals(dt,expected);

            

            System.Debug('ClickServiceTest Post dt:' + dt + ' / expected:' + expected);

        }

        catch(Exception ex)

        {

            System.Debug('Error: ' + ex.getMessage());

        }

    }

}

 

 

APEX Class:

//Generated by wsdl2apex

public class MyService {
public class Available_element {
public String token;
public String address1;
public String address2;
public String city;
public String stateAbbrev;
public String postalCode;
public Integer serviceCodeID;
private String[] token_type_info = new String[]{'token','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] address1_type_info = new String[]{'address1','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] address2_type_info = new String[]{'address2','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] city_type_info = new String[]{'city','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] stateAbbrev_type_info = new String[]{'stateAbbrev','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] postalCode_type_info = new String[]{'postalCode','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] serviceCodeID_type_info = new String[]{'serviceCodeID','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
private String[] field_order_type_info = new String[]{'token','address1','address2','city','stateAbbrev','postalCode','serviceCodeID'};
}
public class AvailableResponse_element {
public DateTime GetFirstInstallAppointmentAvailableResult;
private String[] GetFirstInstallAppointmentAvailableResult_type_info = new String[]{'GetFirstInstallAppointmentAvailableResult','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
private String[] field_order_type_info = new String[]{'GetFirstInstallAppointmentAvailableResult'};
}
public class AccountServiceSoap {
public String endpoint_x = 'http://someservice.com';
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://tempuri.org/', 'MyService'};

public DateTime GetFirstInstallAppointmentAvailable(String token,String address1,String address2,String city,String stateAbbrev,String postalCode,Integer serviceCodeID) {
MyService.Available_element request_x = new MyService.Available_element();
MyService.AvailableResponse_element response_x;
request_x.token = token;
request_x.address1 = address1;
request_x.address2 = address2;
request_x.city = city;
request_x.stateAbbrev = stateAbbrev;
request_x.postalCode = postalCode;
request_x.serviceCodeID = serviceCodeID;
Map<String, MyService.AvailableResponse_element> response_map_x = new Map<String, MyService.AvailableResponse_element>();
response_map_x.put('response_x', response_x);

if(Test.isRunningTest())
{
return DateTime.newInstanceGMT(1900,1,1);
}

WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://tempuri.org/GetFirstInstallAppointmentAvailable',
'http://tempuri.org/',
'GetFirstInstallAppointmentAvailable',
'http://tempuri.org/',
'GetFirstInstallAppointmentAvailableResponse',
'MyService.AvailableResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.GetFirstInstallAppointmentAvailableResult;
}
}
}

  • March 09, 2012
  • Like
  • 0

I have an external web service that's called from a class generated from a wsdl file.  I've wrapped the invoke method with a Test.isRunningTest() check so that my tests don't fail due to a callout.  My assert comes back successful, but code coverage remains at 0%.

 

(code posted below)

 

Any thoughts and/or ideas would be greatly appreciated.

 

Thank you in advance!

Sam

 

APEX Test:

@isTest

private Class MyService

{

    publicstatictestMethodvoid TestMyService()

    {

        try

        {

            MyService.AccountServiceSoap cs = new MyService.AccountServiceSoap();

            DateTime dt = cs.GetFirstInstallAppointmentAvailable('token', '', '', '', '', '10023', 982);

            

            //With the callout, I know that the returned result will be 1/1/1900

            DateTime expected = DateTime.newInstanceGMT(1900,1,1);

            

            System.Debug('ClickServiceTest Pre dt:' + dt + ' / expected:' + expected);

            

            System.AssertEquals(dt,expected);

            

            System.Debug('ClickServiceTest Post dt:' + dt + ' / expected:' + expected);

        }

        catch(Exception ex)

        {

            System.Debug('Error: ' + ex.getMessage());

        }

    }

}

 

 

APEX Class:

//Generated by wsdl2apex

public class MyService {
public class Available_element {
public String token;
public String address1;
public String address2;
public String city;
public String stateAbbrev;
public String postalCode;
public Integer serviceCodeID;
private String[] token_type_info = new String[]{'token','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] address1_type_info = new String[]{'address1','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] address2_type_info = new String[]{'address2','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] city_type_info = new String[]{'city','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] stateAbbrev_type_info = new String[]{'stateAbbrev','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] postalCode_type_info = new String[]{'postalCode','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] serviceCodeID_type_info = new String[]{'serviceCodeID','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
private String[] field_order_type_info = new String[]{'token','address1','address2','city','stateAbbrev','postalCode','serviceCodeID'};
}
public class AvailableResponse_element {
public DateTime GetFirstInstallAppointmentAvailableResult;
private String[] GetFirstInstallAppointmentAvailableResult_type_info = new String[]{'GetFirstInstallAppointmentAvailableResult','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
private String[] field_order_type_info = new String[]{'GetFirstInstallAppointmentAvailableResult'};
}
public class AccountServiceSoap {
public String endpoint_x = 'http://someservice.com';
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://tempuri.org/', 'MyService'};

public DateTime GetFirstInstallAppointmentAvailable(String token,String address1,String address2,String city,String stateAbbrev,String postalCode,Integer serviceCodeID) {
MyService.Available_element request_x = new MyService.Available_element();
MyService.AvailableResponse_element response_x;
request_x.token = token;
request_x.address1 = address1;
request_x.address2 = address2;
request_x.city = city;
request_x.stateAbbrev = stateAbbrev;
request_x.postalCode = postalCode;
request_x.serviceCodeID = serviceCodeID;
Map<String, MyService.AvailableResponse_element> response_map_x = new Map<String, MyService.AvailableResponse_element>();
response_map_x.put('response_x', response_x);

if(Test.isRunningTest())
{
return DateTime.newInstanceGMT(1900,1,1);
}

WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://tempuri.org/GetFirstInstallAppointmentAvailable',
'http://tempuri.org/',
'GetFirstInstallAppointmentAvailable',
'http://tempuri.org/',
'GetFirstInstallAppointmentAvailableResponse',
'MyService.AvailableResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.GetFirstInstallAppointmentAvailableResult;
}
}
}

  • March 09, 2012
  • Like
  • 0