Invalid interface: ...
 
Notifications
Clear all

Invalid interface: WebServiceMock - salesforce

1 Posts
1 Users
0 Likes
787 Views
Posts: 205
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

I am working on the Apex SOAP Callouts Trailhead challenge, Generate an Apex class using WSDL2Apex and write a test class - with ParkService class, ParkLocator class, ParkServiceMock class and ParkServiceTest class. But getting the error Invalid interface: WebServiceMock while trying to save the ParkServiceMock class. I tried loggin out and re-logging in, closed the browser, etc. Still the error. Code is below:

public class ParkLocator {
    public static String[]country(String theCountry){
        ParkService.ParksImplPort parkSvc = new ParkService.ParksImplPort();
        return parkSvc.byCountry(theCountry);
    }
}
@isTest
private class ParkLocatorTest {
    @isTest static void testCallout(){
        Test.setMock(WebServiceMock.class, new ParkServiceMock());
        String country = 'United States';
        List<String> result = ParkLocator.country(country);
        List<String> parks = new List<String>{'Yellowstone', 'Big Bear', 'Yosemite'};
        System.assertEquals(parks, result);
    }
}
@isTest
global class ParkServiceMock 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) {
		// specify the response you want to send
		ParkService.byCountryResponse response_x = new ParkService.byCountryResponse();
    	response_x.return_x = new List<String>{'Yellowstone', 'Big Bear', 'Yosemite'};
        response.put('response_x', response_x);
    }
}

Any pointers would help. 

Issue Tags
Share: