### Question:
FreeIpaClientFactory { public FreeIpaClient getFreeIpaClientForStackWithPing(Stack stack, String freeIpaFqdn) throws Exception { LOGGER.debug("Ping the login endpoint and creating FreeIpaClient for stack {} for {}", stack.getResourceCrn(), freeIpaFqdn); return getFreeIpaClient(stack, true, true, Optional.of(freeIpaFqdn)); }  FreeIpaClient getFreeIpaClientForStackId(Long stackId); FreeIpaClient getFreeIpaClientByAccountAndEnvironment(String environmentCrn, String accountId); FreeIpaClient getFreeIpaClientForStack(Stack stack); FreeIpaClient getFreeIpaClientForStack(Stack stack, String freeIpaFqdn); FreeIpaClient getFreeIpaClientForStackWithPing(Stack stack, String freeIpaFqdn); String getAdminUser();  }### Answer:
@Test void getFreeIpaClientForStackWithPingShouldReturnClientWhenStackStatusIsUnreachable() { Stack stack = createStack(); stack.setGatewayport(80); FreeIpa freeIpa = new FreeIpa(); freeIpa.setAdminPassword(new Secret("", "")); when(freeIpaService.findByStack(stack)).thenReturn(freeIpa); when(stackService.getByIdWithListsInTransaction(stack.getId())).thenReturn(stack); when(tlsSecurityService.buildTLSClientConfig(any(), any(), any())).thenReturn(new HttpClientConfig(FREEIPP_FQDN)); Status unreachableState = Status.FREEIPA_UNREACHABLE_STATUSES.stream().findAny().get(); StackStatus stackStatus = new StackStatus(stack, unreachableState, "The FreeIPA instance is unreachable.", DetailedStackStatus.UNREACHABLE); stack.setStackStatus(stackStatus); FreeIpaClientException exception = Assertions.assertThrows(FreeIpaClientException.class, () -> underTest.getFreeIpaClientForStackWithPing(stack, FREEIPP_FQDN)); verify(clusterProxyService, times(1)).isCreateConfigForClusterProxy(stack); verify(tlsSecurityService, times(1)).buildTLSClientConfig(any(), any(), any()); Assertions.assertEquals(FreeIpaHostNotAvailableException.class, exception.getCause().getClass()); }
@Test void getFreeIpaClientForStackWithPingShouldReturnClientWhenStackStatusIsValid() { Stack stack = createStack(); stack.setGatewayport(80); FreeIpa freeIpa = new FreeIpa(); freeIpa.setAdminPassword(new Secret("", "")); when(freeIpaService.findByStack(stack)).thenReturn(freeIpa); when(stackService.getByIdWithListsInTransaction(stack.getId())).thenReturn(stack); when(tlsSecurityService.buildTLSClientConfig(any(), any(), any())).thenReturn(new HttpClientConfig(FREEIPP_FQDN)); Status unreachableState = Status.AVAILABLE; StackStatus stackStatus = new StackStatus(stack, unreachableState, "The FreeIPA instance is reachable.", DetailedStackStatus.AVAILABLE); stack.setStackStatus(stackStatus); FreeIpaClientException exception = Assertions.assertThrows(FreeIpaClientException.class, () -> underTest.getFreeIpaClientForStackWithPing(stack, FREEIPP_FQDN)); verify(clusterProxyService, times(1)).isCreateConfigForClusterProxy(stack); verify(tlsSecurityService, times(1)).buildTLSClientConfig(any(), any(), any()); Assertions.assertEquals(FreeIpaHostNotAvailableException.class, exception.getCause().getClass()); }