Ниже это метод, который я пытаюсь проверить с помощью JUnit и MockitoMockito Stubbing
код Java
public String getAuthenticationService() {
Authentication endpoint;
String token = "";
try {
URL wsdlURL = new URL(authenticationURL);
SoapService service = new SoapService(wsdlURL,
new QName("SomeQName",
"SoapService"));
endpoint = service.getAuthenticationPort();
token = endpoint.authenticate(username, password);
} catch (Exception e) {
throw new GenericException(
"OpenText AuthenticationService not working Error is "
+ e.toString());
}
return token;
}
метод Junit
public void testGetAuthenticationService()
throws AuthenticationException_Exception {
AuthenticationService mockService = Mockito
.mock(AuthenticationService.class);
Authentication mockEndpoint = Mockito.mock(Authentication.class);
Mockito.when(mockService.getAuthenticationPort()).thenReturn(
mockEndpoint);
Mockito.when(mockEndpoint.authenticate(username, password)).thenReturn(
token);
}
Когда я запускаю тест Junit случай конечной точки .authenticate пытается подключиться к actaul soap service, а метод stubbing не работает, что я делаю неправильно здесь
Альтернативный подход - издеваться фактическое обслуживание на локальном хосте: https://github.com/skjolber/mockito-soap -cxf – ThomasRS