function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Test Code Coverage for classes generated by wsdl2java

Another question on callouts.


I have stubs generate by WSDL to java.  Do I need to get code coverage on these?


If so, I would think that the only way to do it would be to edit them and put in a testMode flag and conditionally not WebServiceCallout.invoke() call when that's set.  Then set the testMode flag in a test method.


Is that something that I'm going to have to do or is there another work-around?


The generated code is shown below (URLS obscured for security reasons.  I take it I have to hack this to get coverage on all the line except the WebServiceCallout.invoke()???



public class HMHEaiOtsCustomerGetcustomer {
    public class SOAPEventSource {
        public String endpoint_x = 'http:urldeleted';
        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://www.foobar/getCustomerDetailImpl', 'HMHEaiOtsCustomerGetcustomer', 'http://foobar/Customer', 'HMHEaiOtsCustomer', 'http://foobar/EAI', 'HMHEai', 'http://foobar/EAI/OTS/Material', 'HMHEaiOtsMaterial'};
        public HMHEaiOtsCustomer.customerDetail_element[] getCustomerDetail(HMHEaiOtsCustomer.customerKey_element[] customerKey) {
            HMHEaiOtsCustomer.customerKeyList_element request_x = new HMHEaiOtsCustomer.customerKeyList_element();
            HMHEaiOtsCustomer.customerDetailList_element response_x;
            request_x.customerKey = customerKey;
            Map<String, HMHEaiOtsCustomer.customerDetailList_element> response_map_x = new Map<String, HMHEaiOtsCustomer.customerDetailList_element>();
            response_map_x.put('response_x', response_x);
              new String[]{endpoint_x,
            response_x = response_map_x.get('response_x');
            return response_x.customerDetail;




Getting up to 75% coverage on a generated Webservice class is pretty straightforward - just create a new testMethod that manually instantiates any public objects and calls all of the webservice operations inside of the generated class.  No need to worry about any assertions or anything here.  


I'm pretty sure that Salesforce will ignore any invoke calls coming from within a testMethod, so you don't need to worry about stubbing out the invoke line. 




P.S. What's java got to do with anything? :)


java was typeo.  use to work a lot with wsdl2java.  Meant to type wsdl2apex.