I have a Java class that I’m trying to write unit tests for using testng and mockito. The class inherits from the javax.xml.ws.Service class.
The WSDL URL required by the Service class is currently unavailable in my development environment. This prevents me from creating a Service instance and testing the functionality of the ServiceChild class.
I want to be able to write unit tests for the ServiceChild class without relying on the actual WSDL URL. Instead, I want to mock the Service class and simulate its behavior to test the functionality of the ServiceChild class.
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.URL;
public class ServiceChild extends Service {
private final static URL DEFAULT_URL;
private final static QName DEFAULT_QNAME = new QName("http://example/qname", "ExampleName");
static {
URL wsdl = null;
try {
wsdl = new URL('https://wsdl/location');
} catch (MalformedURLException e) {
e = new WebServiceException(e);
}
DEFAULT_URL = wsdl;
}
public ServiceChild() {
super(DEFAULT_URL, DEFAULT_QNAME)
}
public ServiceChild(URL wsdl, QName name) {
super(wsdl, name);
}
}
Currently, when I try to call the no args constructor in my unit test:
ServiceChild serviceChild = new ServiceChild();
I get a “java.net.ConnectException: Connection timed out: connect” error.