1

The following class is wsdl2apex generated. Can anyone help me on how to write test class for the same

//Generated by wsdl2apex

public class e_services {
    public class EPort {
        public String endpoint_x = 'http://xyz';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        public e_services.authentication_element parameters;
        private String parameters_hns = 'authentication=urn:E';
        private String[] ns_map_type_info = new String[]{'urn:E', 'e_services'};


        public e_services.C_Webservice_AddressCompleteRespons_element[] E_AddressesSearch(Integer HousenumberFrom,String PostalCode,Integer HousenumberUntil) {
            e_services.E_AddressesSearch_element request_x = new e_services.E_AddressesSearch_element();
            e_services.E_AddressesSearchResponse_element response_x;
            if(HousenumberFrom>0) request_x.HousenumberFrom = HousenumberFrom;
            if(HousenumberUntil>0) request_x.HousenumberUntil = HousenumberUntil;
            request_x.PostalCode = PostalCode;
            Map<String, e_services.E_AddressesSearchResponse_element> response_map_x = new Map<String, e_services.E_AddressesSearchResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'urn:EE_AddressesSearch',
              'urn:E',
              'E_AddressesSearch',
              'urn:E',
              'E_AddressesSearchResponse',
              'e_services.E_AddressesSearchResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.C_Webservice_AddressCompleteRespons;
        }
        public e_services.C_Webservice_ExternalZipcodeRespons_element E_Postcodecheck(String Postcode,String HuisnummerExtentie,Integer Huisnummer) {
            e_services.E_Postcodecheck_element request_x = new e_services.E_Postcodecheck_element();
            e_services.E_PostcodecheckResponse_element response_x;
            request_x.Postcode = Postcode;
            request_x.HuisnummerExtentie = HuisnummerExtentie;
            request_x.Huisnummer = Huisnummer;
            Map<String, e_services.E_PostcodecheckResponse_element> response_map_x = new Map<String, e_services.E_PostcodecheckResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'urn:EE_Postcodecheck',
              'urn:E',
              'E_Postcodecheck',
              'urn:E',
              'E_PostcodecheckResponse',
              'e_services.E_PostcodecheckResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.C_Webservice_ExternalZipcodeRespons;
        }
        public e_services.C_Webservice_AddressCompleteRespons_element[] E_PostcodeSearch(String TownPartial,String StreetPartial) {
            e_services.E_PostcodeSearch_element request_x = new e_services.E_PostcodeSearch_element();
            e_services.E_PostcodeSearchResponse_element response_x;
            request_x.TownPartial = TownPartial;
            request_x.StreetPartial = StreetPartial;
            Map<String, e_services.E_PostcodeSearchResponse_element> response_map_x = new Map<String, e_services.E_PostcodeSearchResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'urn:EE_PostcodeSearch',
              'urn:E',
              'E_PostcodeSearch',
              'urn:E',
              'E_PostcodeSearchResponse',
              'e_services.E_PostcodeSearchResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.C_Webservice_AddressCompleteRespons;
        }
    }
    public class E_PostcodeSearch_element {
        public String TownPartial;
        public String StreetPartial;
        private String[] TownPartial_type_info = new String[]{'TownPartial','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] StreetPartial_type_info = new String[]{'StreetPartial','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'TownPartial','StreetPartial'};
    }
    public class E_AddressesSearch_element {
        public Integer HousenumberFrom;
        public String PostalCode;
        public Integer HousenumberUntil;
        private String[] HousenumberFrom_type_info = new String[]{'HousenumberFrom','http://www.w3.org/2001/XMLSchema','integer','0','1','false'};
        private String[] PostalCode_type_info = new String[]{'PostalCode','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] HousenumberUntil_type_info = new String[]{'HousenumberUntil','http://www.w3.org/2001/XMLSchema','integer','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'HousenumberFrom','PostalCode','HousenumberUntil'};
    }
    public class authentication_element {
        public String username;
        public String password;
        private String[] username_type_info = new String[]{'username','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'username','password'};
    }
    public class E_AddressesSearchResponse_element {
        public e_services.C_Webservice_AddressCompleteRespons_element[] C_Webservice_AddressCompleteRespons;
        private String[] C_Webservice_AddressCompleteRespons_type_info = new String[]{'C_Webservice.AddressCompleteRespons','urn:E','C_Webservice.AddressCompleteRespons_element','0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'C_Webservice_AddressCompleteRespons'};
    }
    public class E_PostcodeSearchResponse_element {
        public e_services.C_Webservice_AddressCompleteRespons_element[] C_Webservice_AddressCompleteRespons;
        private String[] C_Webservice_AddressCompleteRespons_type_info = new String[]{'C_Webservice.AddressCompleteRespons','urn:E','C_Webservice.AddressCompleteRespons_element','0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'C_Webservice_AddressCompleteRespons'};
    }
    public class E_Postcodecheck_element {
        public String Postcode;
        public String HuisnummerExtentie;
        public Integer Huisnummer;
        private String[] Postcode_type_info = new String[]{'Postcode','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] HuisnummerExtentie_type_info = new String[]{'HuisnummerExtentie','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Huisnummer_type_info = new String[]{'Huisnummer','http://www.w3.org/2001/XMLSchema','integer','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'Postcode','HuisnummerExtentie','Huisnummer'};
    }
    public class C_Webservice_AddressCompleteRespons_element {
        public String Zipcode;
        public String Town;
        public String Street;
        public Integer HouseNumber;
        public String HouseNumberExtension;
        private String[] Zipcode_type_info = new String[]{'Zipcode','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Town_type_info = new String[]{'City','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Street_type_info = new String[]{'Street','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] HouseNumber_type_info = new String[]{'HouseNumber','http://www.w3.org/2001/XMLSchema','integer','0','1','false'};
        private String[] HouseNumberExtension_type_info = new String[]{'HouseNumberExtension','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'Zipcode','Town','Street','HouseNumber','HouseNumberExtension'};
    }
    public class E_PostcodecheckResponse_element {
        public e_services.C_Webservice_ExternalZipcodeRespons_element C_Webservice_ExternalZipcodeRespons;
        private String[] C_Webservice_ExternalZipcodeRespons_type_info = new String[]{'C_Webservice.ExternalZipcodeRespons','urn:E','C_Webservice.ExternalZipcodeRespons_element','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'C_Webservice_ExternalZipcodeRespons'};
    }
    public class C_Webservice_ExternalZipcodeRespons_element {
        public Integer Distance;
        public Boolean IsValid;
        public Boolean CrossesRailway;
        public Boolean CrossesWater;
        public Boolean CrossesMainroad;
        private String[] Distance_type_info = new String[]{'Distance','http://www.w3.org/2001/XMLSchema','integer','0','1','false'};
        private String[] IsValid_type_info = new String[]{'IsValid','http://www.w3.org/2001/XMLSchema','boolean','0','1','false'};
        private String[] CrossesRailway_type_info = new String[]{'CrossesRailway','http://www.w3.org/2001/XMLSchema','boolean','0','1','false'};
        private String[] CrossesWater_type_info = new String[]{'CrossesWater','http://www.w3.org/2001/XMLSchema','boolean','0','1','false'};
        private String[] CrossesMainroad_type_info = new String[]{'CrossesMainroad','http://www.w3.org/2001/XMLSchema','boolean','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:E','false','false'};
        private String[] field_order_type_info = new String[]{'Distance','IsValid','CrossesRailway','CrossesWater','CrossesMainroad'};
    }
}
3
  • See the Test Web Service Callouts documentation.
    – Keith C
    Commented May 31, 2016 at 9:13
  • I have already gone through that but I am not getting any example for wsdl2apex
    – wizard
    Commented May 31, 2016 at 9:18
  • That article does relate to wsdl2apex generated code but you have to do the work of building an appropriate response which requires digging in to the message structure. See Daniel's answer for a tool that might help.
    – Keith C
    Commented May 31, 2016 at 9:21

1 Answer 1

1

I've written a free tool that will generate the Apex Test classes for a WSDL automatically. FuseIT SFDC Explorer. There is also a Dreamforce presentation on its usage.

Basically it will generate the WebServiceMock implementation for you with minimal dummy returns. It will also create the corresponding test classes. These are really basic and only focused on getting coverage for the generated code. You will need to flesh them out with suitable content for the services in question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .