You need to sign in to do that
Don't have an account?
MarcFog
No Apex class named 'ParkServiceMock' was found
Greetings - has anyone received the error "No Apex class named 'ParkServiceMock' was found."? I have the ParkServiceMock class defined, and called out in the ParkLocatorTest class using Test.setMock(WebServiceMock.class, new ParkServiceMock());
I also verified that the tests run with 100% code coverage, and the ParkLocator class returns the names of parks.
Any idea what I'm doing wrong? Thanks in advance.
I also verified that the tests run with 100% code coverage, and the ParkLocator class returns the names of parks.
Any idea what I'm doing wrong? Thanks in advance.
ParkLocatorTest
ParkLocator
and ParkServiceMock
I greatly appreciate any insight into what's going wrong.
Marc
Um, this is not an "Answer", as I am getting the same error from the Apex SOAP Callouts challenge. To wit:
In my case, I incorrectly named the mock class as ParkLocatorMock.apxc when I created it initially. So, I legitimately got the error at first. I quickly realized that I 'fumble-brained' the naming, so I then created the class named properly. I re-ran my tests and got the same error again. So I deleted the incorrectly named class, performed a Clear Text Data, and performed a Run All, but the error persisted.
Here is all of the pertinent code ...
My ParkLocator.apxc file:
My ParkLocatorTest.apxc file:
My ParkServiceMock.apxc file:
The Apex classes created by the WSDL2Apex tool:
And lastly, the parks.xml file itself:
<?xml version='1.0' encoding='UTF-8'?> <wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://parks.services/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="ParksImplService" targetNamespace="http://parks.services/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://parks.services/" elementFormDefault="unqualified" targetNamespace="http://parks.services/" version="1.0"> <xs:element name="byCountry" type="tns:byCountry"/> <xs:element name="byCountryResponse" type="tns:byCountryResponse"/> <xs:complexType name="byCountry"> <xs:sequence> <xs:element minOccurs="0" name="arg0" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="byCountryResponse"> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="byCountry"> <wsdl:part element="tns:byCountry" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="byCountryResponse"> <wsdl:part element="tns:byCountryResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="Parks"> <wsdl:operation name="byCountry"> <wsdl:input message="tns:byCountry" name="byCountry"> </wsdl:input> <wsdl:output message="tns:byCountryResponse" name="byCountryResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="ParksImplServiceSoapBinding" type="tns:Parks"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="byCountry"> <soap:operation soapAction="" style="document"/> <wsdl:input name="byCountry"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="byCountryResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="ParksImplService"> <wsdl:port binding="tns:ParksImplServiceSoapBinding" name="ParksImplPort"> <soap:address location="https://th-apex-soap-service.herokuapp.com/service/parks"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
I'm hoping that Mr Douglas is monitoring this post and can offer a reason why this error is persisting. By the way, I've read a number of posts that pertain to errors that claim the absence of classes that appear to exist, in addition to posts that offer tips on clearing caches and re-running stuff. So far, I haven't hit on any technique that solves the problem. I refuse to get cocky and sugest that something in the system is broken, but for the life of me, I can't see what if anything I'm doing wrong. I don't think I've messed up, but I "sit" ready to be corrected. (:>)
David
Deleting the ParkServiceMock 'again' and then re-creating it a third time seems to have done it. Guess third time IS a charm! (:>) In any case, thank you very much. I love the Salesforce Trailhead challenges,*cough* when they work *cough*. I also like the jokey banter. The 'glitchy' encounters, not so much. Again, thanks. Cheers,
David
public class ParkLocator {
public static List<String> Country(String name) {
List<String> countries = new List<String>();
ParkService.ParksImplPort park = new ParkService.ParksImplPort();
countries = park.byCountry(name);
return countries;
}
}
----------------------------------------------------------------------------------------------------------
@isTest
private class ParkLocatorTest {
@isTest static void testCallout() {
// This causes a fake response to be generated
Test.setMock(WebServiceMock.class, new ParkServiceMock());
// Call the method that invokes a callout
String[] parks = ParkLocator.Country('Japan');
// Verify that a fake result is returned
system.assert(parks.size() > 0);
}
}
----------------------------------------------------------------------------------------------------------
@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) {
// start - specify the response you want to send
ParkService.byCountryResponse response_x = new ParkService.byCountryResponse();
response_x.return_x = new List<String>{'Germany', 'India', 'Japan', 'United States'};
response.put('response_x', response_x);
}
}