2

I have a wsdl2apex class which resembes like this.

public class wwwmysiteComsfdcContract {
    public class sfdcContractWSDLSOAPQSPort {
        public String endpoint_x = 'http://sfdc2-osb-dit.us.mysite.com:80/sfdc/Contract/Services';
        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;
        public wwwmysiteComsfdcGilHeaderdataxmlsCONTRACT.headerData_element request_header;
        private String request_header_hns = 'headerData=http://www.mysite.com/sfdc/GIL/HeaderDataXMLS';
        private String[] ns_map_type_info = new String[] {
            'http://www.mysite.com/sfdc/Contract/types', 'wwwmysiteComsfdcContractTypes', 'http://www.mysite.com/sfdc/Contract/', 'wwwmysiteComsfdcContract', 'http://www.mysite.com/sfdc/Contract/GetContractDetails/types', 'wwwmysiteComsfdcContractGetcontractdet', 'http://www.mysite.com/sfdc/GIL/HeaderDataXMLS', 'wwwmysiteComsfdcGilHeaderdataxmlsCONTRACT', 'http://www.mysite.com/sfdc/Contract/CreateMessage', 'wwwmysiteComsfdcContractCreatemessage'
        };
        public wwwmysiteComsfdcContractTypes.SearchResultType Search_x(String Region, String ContractNumber, String ssnum, String PhoneNumber, String CreditApplicationNumber, String SerialTagNumber, String InvoiceNumber, String mysiteOrderNumber, String ContactName, String TaxIdNumber, String PONumber, String CustomerName, wwwmysiteComsfdcContractTypes.Pagination_element Pagination) {
            wwwmysiteComsfdcContractTypes.SearchRequestType request_x = new wwwmysiteComsfdcContractTypes.SearchRequestType();
            request_x.Region = Region;
            request_x.ContractNumber = ContractNumber;
            request_x.ssnum = ssnum;
            request_x.PhoneNumber = PhoneNumber;
            request_x.CreditApplicationNumber = CreditApplicationNumber;
            request_x.SerialTagNumber = SerialTagNumber;
            request_x.InvoiceNumber = InvoiceNumber;
            request_x.mysiteOrderNumber = mysiteOrderNumber;
            request_x.ContactName = ContactName;
            request_x.TaxIdNumber = TaxIdNumber;
            request_x.PONumber = PONumber;
            request_x.CustomerName = CustomerName;
            request_x.Pagination = Pagination;
            wwwmysiteComsfdcContractTypes.SearchResultType response_x;
            Map < String, wwwmysiteComsfdcContractTypes.SearchResultType > response_map_x = new Map < String, wwwmysiteComsfdcContractTypes.SearchResultType > ();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
            this,
            request_x,
            response_map_x,
            new String[] {
                endpoint_x,
                    'http://www.mysite.com/sfdc/Contract/Search',
                    'http://www.mysite.com/sfdc/Contract/types',
                    'SearchRequest',
                    'http://www.mysite.com/sfdc/Contract/types',
                    'SearchResponse',
                    'wwwmysiteComsfdcContractTypes.SearchResultType'
            });
            response_x = response_map_x.get('response_x');
            return response_x;
        }
        public wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsResponseType GetContractDetails(String Region, String ContractNumber) {
            wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsRequestType request_x = new wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsRequestType();
            request_x.Region = Region;
            request_x.ContractNumber = ContractNumber;
            wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsResponseType response_x;
            Map < String, wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsResponseType > response_map_x = new Map < String, wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsResponseType > ();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
            this,
            request_x,
            response_map_x,
            new String[] {
                endpoint_x,
                    'http://www.mysite.com/sfdc/Contract/GetContractDetails/types',
                    'http://www.mysite.com/sfdc/Contract/GetContractDetails/types',
                    'GetContractDetailsRequest',
                    'http://www.mysite.com/sfdc/Contract/GetContractDetails/types',
                    'GetContractDetailsResponse',
                    'wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsResponseType'
            });
            response_x = response_map_x.get('response_x');
            return response_x;
        }
        public wwwmysiteComsfdcContractCreatemessage.CreateMessageResponseType CreateMessage(Boolean asynchronous, wwwmysiteComsfdcContractCreatemessage.RegionType Region, wwwmysiteComsfdcContractCreatemessage.CommentsType Comments) {
            wwwmysiteComsfdcContractCreatemessage.CreateMessageRequestType request_x = new wwwmysiteComsfdcContractCreatemessage.CreateMessageRequestType();
            request_x.asynchronous = asynchronous;
            request_x.Region = Region;
            request_x.Comments = Comments;
            wwwmysiteComsfdcContractCreatemessage.CreateMessageResponseType response_x;
            Map < String, wwwmysiteComsfdcContractCreatemessage.CreateMessageResponseType > response_map_x = new Map < String, wwwmysiteComsfdcContractCreatemessage.CreateMessageResponseType > ();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
            this,
            request_x,
            response_map_x,
            new String[] {
                endpoint_x,
                    'http://www.mysite.com/sfdc/Contract/CreateMessage/action',
                    'http://www.mysite.com/sfdc/Contract/CreateMessage',
                    'CreateMessageRequest',
                    'http://www.mysite.com/sfdc/Contract/CreateMessage',
                    'CreateMessageResponse',
                    'wwwmysiteComsfdcContractCreatemessage.CreateMessageResponseType'
            });
            response_x = response_map_x.get('response_x');
            return response_x;
        }
    }
}

Test class

@isTest
private class ContractMockCalloutTest {
    testmethod static void SFDCGatewayWSDLSOAPQSPort_SearchCustomerContractTest() {
        Test.startTest();
        Test.setMock(WebServiceMock.class, new ContractListMockWebServiceCallout());
        wwwmysiteComsfdcContract.wwwmysiteComsfdcContract stub = new wwwmysiteComsfdcContract.wwwmysiteComsfdcContract();
        //Here I am stuck, I am not able to access the inner class and its methods in the WSDL2Apex class in test class. 

//if I refer stub.innerclass it is throwing error any thoughts what I am doing wrong. } }

3
  • 1
    Can you explain exactly why you're stuck? – Matt Lacey Sep 24 '15 at 4:03
  • @LaceySnr isTest private class ContractMockCalloutTest { testmethod static void SFDCGatewayWSDLSOAPQSPort_SearchCustomerContractTest() { Test.startTest(); Test.setMock(WebServiceMock.class, new ContractListMockWebServiceCallout()); wwwmysiteComsfdcContract.wwwmysiteComsfdcContract stub = new wwwmysiteComsfdcContract.wwwmysiteComsfdcContract(); //Here I am stuck when I refer the following line it is throwing the error as invalid type stub.wwwmysiteComsfdcContractTypes.SearchResultType and how to make a move from here no Idea please let me know. } } – Suresh Sep 24 '15 at 14:16
  • @LaceySnr After Initalising the outer class I am not able to invoke or access the inner class. – Suresh Sep 24 '15 at 16:15
0

One issue I see, your base example up top doesn't match your stub class you instantiate in the test. Note the extra "Contract" before WSDLSOAPQSPort.

1
  • I corrected that and I did not have any idea to go further if possible please suggest me some thing to go further. – Suresh Sep 23 '15 at 22:13
0

For inner classes you can do it it by creating an instance of the Outer class in the test as below.

public class classA {
    public class classB  {
       public void doSomething(){
         ---some code----
    }
  }
}

Test Class

@isTest
private class TestClassA {
  static {
    // This should get code coverage on inner class
    new ClassA();
  }     
  @isTest static void testSomethingInClassB() {
    ClassA.ClassB b = new ClassA.ClassB();
    b.doSomething();
  }
}
2
  • its is throwing error as classB is invalid. – Suresh Sep 23 '15 at 22:12
  • Hey Saroj I updated my class with actual class can you please let me know what I can do further. – Suresh Sep 23 '15 at 22:25
0

Your test will want to create an instance of the port class.

wwwmysiteComsfdcContract.sfdcContractWSDLSOAPQSPort stub = 
    new wwwmysiteComsfdcContract.sfdcContractWSDLSOAPQSPort();
wwwmysiteComsfdcContractGetcontractdet.GetContractDetailsResponseType result =
    stub.GetContractDetails('Region', 'ContractNumber');


wwwmysiteComsfdcContractTypes.Pagination_element pagination = new wwwmysiteComsfdcContractTypes.Pagination_element();
// More code here to setup pagination
wwwmysiteComsfdcContractTypes.SearchResultType searchResult = 
    stub. Search_x('Region', 'ContractNumber', 'ssnum', 'PhoneNumber', 
                   'CreditApplicationNumber', 'SerialTagNumber', 'InvoiceNumber',
                   'mysiteOrderNumber', 'ContactName', 'TaxIdNumber', 'PONumber', 
                   'CustomerName', pagination);

If you are mostly after code coverage for the generated Wsdl2Apex classes, I've made a tool that will do this for you. There is an option when generating the Apex classes to also generate the test methods to give you coverage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.