@Test(expected = DeleteException.class) public void expectDeleteExceptionIfHostCollectionFails() throws FreeIpaClientException { when(freeIpaClient.findAllHost()).thenThrow(new FreeIpaClientException("error")); underTest.deleteHostsWithDeleteException(freeIpaClient, Set.of("testHost")); }
public void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts) throws FreeIpaClientException, DeleteException { try { Pair<Set<String>, Map<String, String>> removeHostsResult = removeHosts(client, hosts); if (!removeHostsResult.getSecond().isEmpty()) { throw new DeleteException(HOST_DELETION_FAILED + ' ' + removeHostsResult.getSecond()); } } catch (RetryableFreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new RetryableFreeIpaClientException(HOST_DELETION_FAILED, e, new DeleteException(HOST_DELETION_FAILED)); } catch (FreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new DeleteException(HOST_DELETION_FAILED); } }
HostDeletionService { public void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts) throws FreeIpaClientException, DeleteException { try { Pair<Set<String>, Map<String, String>> removeHostsResult = removeHosts(client, hosts); if (!removeHostsResult.getSecond().isEmpty()) { throw new DeleteException(HOST_DELETION_FAILED + ' ' + removeHostsResult.getSecond()); } } catch (RetryableFreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new RetryableFreeIpaClientException(HOST_DELETION_FAILED, e, new DeleteException(HOST_DELETION_FAILED)); } catch (FreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new DeleteException(HOST_DELETION_FAILED); } } }
HostDeletionService { public void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts) throws FreeIpaClientException, DeleteException { try { Pair<Set<String>, Map<String, String>> removeHostsResult = removeHosts(client, hosts); if (!removeHostsResult.getSecond().isEmpty()) { throw new DeleteException(HOST_DELETION_FAILED + ' ' + removeHostsResult.getSecond()); } } catch (RetryableFreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new RetryableFreeIpaClientException(HOST_DELETION_FAILED, e, new DeleteException(HOST_DELETION_FAILED)); } catch (FreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new DeleteException(HOST_DELETION_FAILED); } }  }
HostDeletionService { public void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts) throws FreeIpaClientException, DeleteException { try { Pair<Set<String>, Map<String, String>> removeHostsResult = removeHosts(client, hosts); if (!removeHostsResult.getSecond().isEmpty()) { throw new DeleteException(HOST_DELETION_FAILED + ' ' + removeHostsResult.getSecond()); } } catch (RetryableFreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new RetryableFreeIpaClientException(HOST_DELETION_FAILED, e, new DeleteException(HOST_DELETION_FAILED)); } catch (FreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new DeleteException(HOST_DELETION_FAILED); } }  Pair<Set<String>, Map<String, String>> removeHosts(FreeIpaClient client, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeServers(FreeIpaClient client, Set<String> hosts); void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts); }
HostDeletionService { public void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts) throws FreeIpaClientException, DeleteException { try { Pair<Set<String>, Map<String, String>> removeHostsResult = removeHosts(client, hosts); if (!removeHostsResult.getSecond().isEmpty()) { throw new DeleteException(HOST_DELETION_FAILED + ' ' + removeHostsResult.getSecond()); } } catch (RetryableFreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new RetryableFreeIpaClientException(HOST_DELETION_FAILED, e, new DeleteException(HOST_DELETION_FAILED)); } catch (FreeIpaClientException e) { LOGGER.error(HOST_DELETION_FAILED + ' ' + e.getLocalizedMessage(), e); throw new DeleteException(HOST_DELETION_FAILED); } }  Pair<Set<String>, Map<String, String>> removeHosts(FreeIpaClient client, Set<String> hosts); Pair<Set<String>, Map<String, String>> removeServers(FreeIpaClient client, Set<String> hosts); void deleteHostsWithDeleteException(FreeIpaClient client, Set<String> hosts);  }