|
21 | 21 |
|
22 | 22 | import java.io.IOException; |
23 | 23 | import java.net.SocketTimeoutException; |
| 24 | +import java.net.UnknownHostException; |
24 | 25 | import java.nio.charset.StandardCharsets; |
25 | 26 | import java.nio.file.Files; |
26 | 27 | import java.nio.file.Path; |
@@ -289,6 +290,50 @@ void withGeneralExceptionConnectTimeout() throws ApiException { |
289 | 290 | executeTestWithException(generalException); |
290 | 291 | } |
291 | 292 |
|
| 293 | + @Test |
| 294 | + void withNameResolutionApiException() throws ApiException { |
| 295 | + // Create an ApiException with UnknownHostException as cause containing "Name does not resolve" |
| 296 | + UnknownHostException nameResolutionException = new UnknownHostException("msg-solace-test.lcag-cmlz-n.lhgroup.de: Name does not resolve"); |
| 297 | + ApiException apiException = new ApiException(nameResolutionException); |
| 298 | + |
| 299 | + executeTestWithException(apiException); |
| 300 | + } |
| 301 | + |
| 302 | + @Test |
| 303 | + void withNameResolutionExceptionMessage() throws ApiException { |
| 304 | + // Create an ApiException with "Name does not resolve" in the message |
| 305 | + ApiException apiException = new ApiException("java.net.UnknownHostException: msg-solace-test.lcag-cmlz-n.lhgroup.de: Name does not resolve"); |
| 306 | + |
| 307 | + executeTestWithException(apiException); |
| 308 | + } |
| 309 | + |
| 310 | + @Test |
| 311 | + void withNestedNameResolutionException() throws ApiException { |
| 312 | + // Create nested exception with UnknownHostException deep in the cause chain |
| 313 | + UnknownHostException nameResolutionException = new UnknownHostException("host.example.com: Name does not resolve"); |
| 314 | + RuntimeException wrapperException = new RuntimeException("Wrapper exception", nameResolutionException); |
| 315 | + ApiException apiException = new ApiException(wrapperException); |
| 316 | + |
| 317 | + executeTestWithException(apiException); |
| 318 | + } |
| 319 | + |
| 320 | + @Test |
| 321 | + void withNonNameResolutionUnknownHostException() throws ApiException { |
| 322 | + // Create UnknownHostException with different message (not name resolution) |
| 323 | + UnknownHostException unknownHostException = new UnknownHostException("No route to host"); |
| 324 | + ApiException apiException = new ApiException(unknownHostException); |
| 325 | + |
| 326 | + executeTestWithException(apiException); |
| 327 | + } |
| 328 | + |
| 329 | + @Test |
| 330 | + void withGeneralExceptionNameResolution() throws ApiException { |
| 331 | + // Create a general Exception (not ApiException) with name resolution error |
| 332 | + RuntimeException generalException = new RuntimeException("Connection failed: Name does not resolve"); |
| 333 | + |
| 334 | + executeTestWithException(generalException); |
| 335 | + } |
| 336 | + |
292 | 337 | private void executeTestWithException(Exception exception) throws ApiException { |
293 | 338 | ClientProfileApi clientProfileApi = Mockito.mock(ClientProfileApi.class); |
294 | 339 | when(sempApiProvider.getClientProfileApi()).thenReturn(clientProfileApi); |
|
0 commit comments